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;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
fast;
}
int n,k,q;
struct Node
{
int l,r;
Node*lc;
Node*rc;
ll sums[33];
ll numApplied;
Node(int L,int R,vl&a)
{
l = L,r = R;
int mid = (l + r)/2;
numApplied = 0;
for (int i = 0;i<=32;i++)sums[i] = 0;
if (l != r){
lc = new Node(l,mid,a);
rc = new Node(mid + 1,r,a);
for (int i = 0;i<=32;i++)
sums[i] = lc->sums[i] + rc->sums[i];
}
else{
sums[0] = a[l];
for (int i = 1;i<=32;i++)
sums[i] = sums[i - 1]/k;
}
}
};
void shift(Node*root,int s)
{
if (k != 1){
for (int i = 0;i<=32;i++)
root->sums[i] = (i + s <= 32 ? root->sums[i + s] : 0);
}
}
void push(Node*root)
{
shift(root,root->numApplied);
if (root->lc){
root->lc->numApplied += root->numApplied;
root->rc->numApplied += root->numApplied;
}
root->numApplied = 0;
}
void PointUpdate(Node*root,int pos,int x)
{
push(root);
if (!(root->l <= pos and pos <= root->r))return;
if (root->l == root->r){
root->numApplied = 0;
root->sums[0] = x;
for (int i = 1;i<=32;i++)
root->sums[i] = root->sums[i - 1]/k;
return;
}
PointUpdate(root->lc,pos,x);
PointUpdate(root->rc,pos,x);
for (int i = 0;i<=32;i++)
root->sums[i] = root->lc->sums[i] + root->rc->sums[i];
}
void Spray(Node*root,int l,int r)
{
push(root);
if (root->l > r or l > root->r)return;
if (l <= root->l and root->r <= r){
root->numApplied++;
push(root);
return;
}
Spray(root->lc,l,r);
Spray(root->rc,l,r);
for (int i = 0;i<=32;i++)
root->sums[i] = root->lc->sums[i] + root->rc->sums[i];
}
ll query(Node*root,int l,int r)
{
push(root);
if (root->l > r or l > root->r)return 0;
if (l <= root->l and root->r <= r)
return root->sums[0];
return query(root->lc,l,r) + query(root->rc,l,r);
}
int main()
{
setIO();
cin>>n>>q>>k;
vl a(n + 1);
for (int i = 1;i<=n;i++)cin>>a[i];
Node*root = new Node(1,n,a);
while (q--){
int t;
cin>>t;
if (t == 1){
int pos;
ll x;
cin>>pos>>x;
PointUpdate(root,pos,x);
}
if (t == 2){
int l,r;
cin>>l>>r;
Spray(root,l,r);
}
if (t == 3){
int l,r;
cin>>l>>r;
cout<<query(root,l,r)<<"\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... |