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<iostream>
#include<deque>
using namespace std;
long long lazy[1000005],seg[1000005],a[100005];
void push(int id,int left,int right)
{
int mid = (left + right) / 2;
seg[id * 2] += lazy[id] * (mid - left + 1);
seg[id * 2 + 1] += lazy[id] * (right - mid);
lazy[id * 2] += lazy[id];
lazy[id * 2 + 1] += lazy[id];
lazy[id] = 0;
}
void update(int id,int l,int r,int u,int v,long long val)
{
if (u > v) return;
if (u == l and v == r)
{
seg[id] += val * (v - u + 1);
lazy[id] += val;
return;
}
push(id, l, r);
int mid = (l + r) / 2;
update(id * 2, l, mid, u, min(v, mid), val);
update(id * 2 + 1, mid + 1, r, max(u, mid + 1), v, val);
seg[id] = seg[id * 2] + seg[id * 2 + 1];
}
long long get(int id,int l,int r,int u,int v)
{
if(u > v)
{
return 0;
}
if(u == l and v == r)
{
return seg[id];
}
push(id,l,r);
int mid = (l + r)/2;
return get(id * 2,l,mid,u,min(v,mid)) + get(id * 2 + 1,mid + 1,r,max(u,mid + 1),v);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n,k,q;
cin >> n >> k;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
update(1,0,n,i,n,a[i]);
}
cin >> q;
while(q--)
{
long long int type,l,r,x;
cin >> type;
if(type == 2)
{
cin >> l >> r >> x;
int h = (l + x - 1);
k = r - x;
cout << get(1,0,n,h,r) - get(1,0,n,l - 1,k) << endl;
}
else
{
deque<int> v,d;
for(int i = 0;i < k;i++)
{
int x;
cin >> x;
v.push_back(x);
d.push_back(x);
}
d.push_back(d[0]);
d.pop_front();
for(int i = 0;i < k;i++)
{
update(1,0,n,v[i],n,a[d[i]] - a[v[i]]);
}
int h = a[v[0]];
for(int i = 0;i < k - 1;i++)
{
a[v[i]] = a[d[i]];
}
a[v[k - 1]] = h;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |