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 N 1000000
#define ll long long
vector<ll> lista(N), prefiksalnalista(N);
ll n;
void update(int p, ll value){
lista[p]=value;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
ll q,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>lista[i];
prefiksalnalista[i]=prefiksalnalista[i-1]+lista[i];
}
cin>>q;
for(int i=0;i<q;i++){
short c;
cin>>c;
if(c==1){
int a;
cin>>a;
int first=lista[a-1];
int b=a;
for(int i=0;i<k-1;i++){
int d=b;
cin>>b;
update(d-1,lista[b-1]);
}
update(b-1,first);
}
else if(c==2){
int a,b,m;
cin>>a>>b>>m;
ll rezultat=0;
if(min(b-m-a+2,2*m-2)==(b-m-a+2))
for(int i=a;i<=b-m+1;i++)
rezultat+=prefiksalnalista[i+m-1]-prefiksalnalista[i-1];
else{
for(int i=a,cnt=1;i<a+m;i++,cnt++) rezultat+=cnt*lista[i];
for(int i=b,cnt=1;i>b-m;i--,cnt++) rezultat+=cnt*lista[i];
rezultat+=m*(prefiksalnalista[b-m]-prefiksalnalista[a+m-1]);
}
cout<<rezultat<<'\n';
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |