#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
typedef pair<ll,ll> ii;
const ll inf=1e15;
const ll maxn=5e5+5;
const ll mod=1e9+7;
struct node{
ll s,e,m,val;
node *l,*r;
node(ll _s,ll _e):s(_s),e(_e),m((_s+_e)>>1),val(0){
if (s!=e) l=new node(s,m),r=new node(m+1,e);
}
void upd(ll p, ll v){
if (s==e){val=v; return;}
if (p>m) r->upd(p,v);
if (p<=m) l->upd(p,v);
val=l->val+r->val;
}
ll query(ll x, ll y){
if (x<=s && e<=y) return val;
if (x>m) return r->query(x,y);
if (y<=m) return l->query(x,y);
return l->query(x,y)+r->query(x,y);
}
}*root;
set<ll> s;
ll arr[maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n,q,ele,k;
cin>>n>>q>>k;
root=new node(1,n);
for (int i=1;i<=n;i++){
cin>>ele;
arr[i]=ele;
root->upd(i,ele);
if (arr[i]) s.insert(i);
}
ll t,a,b;
for (int i=0;i<q;i++){
cin>>t;
t--;
if (t==1){
cin>>a>>b;
if (k==1) continue;
for (auto it=s.lower_bound(a);it!=s.end() && *it<=b;){
root->upd(*it,arr[*it]/k);
arr[*it]/=k;
if (arr[*it]==0) it=s.erase(it);
else it++;
}
}
if (t==0){
cin>>a>>b;
arr[a]=b;
root->upd(a,arr[a]);
if (arr[a]) s.insert(a);
}
if (t==2){
cin>>a>>b;
cout<<root->query(a,b)<<endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
472 KB |
Output is correct |
3 |
Correct |
3 ms |
588 KB |
Output is correct |
4 |
Correct |
6 ms |
584 KB |
Output is correct |
5 |
Correct |
9 ms |
844 KB |
Output is correct |
6 |
Correct |
6 ms |
844 KB |
Output is correct |
7 |
Correct |
7 ms |
844 KB |
Output is correct |
8 |
Correct |
7 ms |
844 KB |
Output is correct |
9 |
Correct |
9 ms |
844 KB |
Output is correct |
10 |
Correct |
8 ms |
916 KB |
Output is correct |
11 |
Correct |
7 ms |
972 KB |
Output is correct |
12 |
Correct |
8 ms |
936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
11340 KB |
Output is correct |
2 |
Correct |
80 ms |
8220 KB |
Output is correct |
3 |
Correct |
92 ms |
16068 KB |
Output is correct |
4 |
Correct |
126 ms |
20548 KB |
Output is correct |
5 |
Correct |
140 ms |
21280 KB |
Output is correct |
6 |
Correct |
156 ms |
21244 KB |
Output is correct |
7 |
Correct |
142 ms |
21200 KB |
Output is correct |
8 |
Correct |
134 ms |
21316 KB |
Output is correct |
9 |
Correct |
124 ms |
21060 KB |
Output is correct |
10 |
Correct |
115 ms |
21104 KB |
Output is correct |
11 |
Correct |
132 ms |
21088 KB |
Output is correct |
12 |
Correct |
128 ms |
21064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
1728 KB |
Output is correct |
2 |
Correct |
27 ms |
7500 KB |
Output is correct |
3 |
Correct |
32 ms |
7624 KB |
Output is correct |
4 |
Correct |
53 ms |
5316 KB |
Output is correct |
5 |
Correct |
105 ms |
17356 KB |
Output is correct |
6 |
Correct |
107 ms |
17356 KB |
Output is correct |
7 |
Correct |
107 ms |
17860 KB |
Output is correct |
8 |
Correct |
112 ms |
17344 KB |
Output is correct |
9 |
Correct |
96 ms |
17248 KB |
Output is correct |
10 |
Correct |
98 ms |
17268 KB |
Output is correct |
11 |
Correct |
93 ms |
17284 KB |
Output is correct |
12 |
Correct |
91 ms |
17356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
11212 KB |
Output is correct |
2 |
Correct |
163 ms |
11588 KB |
Output is correct |
3 |
Correct |
265 ms |
9684 KB |
Output is correct |
4 |
Correct |
176 ms |
8048 KB |
Output is correct |
5 |
Correct |
295 ms |
20932 KB |
Output is correct |
6 |
Correct |
341 ms |
21084 KB |
Output is correct |
7 |
Correct |
286 ms |
20968 KB |
Output is correct |
8 |
Correct |
451 ms |
21060 KB |
Output is correct |
9 |
Correct |
367 ms |
21012 KB |
Output is correct |
10 |
Correct |
446 ms |
20972 KB |
Output is correct |
11 |
Correct |
312 ms |
20932 KB |
Output is correct |
12 |
Correct |
601 ms |
20892 KB |
Output is correct |