#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
int n,q,k,x,y,type;
struct SegmentTree{
ll sum;
int Max;
}sgt[MAXN<<2];
void updatePoint(int id, int l, int r, int pos, int val){
if(pos<l||r<pos) return;
if(l==r) return sgt[id].sum=sgt[id].Max=val, void();
int mid=(l+r)>>1;
updatePoint(id<<1,l,mid,pos,val);
updatePoint(id<<1|1,mid+1,r,pos,val);
sgt[id].sum=sgt[id<<1].sum+sgt[id<<1|1].sum;
sgt[id].Max=max(sgt[id<<1].Max,sgt[id<<1|1].Max);
}
void updateRange(int id, int l, int r, int u, int v){
if(v<l||r<u||sgt[id].Max==0) return;
if(l==r) return sgt[id].sum/=k, sgt[id].Max=sgt[id].sum, void();
int mid=(l+r)>>1;
updateRange(id<<1,l,mid,u,v);
updateRange(id<<1|1,mid+1,r,u,v);
sgt[id].sum=sgt[id<<1].sum+sgt[id<<1|1].sum;
sgt[id].Max=max(sgt[id<<1].Max,sgt[id<<1|1].Max);
}
ll getsum(int id, int l, int r, int u, int v){
if(v<l||r<u) return 0ll;
if(u<=l&&r<=v) return sgt[id].sum;
int mid=(l+r)>>1;
return getsum(id<<1,l,mid,u,v)+getsum(id<<1|1,mid+1,r,u,v);
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n >> q >> k;
for(int i = 1; i<=n; ++i)
cin >> x, updatePoint(1,1,n,i,x);
while(q--){
cin >> type >> x >> y;
if(type==1) updatePoint(1,1,n,x,y);
else if(type==2&&k!=1) updateRange(1,1,n,x,y);
else cout << getsum(1,1,n,x,y) << "\n";
}
}
//block = q/(n+30)
//type 1 complexity: block*n*log(n)
//type 2 complexity: block*30*n*log(n)
//worst complexity ~ 5e7
Compilation message (stderr)
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:54:45: note: in expansion of macro 'fo'
54 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
sterilizing.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:54:45: note: in expansion of macro 'fo'
54 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
# | 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... |