# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
839681 | konber | Addk (eJOI21_addk) | C++14 | 9 ms | 976 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 <iostream>
#include <vector>
using namespace std;
typedef long long ll;
vector<ll> pref1, pref2;
ll prefix_sum1(int a, int b){
return pref1[b] - pref1[a-1];
}
ll prefix_sum2(int a, int b){
return pref2[b] - pref2[a-1] - (a-1)*prefix_sum1(a, b);
}
int main()
{
int N, K;
scanf("%d%d", &N, &K);
if(K!=1)
return 0;
vector<int> a(N+1);
pref1.resize(N+1, 0);
pref2.resize(N+1, 0);
for(int i=1; i <= N; i++){
scanf("%d", &a[i]);
}
for(int i=1; i <= N; i++){
pref1[i] = pref1[i-1] + a[i];
pref2[i] = pref2[i-1] + i*a[i];
}
int Q;
scanf("%d", &Q);
while(Q--){
int q;
scanf("%d", &q);
if(q==1){
int ig;
scanf("%d", &ig);
continue;
}
int l, r, m;
scanf("%d%d%d", &l, &r, &m);
/*
ll ans=0;
for(int i=l; i <= r-m+1; i++){
ans += prefix_sum1(i, i+m-1);
}
printf("%lld\n", ans);
*/
if(m==1){
printf("%lld\n", prefix_sum1(l, r));
continue;
}
int ind1=l+m-1, ind2=r-m+1;
if(ind1 <= ind2){
ll ans = m*prefix_sum1(ind1, ind2);
ans += prefix_sum2(l, ind1-1);
ans += m*prefix_sum1(ind2+1, r) - prefix_sum2(ind2+1, r);
printf("%lld\n", ans);
}
else{
m = ind2-l+1;
swap(ind1, ind2);
ll ans;
if(m==1) ans=prefix_sum1(l, r);
else{
ans = m*prefix_sum1(ind1, ind2);
ans += prefix_sum2(l, ind1-1);
ans += m*prefix_sum1(ind2+1, r) - prefix_sum2(ind2+1, r);
}
printf("%lld\n", ans);
}
}
}
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... |