이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <iostream>
using namespace std;
const int N = 1e5 + 100;
const int M = 1e6;
int n, m, t;
int h[N];
int d[M + 1];
void update(int x, int s)
{
while(x <= M){
d[x] += s;
x += (x & -x);
}
}
int get(int x){
int s = 0;
while(x > 0){
s += d[x];
x -= (x & -x);
}
return s;
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i < n; i++){
int l, r;
l = min(h[i], h[i + 1]);
r = max(h[i], h[i + 1]);
update(l, +1);
update(r + 1, -1);
}
while(m--){
int pos, val, l, r, H;
cin >> t;
if(t == 1){
cin >> pos >> val;
if(pos != 1){
l = min(h[pos], h[pos - 1]);
r = max(h[pos], h[pos - 1]);
update(l, -1); update(r + 1, +1);
l = min(val, h[pos - 1]);
r = max(val, h[pos - 1]);
update(l, +1); update(r + 1, -1);
}
if(pos != n){
l = min(h[pos], h[pos + 1]);
r = max(h[pos], h[pos + 1]);
update(l, -1); update(r + 1, +1);
l = min(val, h[pos + 1]);
r = max(val, h[pos + 1]);
update(l, +1); update(r + 1, -1);
}
h[pos] = val;
}
else{
cin >> H;
cout << get(H) << endl;
}
}
}
/*
3 3
1 5 1
2 3
1 1 5
2 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |