日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数论分块练习([CF830 C]Bamboo Partition + [hdu 6395]Sequence )

發(fā)布時間:2023/12/3 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数论分块练习([CF830 C]Bamboo Partition + [hdu 6395]Sequence ) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

  • T1:Sequence
    • title
    • solution
  • T2:Bamboo Partition
    • title
    • solution
    • code

T1:Sequence

title

傳送

solution

一眼就是很裸的矩陣加速
?pl?\lfloor\frac{p}{l}\rfloor?lp??分塊矩陣加速就可以了
[BA1]×[DC?pl?010001]\begin{bmatrix} B\\ A\\ 1\\ \end{bmatrix} \times \begin{bmatrix} D&C&\lfloor\frac{p}{l}\rfloor\\ 0&1&0\\ 0&0&1 \end{bmatrix} ???BA1????×???D00?C10??lp??01????
這道題唯一算得上是坑的應(yīng)該是n,pn,pn,p的大小,當(dāng)p/l==0p/l==0p/l==0直接矩陣加速到底即可,注意rrr不能超過nnn
## code

#include <cstdio> #include <cstring> #include <iostream> using namespace std; #define ll long long #define mod 1000000007 struct Matrix {ll c[5][5];void init() {memset( c, 0, sizeof( c ) );}Matrix operator * ( const Matrix &a ) {Matrix ans;ans.init();for( int i = 1;i <= 3;i ++ )for( int j = 1;j <= 3;j ++ )for( int k = 1; k <= 3;k ++ )ans.c[i][j] = ( ans.c[i][j] + c[i][k] * a.c[k][j] ) % mod;return ans;} }V; ll T, A, B, C, D, P, n; ll ans1, ans2;Matrix qkpow( Matrix a, int b ) {Matrix ans;ans.init();for( int i = 1;i <= 3;i ++ ) ans.c[i][i] = 1;while( b ) {if( b & 1 ) ans = ans * a;a = a * a;b >>= 1;}return ans; }signed main() {scanf( "%lld", &T );while( T -- ) {scanf( "%lld %lld %lld %lld %lld %lld", &A, &B, &C, &D, &P, &n );if( n == 1 ) { printf( "%lld\n", A ); continue; }if( n == 2 ) { printf( "%lld\n", B ); continue; }ans1 = B, ans2 = A;for( int l = 3, r;l <= n;l = r + 1 ) {if( P / l == 0 ) {V.init();V.c[1][1] = D, V.c[1][2] = C;V.c[2][1] = V.c[3][3] = 1;V = qkpow( V, n - l + 1 );ans1 = ( V.c[1][1] * ans1 % mod + V.c[1][2] * ans2 % mod + V.c[1][3] ) % mod;ans2 = ( V.c[2][1] * ans1 % mod + V.c[2][2] * ans2 % mod + V.c[2][3] ) % mod;break;}r = min( n, P / ( P / l ) );V.init();V.c[1][1] = D, V.c[1][2] = C, V.c[1][3] = P / l;V.c[2][1] = V.c[3][3] = 1;V = qkpow( V, r - l + 1 );ll newans1 = ( V.c[1][1] * ans1 % mod + V.c[1][2] * ans2 % mod + V.c[1][3] ) % mod;ll newans2 = ( V.c[2][1] * ans1 % mod + V.c[2][2] * ans2 % mod + V.c[2][3] ) % mod;ans1 = newans1, ans2 = newans2;}printf( "%lld\n", ans1 );} return 0; }

T2:Bamboo Partition

title

傳送門

solution

∑i=1nd?((ai?1)%d+1)≤k∑_{i=1}^nd?((a_i?1)\%d+1)≤ki=1n?d?((ai??1)%d+1)k
=∑i=1nd?∑i=1n(ai?1??ai?1d??d+1)≤k=\sum_{i=1}^nd-\sum_{i=1}^n(a_i-1-\lfloor\frac{a_i-1}ozvdkddzhkzd\rfloor*d+1)\le k=i=1n?d?i=1n?(ai??1??dai??1???d+1)k
=n?d?∑i=1nai+∑i=1n?ai?1d??d≤k=n*d-\sum_{i=1}^na_i+\sum_{i=1}^n\lfloor\frac{a_i-1}ozvdkddzhkzd\rfloor*d\le k=n?d?i=1n?ai?+i=1n??dai??1???dk
d(n+∑i=1n?ai?1d??d)≤k+∑i=1naid(n+\sum_{i=1}^n\lfloor\frac{a_i-1}ozvdkddzhkzd\rfloor*d)\le k+\sum_{i=1}^na_id(n+i=1n??dai??1???d)k+i=1n?ai?
?ai?1d?\lfloor\frac{a_i-1}ozvdkddzhkzd\rfloor?dai??1??有根號的取值,我們直接分塊即可

code

#include <cstdio> #include <iostream> using namespace std; #define N 105 #define int long long int n, k, Max, ans; int a[N];signed main() {scanf( "%lld %lld", &n, &k );for( int i = 1;i <= n;i ++ ) scanf( "%lld", &a[i] ), k += a[i], Max = max( Max, a[i] - 1 );for( int l = 1, r, sum;l <= Max;l = r + 1 ) {r = Max, sum = 0;for( int i = 1;i <= n;i ++ )if( a[i] - 1 >= l ) {sum += ( a[i] - 1 ) / l;r = min( r, ( a[i] - 1 ) / ( ( a[i] - 1 ) / l ) );}if( l <= k / ( sum + n ) ) ans = max( ans, min( k / ( sum + n ), r ) );}if( Max < k / n ) ans = max( ans, k / n );printf( "%lld", ans );return 0; }

總結(jié)

以上是生活随笔為你收集整理的数论分块练习([CF830 C]Bamboo Partition + [hdu 6395]Sequence )的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。