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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

poj 3486 A Simple Problem with Integers(树状数组第三种模板改段求段)

發布時間:2025/3/8 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 3486 A Simple Problem with Integers(树状数组第三种模板改段求段) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 /* 2 樹狀數組第三種模板(改段求段)不解釋!
不明白的點這里:here!
3 */ 4 #include<iostream> 5 #include<cstring> 6 #include<cstdio> 7 #include<algorithm> 8 #define N 100005 9 using namespace std; 10 11 typedef long long LL; 12 13 LL ss[N], B[N], C[N]; 14 15 int n, m; 16 17 void addB(int x, int k){//B[i]表示被1...i整體一共加了多少的總和 18 for(int i=x; i<=n; i+=i&(-i)) B[i]+=x*k; 19 } 20 21 void addC(int x, int k){//1....x節點的每個節點的增量 22 for(int i=x; i>0; i-=i&(-i)) C[i]+=k; 23 } 24 25 LL sumB(int x){ 26 LL s=0; 27 for(int i=x; i>0; i-=i&(-i)) s+=B[i]; 28 return s; 29 } 30 31 LL sumC(int x){//x節點總共的增量 32 LL s=0; 33 for(int i=x; i<=n; i+=i&(-i)) s+=C[i]; 34 return s; 35 } 36 37 LL sum(int x){ 38 return x==0 ? 0 : sumC(x)*x + sumB(x-1); 39 } 40 41 void update(int a, int b, int c){ 42 addB(b, c); 43 addC(b, c); 44 if(a-1>0){ 45 addB(a-1, -c); 46 addC(a-1, -c); 47 } 48 } 49 50 int main(){ 51 int m; 52 while(scanf("%d%d", &n, &m)!=EOF){ 53 for(int i=1; i<=n; ++i){ 54 scanf("%lld", &ss[i]); 55 ss[i]+=ss[i-1]; 56 } 57 char ch[2]; 58 int a, b, c; 59 while(m--){ 60 scanf("%s", ch); 61 if(ch[0]=='Q'){ 62 scanf("%d%d", &a, &b); 63 printf("%lld\n", ss[b]-ss[a-1]+sum(b)-sum(a-1)); 64 } 65 else{ 66 scanf("%d%d%d", &a, &b, &c); 67 update(a, b, c); 68 } 69 } 70 } 71 return 0; 72 }

?

轉載于:https://www.cnblogs.com/hujunzheng/p/3969029.html

總結

以上是生活随笔為你收集整理的poj 3486 A Simple Problem with Integers(树状数组第三种模板改段求段)的全部內容,希望文章能夠幫你解決所遇到的問題。

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