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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeForces - 1207F Remainder Problem(分块)

發布時間:2024/4/11 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces - 1207F Remainder Problem(分块) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:點擊查看

題目大意:給出一個長度為 500000500000500000 的數組,初始時全部為 000,需要執行 nnn 次操作,每次操作分為兩種類型:

  • 1xy1 \ x \ y1?x?yax+=ya_x+=yax?+=y
  • 2xy2 \ x \ y2?x?y:統計∑i∈R(x,y)ai\sum_{i \in R(x,y)}a_iiR(x,y)?ai?,其中 R(x,y)R(x,y)R(x,y)[1,500000][1,500000][1,500000] 中對 xxx 取余等于 yyy 的位置
  • 題目分析:考慮根號分塊,即小范圍暴力大范圍通過預處理獲得,當 x≤500000x \le \sqrt {500000}x500000? 時,直接維護一個前綴和 sumi,jsum_{i,j}sumi,j? 代表 x=i,y=jx = i,y = jx=i,y=j 時的答案;當 x≥500000x \ge \sqrt {500000}x500000? 時,暴力查詢的時間復雜度是 500000\sqrt {500000}500000?

    考慮修改,每次直接暴力修改 sumsumsum 數組即可,時間復雜度同樣是 500000\sqrt {500000}500000? 的,所以這個題分塊實現兩個操作的時間復雜度均攤下來就是 O(nn)O(n\sqrt n)O(nn?)

    代碼:

    // #pragma GCC optimize(2) // #pragma GCC optimize("Ofast","inline","-ffast-math") // #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<unordered_map> using namespace std; typedef long long LL; typedef unsigned long long ull; template<typename T> inline void read(T &x) {T f=1;x=0;char ch=getchar();while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();x*=f; } template<typename T> inline void write(T x) {if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0'); } const int inf=0x3f3f3f3f; const int N=1e6+100; LL sum[1010][1010],a[N]; int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);int n;read(n);for(int i=1;i<=n;i++){int op,x,y;read(op),read(x),read(y);if(op==1){for(int i=1;i<=1000;i++) sum[i][x%i]+=y;a[x]+=y;}else{if(x<=1000) write(sum[x][y]),putchar('\n');else{LL ans=0;for(int i=y;i<=500000;i+=x) ans+=a[i];write(ans),putchar('\n');}}}return 0; }

    總結

    以上是生活随笔為你收集整理的CodeForces - 1207F Remainder Problem(分块)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。