#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int G = 1e6 + 10;
int n, m, v[MAX], op, seg[4 * G], x, y, h;
void update(int p, int q, int ini, int fim, int pos, int val){
if(fim < p || q < ini) return;
if(p <= ini && fim <= q){
seg[pos] += val;
return;
}
int m = (ini + fim) / 2;
update(p, q, ini, m, 2 * pos, val);
update(p, q, m + 1, fim, 2 * pos + 1, val);
return;
}
int query(int id, int ini, int fim, int pos){
if(id < ini || fim < id) return 0;
if(ini == fim) return seg[pos];
int m = (ini + fim) / 2;
int a = query(id, ini, m, 2 * pos);
int b = query(id, m + 1, fim, 2 * pos + 1);
return seg[pos] + a + b;
}
int main(){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++){
scanf("%d", &v[i]);
if(i > 1){
int a = min(v[i], v[i - 1]);
int b = max(v[i], v[i - 1]);
update(a, b, 1, G, 1, 1);
}
}
for(int i = 1; i <= m; i++){
scanf("%d", &op);
if(op == 1){
scanf("%d %d", &x, &y);
if(x > 1){
int a = min(v[x], v[x - 1]);
int b = max(v[x], v[x - 1]);
update(a, b, 1, G, 1, - 1);
a = min(y, v[x - 1]);
b = max(y, v[x - 1]);
update(a, b, 1, G, 1, 1);
}
if(x < n){
int a = min(v[x], v[x + 1]);
int b = max(v[x], v[x + 1]);
update(a, b, 1, G, 1, - 1);
a = min(y, v[x + 1]);
b = max(y, v[x + 1]);
update(a, b, 1, G, 1, 1);
}
v[x] = y;
continue;
}
scanf("%d", &h);
printf("%d\n", query(h, 1, G, 1));
}
return 0;
}
Compilation message
game.cpp: In function 'int main()':
game.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d", &v[i]);
| ~~~~~^~~~~~~~~~~~~
game.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d", &op);
| ~~~~~^~~~~~~~~~~
game.cpp:56:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | scanf("%d", &h);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
6612 KB |
Output is correct |
3 |
Correct |
5 ms |
6356 KB |
Output is correct |
4 |
Correct |
5 ms |
6588 KB |
Output is correct |
5 |
Correct |
5 ms |
6468 KB |
Output is correct |
6 |
Correct |
4 ms |
6612 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
6612 KB |
Output is correct |
3 |
Correct |
5 ms |
6356 KB |
Output is correct |
4 |
Correct |
5 ms |
6588 KB |
Output is correct |
5 |
Correct |
5 ms |
6468 KB |
Output is correct |
6 |
Correct |
4 ms |
6612 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
55 ms |
1408 KB |
Output is correct |
9 |
Correct |
106 ms |
9960 KB |
Output is correct |
10 |
Correct |
107 ms |
9948 KB |
Output is correct |
11 |
Correct |
49 ms |
1356 KB |
Output is correct |
12 |
Correct |
76 ms |
1996 KB |
Output is correct |
13 |
Correct |
66 ms |
1776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
6612 KB |
Output is correct |
3 |
Correct |
5 ms |
6356 KB |
Output is correct |
4 |
Correct |
5 ms |
6588 KB |
Output is correct |
5 |
Correct |
5 ms |
6468 KB |
Output is correct |
6 |
Correct |
4 ms |
6612 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
55 ms |
1408 KB |
Output is correct |
9 |
Correct |
106 ms |
9960 KB |
Output is correct |
10 |
Correct |
107 ms |
9948 KB |
Output is correct |
11 |
Correct |
49 ms |
1356 KB |
Output is correct |
12 |
Correct |
76 ms |
1996 KB |
Output is correct |
13 |
Correct |
66 ms |
1776 KB |
Output is correct |
14 |
Correct |
163 ms |
9624 KB |
Output is correct |
15 |
Correct |
159 ms |
9664 KB |
Output is correct |
16 |
Correct |
166 ms |
9592 KB |
Output is correct |
17 |
Correct |
164 ms |
9580 KB |
Output is correct |
18 |
Correct |
163 ms |
9640 KB |
Output is correct |