#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,q,k,t,x,y,a[100005],tree[400005];
void build(int id,int l,int r){
if(l==r){
tree[id]=a[l];
return;
}
int mid=(l+r)/2;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
tree[id]=tree[id*2]+tree[id*2+1];
}
void update1(int id,int l,int r,int pos,int val){
if(l==r){
tree[id]=val;
return;
}
int mid=(l+r)/2;
if(pos<=mid) update1(id*2,l,mid,pos,val);
else update1(id*2+1,mid+1,r,pos,val);
tree[id]=tree[id*2]+tree[id*2+1];
}
void update2(int id,int l,int r,int u,int v){
if(tree[id]==0||k==1) return;
if(l==r){
tree[id]/=k;
return;
}
int mid=(l+r)/2;
if(u<=mid) update2(id*2,l,mid,u,v);
if(mid<v) update2(id*2+1,mid+1,r,u,v);
tree[id]=tree[id*2]+tree[id*2+1];
}
int getsum(int id,int l,int r,int u,int v){
if(v<l||u>r||u>v) return 0;
if(u<=l&&r<=v){
return tree[id];
}
int mid=(l+r)/2,ans=0;
if(u<=mid) ans+=getsum(id*2,l,mid,u,v);
if(mid<v) ans+=getsum(id*2+1,mid+1,r,u,v);
return ans;
}
signed main(){
scanf("%lld %lld %lld",&n,&q,&k);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
build(1,1,n);
while(q--){
scanf("%lld %lld %lld",&t,&x,&y);
if(t==1){
update1(1,1,n,x,y);
}if(t==2){
update2(1,1,n,x,y);
}if(t==3){
printf("%lld\n",getsum(1,1,n,x,y));
}
}
}
Compilation message
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld",&n,&q,&k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&a[i]);
~~~~~^~~~~~~~~~~~~~
sterilizing.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld",&t,&x,&y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
504 KB |
Output is correct |
12 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
2168 KB |
Output is correct |
2 |
Correct |
58 ms |
2040 KB |
Output is correct |
3 |
Correct |
56 ms |
3244 KB |
Output is correct |
4 |
Correct |
69 ms |
3572 KB |
Output is correct |
5 |
Correct |
83 ms |
3684 KB |
Output is correct |
6 |
Correct |
83 ms |
3704 KB |
Output is correct |
7 |
Correct |
83 ms |
3656 KB |
Output is correct |
8 |
Correct |
83 ms |
3704 KB |
Output is correct |
9 |
Correct |
77 ms |
3736 KB |
Output is correct |
10 |
Correct |
77 ms |
3708 KB |
Output is correct |
11 |
Correct |
78 ms |
3676 KB |
Output is correct |
12 |
Correct |
80 ms |
3832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
504 KB |
Output is correct |
2 |
Correct |
16 ms |
1656 KB |
Output is correct |
3 |
Correct |
22 ms |
1784 KB |
Output is correct |
4 |
Correct |
57 ms |
1180 KB |
Output is correct |
5 |
Correct |
76 ms |
3192 KB |
Output is correct |
6 |
Correct |
76 ms |
3192 KB |
Output is correct |
7 |
Correct |
70 ms |
3436 KB |
Output is correct |
8 |
Correct |
77 ms |
3320 KB |
Output is correct |
9 |
Correct |
76 ms |
3248 KB |
Output is correct |
10 |
Correct |
74 ms |
3192 KB |
Output is correct |
11 |
Correct |
75 ms |
3192 KB |
Output is correct |
12 |
Correct |
70 ms |
3192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
1960 KB |
Output is correct |
2 |
Correct |
105 ms |
2136 KB |
Output is correct |
3 |
Correct |
119 ms |
1784 KB |
Output is correct |
4 |
Correct |
127 ms |
1372 KB |
Output is correct |
5 |
Correct |
159 ms |
3448 KB |
Output is correct |
6 |
Correct |
184 ms |
3576 KB |
Output is correct |
7 |
Correct |
151 ms |
3520 KB |
Output is correct |
8 |
Correct |
230 ms |
3480 KB |
Output is correct |
9 |
Correct |
187 ms |
3404 KB |
Output is correct |
10 |
Correct |
207 ms |
3540 KB |
Output is correct |
11 |
Correct |
155 ms |
3448 KB |
Output is correct |
12 |
Correct |
269 ms |
3468 KB |
Output is correct |