This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int MAXN = (int) 1e6;
int h[MAXN + 1];
int aib[MAXN + 1];
inline void update(int pos, int val) {
for(int i = pos; i <= MAXN; i += lsb(i)) {
aib[i] += val;
}
}
inline int query(int pos) {
int ans = 0;
for(int i = pos; i > 0; i -= lsb(i)) {
ans += aib[i];
}
return ans;
}
inline void solve(int l, int r, int val) {
if(l > r) {
swap(l, r);
}
update(l, val);
update(r + 1, -val);
}
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for(i = 1; i <= n; i++) {
cin >> h[i];
}
for(i = 1; i < n; i++) {
solve(h[i], h[i + 1], 1);
}
for(i = 1; i <= m; i++) {
int type, pos, val, H;
cin >> type;
if(type == 1) {
cin >> pos >> val;
if(pos > 1) {
solve(h[pos - 1], h[pos], -1);
solve(h[pos - 1], val, 1);
}
if(pos < n) {
solve(h[pos], h[pos + 1], -1);
solve(val, h[pos + 1], 1);
}
h[pos] = val;
}
else {
cin >> H;
cout << query(H) << "\n";
}
}
//cin.close();
//cout.close();
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... |