#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
lli n,q,k;
lli segt[400001][33];
lli lazy[400001]={},crazy[100001]={};
lli qu(lli node,lli l,lli r,lli s,lli e)
{
if(crazy[node]!=0)
{
lazy[node]=min(lazy[node]+crazy[node],32*1LL);
crazy[2*node+1]+=crazy[node];
crazy[2*node+2]+=crazy[node];
crazy[node]=0;
}
if(r<s||l>e)
return(0);
if(l>=s&&r<=e)
return(segt[node][lazy[node]]);
lli m=(l+r)/2;
lli q1=qu(2*node+1,l,m,s,e),q2=qu(2*node+2,m+1,r,s,e);
return(q1+q2);
}
void up2(lli node,lli l,lli r,lli s,lli e)
{
if(crazy[node]!=0)
{
lazy[node]=min(lazy[node]+crazy[node],32*1LL);
crazy[2*node+1]+=crazy[node];
crazy[2*node+2]+=crazy[node];
crazy[node]=0;
}
if(l>e||r<s)
return;
if(l>=s&&r<=e)
{
lazy[node]=min(lazy[node]+1,32*1LL);
crazy[2*node+1]=min(crazy[2*node+1]+1,32*1LL);
crazy[2*node+2]=min(crazy[2*node+2]+1,32*1LL);
return;
}
lli m=(l+r)/2;
up2(2*node+1,l,m,s,e);
up2(2*node+2,m+1,r,s,e);
}
lli c=0;
void up1(lli node,lli l,lli r,lli in,lli v)
{
if(crazy[node]!=0)
{
lazy[node]=min(lazy[node]+crazy[node],32*1LL);
crazy[2*node+1]+=crazy[node];
crazy[2*node+2]+=crazy[node];
crazy[node]=0;
}
if(l==r)
{
lazy[node]=0;
crazy[node]=0;
for(int i=0;i<32*1LL;++i)
{
segt[node][i]=(v);
v/=k;
}
return;
}
lli m=(l+r)/2;
if(in<=m)
up1(2*node+1,l,m,in,v);
else
up1(2*node+2,m+1,r,in,v);
lazy[node]=0;
qu(2*node+1,l,m,l,m);
qu(2*node+2,m+1,r,m+1,r);
for(int i=0;i<33;++i)
segt[node][i]=segt[2*node+1][min(lazy[2*node+1]+i,32*1LL)]+segt[2*node+2][min(lazy[2*node+2]+i,32*1LL)];
}
void init(lli node,lli l,lli r)
{
for(int i=0;i<33;++i)
segt[node][i]=0;
lli m=(l+r)/2;
if(l!=r)
{
init(2*node+1,l,m);
init(2*node+2,m+1,r);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>q>>k;
init(0,0,n-1);
for(lli i=0;i<n;++i)
{
lli f;
cin>>f;
up1(0,0,n-1,i,f);
}
for(lli i=0;i<q;++i)
{
lli f,s,t;
cin>>f>>s>>t;
if(f==1)
{
s--;
up1(0,0,n-1,s,t);
}
else if(f==2)
{
s--;
t--;
up2(0,0,n-1,s,t);
}
else
{
s--;
t--;
cout<<qu(0,0,n-1,s,t)<<endl;
}
}
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
316 ms |
36600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
76 ms |
5048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
268 ms |
36472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |