#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
typedef long long ll;
using namespace std;
ll n,q,k;
ll niz[MAXN],seg[4*MAXN];
set<ll> s;
void dodaj(ll l,ll d,ll p,ll x,ll k){
if(l==d){
seg[k]=x;
return;
}
ll mid=(l+d)/2;
if(p<=mid)dodaj(l,mid,p,x,k+k);
else dodaj(mid+1,d,p,x,k+k+1);
seg[k]=seg[k+k]+seg[k+k+1];
}
ll dobij(ll l,ll d,ll tl,ll td,ll k){
//printf(" %lld %lld %lld %lld\n",l,d,k,seg[k]);
if(l>td || d<tl)return 0;
if(l>=tl && d<=td)return seg[k];
ll mid=(l+d)/2;
return dobij(l,mid,tl,td,k+k)+dobij(mid+1,d,tl,td,k+k+1);
}
vector<ll> zab;
int main()
{
scanf("%lld %lld %lld", &n, &q, &k);
for(ll i=1;i<=n;i++){
scanf("%lld",niz+i);
if(niz[i]!=0){
s.insert(i);
}
dodaj(1,n,i,niz[i],1);
}
while(q--){
ll qt,a,b;
scanf("%lld %lld %lld", &qt, &a, &b);
if(qt==1){
niz[a]=b;
if(niz[a]!=0){
s.insert(a);
}
dodaj(1,n,a,niz[a],1);
}else if(qt==2){
if(k==1)continue;
for(auto it=s.lower_bound(a);it!=s.end() && (*it)<=b;++it){
ll t=*it;
niz[t]/=k;
if(niz[t]==0)zab.pb(t);
dodaj(1,n,t,niz[t],1);
}
for(auto x:zab)s.erase(x);
zab.clear();
}else{
printf("%lld\n",dobij(1,n,a,b,1));
}
}
return 0;
}
Compilation message
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:39:10: 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:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",niz+i);
~~~~~^~~~~~~~~~~~~~
sterilizing.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld", &qt, &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
12 ms |
504 KB |
Output is correct |
5 |
Correct |
13 ms |
632 KB |
Output is correct |
6 |
Correct |
10 ms |
632 KB |
Output is correct |
7 |
Correct |
12 ms |
632 KB |
Output is correct |
8 |
Correct |
12 ms |
632 KB |
Output is correct |
9 |
Correct |
14 ms |
632 KB |
Output is correct |
10 |
Correct |
11 ms |
632 KB |
Output is correct |
11 |
Correct |
11 ms |
632 KB |
Output is correct |
12 |
Correct |
12 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
6332 KB |
Output is correct |
2 |
Correct |
87 ms |
5212 KB |
Output is correct |
3 |
Correct |
106 ms |
8568 KB |
Output is correct |
4 |
Correct |
136 ms |
10304 KB |
Output is correct |
5 |
Correct |
157 ms |
10744 KB |
Output is correct |
6 |
Correct |
156 ms |
10744 KB |
Output is correct |
7 |
Correct |
153 ms |
10744 KB |
Output is correct |
8 |
Correct |
154 ms |
10744 KB |
Output is correct |
9 |
Correct |
149 ms |
10740 KB |
Output is correct |
10 |
Correct |
161 ms |
10616 KB |
Output is correct |
11 |
Correct |
146 ms |
10616 KB |
Output is correct |
12 |
Correct |
146 ms |
10744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1144 KB |
Output is correct |
2 |
Correct |
32 ms |
3164 KB |
Output is correct |
3 |
Correct |
39 ms |
3320 KB |
Output is correct |
4 |
Correct |
69 ms |
2936 KB |
Output is correct |
5 |
Correct |
123 ms |
7160 KB |
Output is correct |
6 |
Correct |
123 ms |
7200 KB |
Output is correct |
7 |
Correct |
126 ms |
7544 KB |
Output is correct |
8 |
Correct |
135 ms |
7520 KB |
Output is correct |
9 |
Correct |
121 ms |
7376 KB |
Output is correct |
10 |
Correct |
112 ms |
7284 KB |
Output is correct |
11 |
Correct |
113 ms |
7412 KB |
Output is correct |
12 |
Correct |
112 ms |
7412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
5880 KB |
Output is correct |
2 |
Correct |
215 ms |
6252 KB |
Output is correct |
3 |
Correct |
360 ms |
5244 KB |
Output is correct |
4 |
Correct |
231 ms |
4728 KB |
Output is correct |
5 |
Correct |
395 ms |
10836 KB |
Output is correct |
6 |
Correct |
471 ms |
10748 KB |
Output is correct |
7 |
Correct |
369 ms |
10872 KB |
Output is correct |
8 |
Correct |
606 ms |
10980 KB |
Output is correct |
9 |
Correct |
494 ms |
11244 KB |
Output is correct |
10 |
Correct |
580 ms |
11252 KB |
Output is correct |
11 |
Correct |
400 ms |
11120 KB |
Output is correct |
12 |
Correct |
832 ms |
11124 KB |
Output is correct |