# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1071305 | vjudge1 | Addk (eJOI21_addk) | C++17 | 0 ms | 0 KiB |
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;
typedef long long int;
typedef long double ld;
#define pb push_back
#define sz size
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fre(s) freopen(s".in", "r", stdin);freopen(s".out", "w", stdout);
#define s second
#define f first
#define ii pair<ll,ll>
const ll mod=1e9+7;
const int N=4e5+6;
const ll inf=1e12+5;
int n,k,d[N],g[N];
int main()
{
ios
cin>>n>>k;
for(int i=1;i<=n;++i)
{
cin>>d[i];
}
int q;
cin>>q;
while(q--)
{
int x;
cin>>x;
if(x==1)
{
for(int i=0;i<k;++i)
{
cin>>g[i];
}
if(k>1)
{
int h=d[g[0]];
for(int i=0;i<k-1;i++)
{
d[g[i]]=d[g[i+1]];
}
d[g[k-1]]=h;
}
}
else
{
int l,r,m;
cin>>l>>r>>m;
int ans=0;
if(r-l+1<m)
{
cout<<0<<"\n";
continue;
}
for(int i=l;i<=r;++i)
{
int cur=m;
cur-=max(ll0,m-(i-l+1));
cur-=max(ll0,m-(r-i+1));
ans+=d[i]*cur;
}
cout<<ans<<endl;
}
}
}