# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
541219 |
2022-03-22T18:58:28 Z |
Fidan |
Addk (eJOI21_addk) |
C++17 |
|
74 ms |
1992 KB |
#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;
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 {
s=sumpre(l, l+k/2-1, pre, dp)+sumsuf(l+k/2, r, pre, dp);
}
cout<<s<<endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
1992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |