이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int H = 1e6 + 5;
struct fenwick_tree {
int f[H];
fenwick_tree() {
memset(f, 0, sizeof(f));
}
void upd(int i, int x) {
for (; i < H; i += i & -i) {
f[i] += x;
}
}
void upd(int l, int r, int x) {
upd(l, x);
upd(r + 1, -x);
}
int get(int i) {
int r = 0;
for (; i > 0; i -= i & -i) {
r += f[i];
}
return r;
}
int get(int l, int r) {
return get(r) - get(l - 1);
}
};
int n, m;
int h[N];
fenwick_tree ft;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> h[i];
if (i >= 2) {
ft.upd(min(h[i - 1], h[i]), max(h[i - 1], h[i]), 1);
}
}
while (m--) {
int t;
cin >> t;
if (t == 1) {
int pos, val;
cin >> pos >> val;
if (pos > 1) {
ft.upd(min(h[pos - 1], h[pos]), max(h[pos - 1], h[pos]), -1);
}
if (pos < n) {
ft.upd(min(h[pos + 1], h[pos]), max(h[pos + 1], h[pos]), -1);
}
h[pos] = val;
if (pos > 1) {
ft.upd(min(h[pos - 1], h[pos]), max(h[pos - 1], h[pos]), +1);
}
if (pos < n) {
ft.upd(min(h[pos + 1], h[pos]), max(h[pos + 1], h[pos]), +1);
}
} else if (t == 2) {
int H;
cin >> H;
cout << ft.get(H) << '\n';
}
}
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... |