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;
int main(){
long long n,k;
cin>>n>>k;
long long a[n];
for(long long i=0;i<n;i++){
cin>>a[i];
}
long long q;
cin>>q;
long long sums[q];
long long u = 0;
if(k==1){
for(long long i=0;i<q;i++){
long long x;
cin>>x;
if(x==1){
long long y;
cin>>y;
continue;
}
else{
long long l,r,m;
cin>>l>>r>>m;
long long s = 0;
long long d = r-l+1;
for(long long j=l-1; j<r; j++){
long long p = j-l+2;
if(p<m && !(d-p+1<m)){
s+=a[j]*p;
}
else if(d-p+1<m && !(p<m)){
s+=a[j]*(d-p+1);
}
else if(p<m && d-p+1<m){
s+=a[j]*min(p-1,d-p);
}
else{
s+=a[j]*m;
}
}
sums[u] = s;
u++;
}
}
}
for(long long i=0;i<u-1;i++){
cout<<sums[i]<<endl;
}
cout<<sums[u-1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |