#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll LINF=(1LL<<60)-1LL;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
struct Segtree{
int n;
vector<ll> dat;
Segtree(int n_){
n=1;
while(n<n_){
n<<=1;
}
dat.resize(2*n);
}
void upd(int k,ll x){
k+=n;
dat[k]=x;
k>>=1;
while(k>0){
dat[k]=dat[k<<1]+dat[k<<1|1];
k>>=1;
}
}
ll get(int a,int b,int k,int l,int r){
if(b<=l||r<=a){
return 0;
}
if(a<=l&&r<=b){
return dat[k];
}
return get(a,b,k<<1,l,(l+r)/2)+get(a,b,k<<1|1,(l+r)/2,r);
}
inline ll get(int a,int b){
return get(a,b,1,0,n);
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,q,k;cin>>n>>q>>k;
vector<ll> c(n);
set<int> st;
Segtree seg(n);
for(int i=0;i<n;i++){
cin>>c[i];
if(c[i]>0){
st.insert(i);
}
seg.upd(i,c[i]);
}
for(int i=0;i<q;i++){
int t,a,b;cin>>t>>a>>b;
if(t==1){
--a;
if(c[a]>0){
st.erase(a);
}
c[a]=b;
if(b>0){
st.insert(a);
}
seg.upd(a,b);
}else if(t==2){
--a;--b;
auto it=st.lower_bound(a);
vector<int> v;
for(;it!=st.end();it++){
if((*it)>b){
break;
}
c[*it]/=k;
if(c[*it]==0){
v.emplace_back(*it);
}
seg.upd((*it),c[*it]);
}
for(auto &e:v){
st.erase(e);
}
}else{
--a;--b;
cout<<seg.get(a,b+1)<<endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
10 ms |
504 KB |
Output is correct |
5 |
Correct |
11 ms |
632 KB |
Output is correct |
6 |
Correct |
9 ms |
632 KB |
Output is correct |
7 |
Correct |
11 ms |
632 KB |
Output is correct |
8 |
Correct |
11 ms |
632 KB |
Output is correct |
9 |
Correct |
12 ms |
636 KB |
Output is correct |
10 |
Correct |
10 ms |
632 KB |
Output is correct |
11 |
Correct |
10 ms |
632 KB |
Output is correct |
12 |
Correct |
10 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5091 ms |
5392 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
1216 KB |
Output is correct |
2 |
Correct |
38 ms |
3064 KB |
Output is correct |
3 |
Correct |
53 ms |
3320 KB |
Output is correct |
4 |
Correct |
151 ms |
2916 KB |
Output is correct |
5 |
Correct |
189 ms |
7376 KB |
Output is correct |
6 |
Correct |
190 ms |
7032 KB |
Output is correct |
7 |
Execution timed out |
5099 ms |
6348 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
6008 KB |
Output is correct |
2 |
Correct |
203 ms |
6264 KB |
Output is correct |
3 |
Correct |
210 ms |
5136 KB |
Output is correct |
4 |
Correct |
223 ms |
4600 KB |
Output is correct |
5 |
Correct |
308 ms |
10764 KB |
Output is correct |
6 |
Correct |
348 ms |
10744 KB |
Output is correct |
7 |
Correct |
323 ms |
10872 KB |
Output is correct |
8 |
Correct |
387 ms |
10744 KB |
Output is correct |
9 |
Correct |
339 ms |
10688 KB |
Output is correct |
10 |
Correct |
373 ms |
10788 KB |
Output is correct |
11 |
Correct |
312 ms |
10616 KB |
Output is correct |
12 |
Correct |
476 ms |
10712 KB |
Output is correct |