#include <bits/stdc++.h>
using namespace std;
#define int long long
int Tree[3000000];
int N=(1<<(int)(log2(200000)));
int l,r;
int solve(int l1,int r1,int i){
if(l1>r||r1<l) return 0;
if(l1>=l&&r1<=r) return Tree[i];
return solve(l1,(r1+l1)/2,i*2)+solve(((l1+r1)/2)+1,r1,i*2+1);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k,q;
cin>>n>>q>>k;
int arr[n+1];
for(int i=0;i<n;i++){
cin>>arr[i];
Tree[i+N]=arr[i];
}
for(int i=N-1;i>=1;i--) Tree[i]=Tree[i*2]+Tree[i*2+1];
if(n>0&&q>0){
while(q--){
int type;
cin>>type;
if(type==1){
int indx,b;
cin>>indx>>b;
arr[indx-1]=b;
}
if(type==2){
int l,r;
cin>>l>>r;
for(int i=l-1;i<r;i++){
arr[i]=arr[i]/k;
}
}
if(type==3){
int l,r,sum=0;
cin>>l>>r;
for(int i=l-1;i<r;i++){
sum+=arr[i];
}
cout<<sum<<endl;
}
}
}
else if(k==1){
while(q--){
int type;
cin>>type;
if(type==1){
int indx,b;
cin>>indx>>b;
indx--;
Tree[indx+N]=arr[indx]=b;
indx+=N;
indx/=2;
while(indx!=0){
Tree[indx]=Tree[indx*2]+Tree[indx*2+1];
indx/=2;
}
}
if(type==3){
cin>>l>>r;
l--;
r--;
cout<<solve(0,N-1,1)<<"\n";
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
4 ms |
2652 KB |
Output is correct |
5 |
Correct |
6 ms |
2648 KB |
Output is correct |
6 |
Correct |
7 ms |
2648 KB |
Output is correct |
7 |
Correct |
6 ms |
2652 KB |
Output is correct |
8 |
Correct |
6 ms |
2652 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
7 ms |
2724 KB |
Output is correct |
11 |
Correct |
6 ms |
2652 KB |
Output is correct |
12 |
Correct |
7 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3699 ms |
3684 KB |
Output is correct |
2 |
Correct |
2291 ms |
4948 KB |
Output is correct |
3 |
Correct |
3654 ms |
5236 KB |
Output is correct |
4 |
Execution timed out |
5092 ms |
5980 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
2904 KB |
Output is correct |
2 |
Correct |
295 ms |
3556 KB |
Output is correct |
3 |
Correct |
461 ms |
3388 KB |
Output is correct |
4 |
Correct |
1037 ms |
4148 KB |
Output is correct |
5 |
Correct |
4170 ms |
5020 KB |
Output is correct |
6 |
Correct |
4144 ms |
5152 KB |
Output is correct |
7 |
Correct |
4217 ms |
5052 KB |
Output is correct |
8 |
Correct |
4196 ms |
5308 KB |
Output is correct |
9 |
Execution timed out |
5043 ms |
4340 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1529 ms |
4640 KB |
Output is correct |
2 |
Correct |
1765 ms |
5024 KB |
Output is correct |
3 |
Correct |
951 ms |
4312 KB |
Output is correct |
4 |
Correct |
1314 ms |
5016 KB |
Output is correct |
5 |
Correct |
4195 ms |
6360 KB |
Output is correct |
6 |
Correct |
4216 ms |
6344 KB |
Output is correct |
7 |
Correct |
4209 ms |
6272 KB |
Output is correct |
8 |
Correct |
4150 ms |
6508 KB |
Output is correct |
9 |
Execution timed out |
5026 ms |
5100 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |