#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include <iomanip>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,int>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
#define double long double
const int mxn=1e5,inf=1e9,lg=30;
int n,k;
bool yes=false;
struct seg{
int v[4*mxn+10][lg+5],add[4*mxn+10],cur[4*mxn+10];
void init(){
for(int i=0;i<4*mxn+10;i++){
for(int j=0;j<lg;j++)v[i][j]=0;
add[i]=cur[i]=0;
}
}
void push(int pos,int l,int r){
if(!add[pos])return;
cur[pos]+=add[pos];
v[pos][0]=v[pos][cur[pos]];
if(l!=r){
add[pos<<1]+=add[pos];
add[(pos<<1)^1]+=add[pos];
}
add[pos]=0;
}
void updr(int l,int r,int ql,int qr,int pos){
push(pos,l,r);
if(r<ql||l>qr)return;
if(l>=ql&&r<=qr){
add[pos]++;
push(pos,l,r);
return;
}
int mid=l+(r-l)/2;
updr(l,mid,ql,qr,(pos<<1));
updr(mid+1,r,ql,qr,(pos<<1)^1);
push(pos<<1,l,mid);
push((pos<<1)^1,mid+1,r);
for(int j=0;j<=lg;j++)v[pos][j]=v[pos<<1][min(cur[pos<<1]+j,lg)]+v[(pos<<1)^1][min(cur[(pos<<1)^1]+j,lg)];
cur[pos]=0;
}
void updp(int l,int r,int qp,int pos,int val){
push(pos,l,r);
if(l>r)return;
cur[pos]=0;
if(l==r){
for(int j=0;j<=lg;j++)v[pos][j]=val,val/=k;
add[pos]=0;
return;
}
int mid=l+(r-l)/2;
if(qp<=mid)updp(l,mid,qp,(pos<<1),val);
else updp(mid+1,r,qp,(pos<<1)^1,val);
push(pos<<1,l,mid);
push((pos<<1)^1,mid+1,r);
for(int j=0;j<=lg;j++)v[pos][j]=v[pos<<1][min(cur[pos<<1]+j,lg)]+v[(pos<<1)^1][min(cur[(pos<<1)^1]+j,lg)];
}
int qry(int l,int r,int ql,int qr,int pos){
push(pos,l,r);
if(r<ql||l>qr)return 0;
if(l>=ql&&r<=qr)return v[pos][0];
int mid=l+(r-l)/2;
return qry(l,mid,ql,qr,pos<<1)+qry(mid+1,r,ql,qr,(pos<<1)^1);
}
}s;
int32_t main(){
fastio
int q;cin>>n>>q>>k;
s.init();
for(int i=1;i<=n;i++){
int a;cin>>a;
s.updp(1,n,i,1,a);
}
while(q--){
int t,a,b;cin>>t>>a>>b;
if(t==1)s.updp(1,n,a,1,b);
else if(t==2)s.updr(1,n,a,b,1);
else cout<<s.qry(1,n,a,b,1)<<"\n";
}
return 0;
}
Compilation message
sterilizing.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
32 | #pragma GCC optimize ("03,unroll-lopps")
| ^
sterilizing.cpp:40:15: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
40 | void init(){
| ^
sterilizing.cpp:46:34: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
46 | void push(int pos,int l,int r){
| ^
sterilizing.cpp:56:48: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
56 | void updr(int l,int r,int ql,int qr,int pos){
| ^
sterilizing.cpp:72:49: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
72 | void updp(int l,int r,int qp,int pos,int val){
| ^
sterilizing.cpp:88:46: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
88 | int qry(int l,int r,int ql,int qr,int pos){
| ^
sterilizing.cpp:96:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
96 | int32_t main(){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
116308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
231 ms |
118484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
69 ms |
116668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
202 ms |
117960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |