이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MXN = 100 * 1000 + 3;
int bit[MXN], a[MXN], n, q;
void upd(int x, int v = 1) {
for(; x <= n; x += (x & -x))
bit[x] += v;
}
void upd(int l, int r, int v) {
upd(l, v);
upd(r + 1, -v);
}
int qry(int x) {
int res = 0;
for(; x > 0; x -= (x & -x))
res += bit[x];
return res;
}
signed main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
cin >> n >> q;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(i > 1) {
int x = min(a[i - 1], a[i]);
int y = max(a[i - 1], a[i]);
upd(x, y, 1);
}
}
while(q--) {
int tp; cin >> tp;
if(tp == 1) {
int i, val;
cin >> i >> val;
if(i > 1) {
int x = min(a[i - 1], a[i]);
int y = max(a[i - 1], a[i]);
upd(x, y, -1);
}
if(i < n) {
int x = min(a[i + 1], a[i]);
int y = max(a[i + 1], a[i]);
upd(x, y, -1);
}
a[i] = val;
if(i > 1) {
int x = min(a[i - 1], a[i]);
int y = max(a[i - 1], a[i]);
upd(x, y, 1);
}
if(i < n) {
int x = min(a[i + 1], a[i]);
int y = max(a[i + 1], a[i]);
upd(x, y, 1);
}
} else {
int h; cin >> h;
cout << qry(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... |