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>
#include <cstdio>
#define endl "\n"
/*/*(last choice)*/ #define int long long
#define all(x) x.begin(), x.end()
#define ll long long
#define tsts int t; cin>>t; while(t--)
#define start cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
int tree[10000005];
set<int>st;
vector<int>v;
int k;
void update(int l, int r, int idx, int val, int node=1)
{
if(l>idx || r<idx)
return;
if(l==r)
{
tree[node]=val;
return;
}
int mid=(l+r)/2;
update(l,mid,idx,val,node*2);
update(mid+1,r,idx,val,node*2+1);
tree[node]=tree[node*2]+tree[node*2+1];
}
void upd(int l, int r)
{
auto it=st.lower_bound(l);
auto it2=st.upper_bound(r);
vector<int>er;
for(; it!=it2; it++)
{
v[*it]/=k;
update(0,1e6,*it,v[*it]);
if(v[*it]==0)
er.push_back(*it);
}
for(auto c:er)
st.erase(c);
}
int gett(int l, int r, int ul, int ur, int node=1)
{
if(l>ur || r<ul)
return 0;
if(l>=ul && r<=ur)
return tree[node];
int mid=(l+r)/2;
return (gett(l,mid,ul,ur,node*2) + gett(mid+1,r,ul,ur,node*2+1));
}
signed main()
{
start
//freopen("codeblocksinput.txt", "w", stdout);
int n,q;
cin>>n>>q>>k;
v.resize(n);
for(int i=0; i<n; i++)
{
cin>>v[i];
update(0,1e6,i,v[i]);
if(v[i]>0)
st.insert(i);
}
while(q--)
{
int x, l ,r;
cin>>x>>l>>r;
if(x==1)
{
v[l-1]=r;
if(l>0)
st.insert(l-1);
update(0,1e6,l-1,r);
}
else if(x==2)
{
if(k==1)
continue;
upd(l-1,r-1);
}
else
cout<<gett(0,1e6,l-1,r-1)<<endl;
}
}
# | 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... |