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;
#define ll long long
#define lld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define IShowSpeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=1e5+10;
const int K=405;
const int mod=1e9+7;
const ll inf=1e18+228;
const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};
ll h[N],t[4*N];
void build(ll v, ll tl, ll tr)
{
if(tl==tr) {
t[v]=h[tl];
return;
}
ll mid = (tl + tr) >> 1;
build(v+v,tl,mid);
build(v+v+1,mid+1,tr);
t[v]=t[v+v]+t[v+v+1];
}
void upd(ll v, ll tl, ll tr, ll pos)
{
if(tl==tr) {
t[v]=h[tl];
return;
}
ll mid = (tl + tr) >> 1;
if(pos<=mid) upd(v+v,tl,mid,pos);
else upd(v+v+1,mid+1,tr,pos);
t[v]=t[v+v]+t[v+v+1];
}
ll get(ll v, ll tl, ll tr, ll l, ll r)
{
if(l<=tl && tr<=r) return t[v];
if(r<tl || tr<l) return 0;
ll mid = (tl + tr) >> 1;
return get(v+v,tl,mid,l,r)+get(v+v+1,mid+1,tr,l,r);
}
int main()
{
//freopen("closing.in","r",stdin);
//freopen("closing.out","w",stdout);
IShowSpeed
ll tt=1;
//cin>>tt;
for(int cas=1;cas<=tt;cas++)
{
//for(int i=0;i<=K;i++) bl[i]={0,0};
//for(int i=1;i<=N-10;i++) h[i]=0;
//cout<<"Case "<<cas<<":\n";
ll n,k,q;
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>h[i];
build(1,1,n);
cin>>q;
while(q--)
{
ll tp;
cin>>tp;
if(tp==1) {
vector<ll>v,lol;
for(int i=1;i<=k;i++) {
ll x;
cin>>x;
v.pb(x);
lol.pb(h[x]);
}
for(int i=0;i<k;i++)
{
if(i==k-1) {
h[v[i]]=lol[0];
}
else {
h[v[i]]=lol[i+1];
}
upd(1,1,n,v[i]);
}
}
else {
ll l,r,m,s;
cin>>l>>r>>m;
s=get(1,1,n,l,r)*m;
for(int i=l,x=m-1;x>0;i++,x--) s-=h[i]*x;
for(int i=r,x=m-1;x>0;i--,x--) s-=h[i]*x;
cout<<s<<"\n";
}
}
}
}
/*
8 3
7 2 5 1 9 3 4 6
3
2 2 7 4
1 2 5 8
2 2 7 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |