Submission #1280646

#TimeUsernameProblemLanguageResultExecution timeMemory
1280646kkkkkAddk (eJOI21_addk)C++20
92 / 100
32 ms5168 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 11; const int inf = 1e18; int a[N], s[N], rs[N], p[N]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k, q; cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; p[i] = a[i] + p[i - 1]; s[i] = s[i - 1] + a[i] * i; rs[i] = rs[i - 1] + a[i] * (n - i + 1); } cin >> q; while(q--){ int t; cin >> t; if(t == 1){ int x; cin >> x; } else{ int l, r, m; cin >> l >> r >> m; int len = (r - l + 1); int ans = (p[r - len + m] - p[l + len - m - 1]) * (len - m + 1); int L = l, R = l + (len - m) - 1; if(L <= R) ans += s[R] - s[L - 1] - (p[R] - p[L - 1]) * (L - 1); R = r, L = r - (len - m) + 1; if(L <= R) ans += rs[R] - rs[L - 1] - (p[R] - p[L - 1]) * (n - R); cout << ans << '\n'; } } } // hello karim nurbakyt sanzhar azamat congratulation europa asia america laplas
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...