Submission #777108

#TimeUsernameProblemLanguageResultExecution timeMemory
777108ind1vAddk (eJOI21_addk)C++11
0 / 100
795 ms1924 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int K = 15; struct fenwick_tree { int64_t fenw[N]; void upd(int idx, int val) { for (; idx < N; idx |= (idx + 1)) { fenw[idx] += val; } } int64_t get(int idx) { int64_t res = 0; for (; idx >= 0; idx &= (idx + 1), --idx) { res += fenw[idx]; } return res; } int64_t get(int l, int r) { return get(r) - get(l - 1); } }; int n, k; int a[N]; int64_t p[N]; int idx[K]; int q; fenwick_tree ft; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; p[i] = a[i] + p[i - 1]; } for (int i = 1; i <= n; i++) { ft.upd(i, p[i]); } cin >> q; while (q--) { int t; cin >> t; if (t == 1) { for (int i = 1; i <= k; i++) { cin >> idx[i]; } } else if (t == 2) { int l, r, m; cin >> l >> r >> m; int64_t ans = 0; for (int i = l; i <= r; i++) { if (i - l + 1 >= m) { ans += p[i] - p[i - l]; } } cout << ans << '\n'; // assert(m <= r - l + 1); // cout << ft.get(min(l + m - 1, r), r) - ft.get(l - 1, l + (r - min(l + m - 1, r) + 1) - 2) << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...