#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pll pair<long long,long long>
#define int long long
using namespace std;
/*using namespace __gnu_pbds;
template<class T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
const int mod=1e9+7;
const int N=1e5+1;
const long long inf=1e18;
int a[N],t[N*4],add[N*4];
void up(int x,int l,int r,int pos){
if(l==r){
t[x]=a[l];
return;
}
int m=(l+r)/2;
if(pos<=m) up(x+x,l,m,pos);
else up(x+x+1,m+1,r,pos);
t[x]=t[x+x]+t[x+x+1];
}
int get(int x,int l,int r,int ll,int rr){
if(l>rr || r<ll){
return 0;
}
if(ll<=l && r<=rr){
return t[x];
}
int m=(l+r)/2;
return get(x+x,l,m,ll,rr)+get(x+x+1,m+1,r,ll,rr);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie();
int n,k;
cin>> n>>k;
for(int i=1;i<=n;i++){
cin>> a[i];
up(1,1,n,i);
}
int q;
cin>> q;
while(q--){
int t;
cin>> t;
if(t==1){
vector< int >v, vv;
v.push_back( 0 );
vv.push_back( 0 );
for( int i = 1, x; i <= k; ++i )
{
cin >>x;
v.push_back( x );
vv.push_back( a[x] );
}
for( int i = 1; i <= k; ++i )
{
if( i == k )
a[v[i]] = vv[1];
else
a[v[i]] = vv[i + 1];
up(1, 1, n, v[i]);
}
}
else {
int l,r,m;
cin>> l>>r>>m;
int ans=get(1,1,n,l,r)*m;
int c=1;
for(int i=l+min(m-1,n/2)-1;i>=l;i--){
ans-=a[i]*c;
c++;
}
c=1;
for(int i=r-min(m-1,n/2)+1;i<=r;i++){
ans-=a[i]*c;
c++;
}
cout<< ans<<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... |