This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |