Submission #583711

#TimeUsernameProblemLanguageResultExecution timeMemory
583711n3rm1nAddk (eJOI21_addk)C++17
36 / 100
91 ms636 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAXN = 1e4 + 10; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int n, k, a[MAXN]; void read_array() { cin >> n >> k; for (int i = 1; i <= n; ++ i) { cin >> a[i]; } } long long answer(int l, int r, int m) { long long ans = 0; for (int i = l; i <= r; ++ i) { long long cnt = m; long long before = i - l, after = r - i; if(before < m)cnt -= m - before - 1; if(i > r - m + 1)cnt -= m - after - 1; ///cout << i << " / " << cnt << endl; ans += 1ll * a[i] * cnt; } return ans; } void queries() { int q; cin >> q; int type, l, r, m, x; while(q --) { cin >> type; if(type & 1) { cin >> x; continue; } else { cin >> l >> r >> m; cout << answer(l, r, m) << endl; } } } int main() { speed(); read_array(); queries(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...