Submission #485271

#TimeUsernameProblemLanguageResultExecution timeMemory
485271MilosMilutinovicSterilizing Spray (JOI15_sterilizing)C++14
10 / 100
53 ms4516 KiB
/** * author: m371 * created: 06.11.2021 23:29:50 **/ #include <bits/stdc++.h> using namespace std; template <typename T> class fenwick { public: vector<T> fenw; int n; fenwick(int _n) : n(_n) { fenw.resize(n); } void modify(int x, T v) { while (x < n) { fenw[x] += v; x |= (x + 1); } } T get(int x) { T v{}; while (x >= 0) { v += fenw[x]; x = (x & (x + 1)) - 1; } return v; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q, k; cin >> n >> q >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (k == 1) { fenwick<long long> fenw(n); for (int i = 0; i < n; i++) { fenw.modify(i, a[i]); } while (q--) { int foo; cin >> foo; if (foo == 1) { int pos, val; cin >> pos >> val; --pos; fenw.modify(pos, val - a[pos]); a[pos] = val; } if (foo == 2) { int l, r; cin >> l >> r; } if (foo == 3) { int l, r; cin >> l >> r; --l, --r; cout << fenw.get(r) - fenw.get(l - 1) << '\n'; } } } else { } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...