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"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll sum[MAXN<<2];
int mx[MAXN<<2],arr[MAXN],k;
void build(int nd,int x,int y){
if(x==y){
sum[nd]=mx[nd]=arr[x];
return;
}
int mid=(x+y)>>1;
build(nd<<1,x,mid);
build(nd<<1|1,mid+1,y);
sum[nd]=sum[nd<<1]+sum[nd<<1|1];
mx[nd]=max(mx[nd<<1],mx[nd<<1|1]);
}
void upd(int p,int v,int nd,int x,int y){
if(x==y){
sum[nd]=mx[nd]=v;
return;
}
int mid=(x+y)>>1;
if(p<=mid)
upd(p,v,nd<<1,x,mid);
else
upd(p,v,nd<<1|1,mid+1,y);
sum[nd]=sum[nd<<1]+sum[nd<<1|1];
mx[nd]=max(mx[nd<<1],mx[nd<<1|1]);
}
void inc(int l,int r,int nd,int x,int y){
if(l>y or x>r or !mx[nd])
return;
if(x==y){
sum[nd]/=k;
mx[nd]/=k;
return;
}
int mid=(x+y)>>1;
inc(l,r,nd<<1,x,mid);
inc(l,r,nd<<1|1,mid+1,y);
sum[nd]=sum[nd<<1]+sum[nd<<1|1];
mx[nd]=max(mx[nd<<1],mx[nd<<1|1]);
}
ll tap(int l,int r,int nd,int x,int y){
if(l>y or x>r)
return 0;
if(l<=x and y<=r)
return sum[nd];
int mid=(x+y)>>1;
return tap(l,r,nd<<1,x,mid)+tap(l,r,nd<<1|1,mid+1,y);
}
int main(){
//~ freopen("file.in", "r", stdin);
int n,q;
scanf("%d%d%d",&n,&q,&k);
for(int i=1;i<=n;i++)
scanf("%d",arr+i);
build(1,1,n);
while(q--){
int t,l,r;
scanf("%d%d%d",&t,&l,&r);
if(t==1)
upd(l,r,1,1,n);
else if(t==2){
if(k!=1)
inc(l,r,1,1,n);
}
else
printf("%lld\n",tap(l,r,1,1,n));
}
return 0;
}
Compilation message (stderr)
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&n,&q,&k);
~~~~~^~~~~~~~~~~~~~~~~~~
sterilizing.cpp:73:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",arr+i);
~~~~~^~~~~~~~~~~~
sterilizing.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&t,&l,&r);
~~~~~^~~~~~~~~~~~~~~~~~~
# | 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... |