#include <bits/stdc++.h>
using namespace std;
const int NM = 1e5, LIM = 1e6;
int N, M, a[NM+5];
int bit[LIM+5];
void update(int x, int val){
while (x <= LIM){
bit[x] += val;
x += x & (-x);
}
}
int get(int x){
int res = 0;
while (x > 0){
res += bit[x];
x -= x & (-x);
}
return res;
}
void upd(int pos, int d){
if (pos > 1){
int l = min(a[pos], a[pos-1])+1, r = max(a[pos], a[pos-1])-1;
if (l <= r){
update(l, d);
update(r+1, -d);
}
}
if (pos < N){
int l = min(a[pos], a[pos+1])+1, r = max(a[pos], a[pos+1])-1;
if (l <= r){
update(l, d);
update(r+1, -d);
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++) cin >> a[i];
for (int i = 1; i < N; i++){
int l = min(a[i], a[i+1])+1, r = max(a[i], a[i+1])-1;
if (l <= r){
update(l, 1);
update(r+1, -1);
}
}
while (M--){
int type; cin >> type;
if (type == 1){
int pos, val; cin >> pos >> val;
upd(pos, -1);
a[pos] = val;
upd(pos, 1);
}
else{
int H; cin >> H;
cout << get(H) << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4572 KB |
Output is correct |
7 |
Correct |
2 ms |
4572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4572 KB |
Output is correct |
7 |
Correct |
2 ms |
4572 KB |
Output is correct |
8 |
Correct |
30 ms |
5468 KB |
Output is correct |
9 |
Correct |
33 ms |
6916 KB |
Output is correct |
10 |
Correct |
35 ms |
6740 KB |
Output is correct |
11 |
Correct |
19 ms |
3164 KB |
Output is correct |
12 |
Correct |
38 ms |
6432 KB |
Output is correct |
13 |
Correct |
33 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4572 KB |
Output is correct |
7 |
Correct |
2 ms |
4572 KB |
Output is correct |
8 |
Correct |
30 ms |
5468 KB |
Output is correct |
9 |
Correct |
33 ms |
6916 KB |
Output is correct |
10 |
Correct |
35 ms |
6740 KB |
Output is correct |
11 |
Correct |
19 ms |
3164 KB |
Output is correct |
12 |
Correct |
38 ms |
6432 KB |
Output is correct |
13 |
Correct |
33 ms |
6484 KB |
Output is correct |
14 |
Correct |
44 ms |
7000 KB |
Output is correct |
15 |
Correct |
46 ms |
6736 KB |
Output is correct |
16 |
Correct |
44 ms |
6744 KB |
Output is correct |
17 |
Correct |
44 ms |
6740 KB |
Output is correct |
18 |
Correct |
43 ms |
6740 KB |
Output is correct |