Submission #580836

#TimeUsernameProblemLanguageResultExecution timeMemory
580836penguin133Addk (eJOI21_addk)C++14
92 / 100
66 ms7528 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pi pair<int, int> #define pii pair<int, pair<int, int> > int P[200005], P2[200005], A[200005], S[200005]; void solve(){ int n, k;cin >> n >> k; for(int i=1;i<=n;i++){ cin >> A[i]; P[i] = P[i-1] + A[i]; P2[i] = P2[i-1] + i*A[i]; } for(int i=n;i>=1;i--){ S[i] = S[i+1] + A[i]*(n-i+1); } int q;cin >> q; while(q--){ int x;cin >> x; if(x == 1){ int p;cin >> p; } else{ int l,r,m; cin >> l >> r >> m; int tmp = (r-l+1); m = min(m, tmp+1-m); int ans = 0; ans += P2[l+m-2] - P2[l-1] - (l-1)*(P[l+m-2] - P[l-1]); ans += S[r-m+2] - S[r+1] - (n-r)*(P[r] - P[r-m+1]); ans += m*(P[r-m+1] - P[l+m-2]); cout << ans << '\n'; } } } main(){ ios::sync_with_stdio(0);cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } }

Compilation message (stderr)

Main.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...