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 ll;
typedef long double ld;
const ll N = 1000'010;
ll sumpre(ll x, ll y, vector<ll> &pre, vector<ll> &dp){
return pre[y]-pre[x-1]-(x-1)*(dp[y]-dp[x-1]);
}
ll sumsuf(ll x, ll y, vector<ll> &pre, vector<ll> &dp){
return (y-x+2)*(dp[y]-dp[x-1])-sumpre(x, y, pre, dp);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k, i;
cin>>n>>k;
vector<ll> a(n+1, 0);
for(i=1; i<=n; i++){
cin>>a[i];
}
vector<ll> pre(n+1, 0);
vector<ll> dp(n+1, 0);
for(i=1; i<=n; i++){
pre[i]=pre[i-1]+i*a[i];
dp[i]=dp[i-1]+a[i];
}
ll q;
cin>>q;
while(q--){
ll t;
cin>>t;
if(t==1){
for(i=0; i<k; i++){
ll x1;
cin>>x1;
}
}
else {
ll l, r, m, k, s=0, b;
cin>>l>>r>>m;
k=r-l+1;
if(k>=2*m){
s=sumpre(l, l+m-1, pre, dp)+m*(dp[r-m]-dp[l+m-1])+sumsuf(r-m+1, r, pre, dp);
}
else {
b=k-m+1;
s=sumpre(l, l+b-1, pre, dp)+b*(dp[r-b]-dp[l+b-1])+sumsuf(r-b+1, r, pre, dp);
}
cout<<s<<endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |