# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
633146 | Jovan26 | Addk (eJOI21_addk) | C++14 | 157 ms | 6616 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;
long long rez;
int main(){
#define int long long
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin>>n;
long long k;
cin>>k;
long long a[n];
long long pref[n+1];
for(long i=0;i<n;i++) cin>>a[i];
long long q;
pref[0] = 0;
int preff[n+1];
preff[0] = 0;
for(int i=1;i<=n;i++){
pref[i] = pref[i-1]+a[i-1];
}
for(int i=1;i<=n;i++){
preff[i] = preff[i-1]+pref[i-1];
}
//for(int i=0;i<=n;i++) cout<<pref[i]<<" ";
cin>>q;
bool p = false;
for(long long j=0;j<q;j++){
int x;
cin>>x;
if(x==1){
int y;
cin>>y;
continue;
}
long long l,r,m;
p = true;
cin>>l>>r>>m;
long long ma = min(m,(r-l+1-m+1));
rez = 0;
l--;
r--;
long long z = 0;
int l1 = l;
int r1 = l1+ma-2;
int rez1 =(r1-l1+1)*pref[r1+1]-(preff[r1+1]-preff[l1]);
int r2 = r;
int l2 = r2-ma+2;
int rez2 =-(r2-l2+1)*pref[l2]+(preff[r2+2]-preff[l2+1]);
int u = (r-l+1)-(r1-l1+1)-(r2-l2+1);
int rez3 = ma*(pref[l2]-pref[r1+1]);
rez+=rez1;
rez+=rez2;
rez+=rez3;
cout<<rez<<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |