第三周 3.14 --- 3.20
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第三周 3.14 --- 3.20相关的知识,希望对你有一定的参考价值。
新的一周><
3.14
cf 635d D - Factory Repairs
用自己的办法wa了两发之后,才明白一神和wtw 说的是什么 T_T
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 7 typedef long long LL; 8 const int maxn = 2e5+5; 9 int n,k,a,b,q; 10 LL sq[4*maxn],sh[4*maxn],s[4*maxn]; 11 int L[maxn],R[maxn]; 12 int p,v,ql,qr; 13 14 void Push_up(int o){ 15 s[o] = s[o<<1] + s[o<<1|1]; 16 sq[o] = sq[o<<1]+sq[o<<1|1]; 17 sh[o] = sh[o<<1]+sh[o<<1|1]; 18 } 19 20 void Update(int o,int l,int r){ 21 if(l == r){ 22 s[o] += 1LL*v; 23 sq[o] = s[o];sh[o] = s[o]; 24 if(sq[o] > b) sq[o] = b; 25 if(sh[o] > a) sh[o] = a; 26 return; 27 } 28 int mid = (l+r)/2; 29 if(p <= mid) Update(o<<1,l,mid); 30 else Update(o<<1|1,mid+1,r); 31 Push_up(o); 32 } 33 34 LL queryq(int o,int l,int r){ 35 if(ql <= l && r <= qr){ 36 return sq[o]; 37 } 38 int mid = (l+r)/2; 39 LL ans = 0LL; 40 if(ql <= mid) ans += queryq(o<<1,l,mid); 41 if(qr > mid) ans += queryq(o<<1|1,mid+1,r); 42 return ans; 43 } 44 45 LL queryh(int o,int l,int r){ 46 if(ql <= l && r <= qr){ 47 return sh[o]; 48 } 49 int mid = (l+r)/2; 50 LL ans = 0LL; 51 if(ql <= mid) ans += queryh(o<<1,l,mid); 52 if(qr > mid) ans += queryh(o<<1|1,mid+1,r); 53 return ans; 54 } 55 56 void solve(){ 57 int cmd,dd,aa,pp; 58 memset(sq,0,sizeof(sq)); 59 memset(sh,0,sizeof(sh)); 60 memset(s,0,sizeof(s)); 61 for(int i = 1;i <= q;i++){ 62 scanf("%d",&cmd); 63 if(cmd == 1){ 64 scanf("%d %d",&p,&v); 65 Update(1,1,n); 66 } 67 else{ 68 scanf("%d",&pp); 69 LL qian = 0LL,hou = 0LL,res = 0LL; 70 ql = 1;qr = pp-1; 71 if(qr >= ql) qian = queryq(1,1,n); 72 ql = pp+k;qr = n; 73 hou = queryh(1,1,n); 74 res = qian + hou; 75 // printf("qian = %I64d hou = %I64d res = %I64d\n",qian,hou,res); 76 printf("%I64d\n",res); 77 } 78 } 79 } 80 81 int main(){ 82 while(scanf("%d %d %d %d %d",&n,&k,&a,&b,&q) != EOF){ 83 solve(); 84 } 85 return 0; 86 }
以上是关于第三周 3.14 --- 3.20的主要内容,如果未能解决你的问题,请参考以下文章