This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<long long>sg,a(100005);
int n,sz;
void is()
{
for(sz=1;sz<n;sz*=2);
sg.resize(sz*2,0);
}
void up(int i,long long v)
{
i+=sz;
sg[i]=v;
for(i/=2;i>0;i/=2)
{
sg[i]=sg[i*2]+sg[i*2+1];
}
}
long long q(int v,int lw,int h,int l,int r)
{
if(lw<=l&&r<=h)return sg[v];
else if(l>=h||lw>=r)return 0;
else
{
int m=(l+r)/2;
return q(v*2,lw,h,l,m)+q(v*2+1,lw,h,m,r);
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
while(t--)
{
int qr,k;
cin>>n>>qr>>k;
is();
for(int x=0;x<n;x++)
{
cin>>a[x];
up(x,a[x]);
}
if(k==1)
{
while(qr--)
{
int t,l,r;
cin>>t>>l>>r;
if(t==1)up(l-1,r);
if(t==3)cout<<q(1,l-1,r,0,sz);
}
}
else
{
while(qr--)
{
int t,l,r;
cin>>t>>l>>r;
if(t==1)a[l-1]=r;
if(t==2)
{
for(int x=l-1;x<r;x++)a[x]/=k;
}
if(t==3)
{
long long s=0;
for(int x=l-1;x<r;x++)s+=a[x];
cout<<s<<'\n';
}
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |