#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, MXN = 1e6 + 9;
int n, q, A[N], L[MXN], G[MXN];
inline void AddL(int i, int val)
{
for (i ++; i < MXN; i += i & -i)
L[i] += val;
}
inline int GetL(int i)
{
int ret = 0;
for (i ++; i; i -= i & -i)
ret += L[i];
return (ret);
}
inline void AddG(int i, int val)
{
for (i = MXN - i - 1; i < MXN; i += i & -i)
G[i] += val;
}
inline int GetG(int i)
{
int ret = 0;
for (i = MXN - i - 1; i; i -= i & - i)
ret += G[i];
return (ret);
}
int main()
{
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++)
scanf("%d", &A[i]);
for (int i = 1; i < n; i++)
{
AddL(max(A[i], A[i + 1]), 1);
AddG(min(A[i], A[i + 1]), 1);
}
for (; q; q --)
{
int t, a, b;
scanf("%d%d", &t, &a);
if (t == 2)
{
printf("%d\n", n - 1 - (GetL(a - 1) + GetG(a + 1)));
continue;
}
scanf("%d", &b);
if (a > 1)
{
AddL(max(A[a], A[a - 1]), -1);
AddG(min(A[a], A[a - 1]), -1);
}
if (a < n)
{
AddL(max(A[a], A[a + 1]), -1);
AddG(min(A[a], A[a + 1]), -1);
}
A[a] = b;
if (a > 1)
{
AddL(max(A[a], A[a - 1]), 1);
AddG(min(A[a], A[a - 1]), 1);
}
if (a < n)
{
AddL(max(A[a], A[a + 1]), 1);
AddG(min(A[a], A[a + 1]), 1);
}
}
return 0;
}
Compilation message
game.cpp: In function 'int main()':
game.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~
game.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &A[i]);
~~~~~^~~~~~~~~~~~~
game.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &t, &a);
~~~~~^~~~~~~~~~~~~~~~
game.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &b);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
7 ms |
6776 KB |
Output is correct |
3 |
Correct |
7 ms |
6520 KB |
Output is correct |
4 |
Correct |
7 ms |
6648 KB |
Output is correct |
5 |
Correct |
7 ms |
6776 KB |
Output is correct |
6 |
Correct |
8 ms |
6776 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
7 ms |
6776 KB |
Output is correct |
3 |
Correct |
7 ms |
6520 KB |
Output is correct |
4 |
Correct |
7 ms |
6648 KB |
Output is correct |
5 |
Correct |
7 ms |
6776 KB |
Output is correct |
6 |
Correct |
8 ms |
6776 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
40 ms |
1684 KB |
Output is correct |
9 |
Correct |
73 ms |
10692 KB |
Output is correct |
10 |
Correct |
76 ms |
10872 KB |
Output is correct |
11 |
Correct |
39 ms |
1656 KB |
Output is correct |
12 |
Correct |
49 ms |
2936 KB |
Output is correct |
13 |
Correct |
46 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
7 ms |
6776 KB |
Output is correct |
3 |
Correct |
7 ms |
6520 KB |
Output is correct |
4 |
Correct |
7 ms |
6648 KB |
Output is correct |
5 |
Correct |
7 ms |
6776 KB |
Output is correct |
6 |
Correct |
8 ms |
6776 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
40 ms |
1684 KB |
Output is correct |
9 |
Correct |
73 ms |
10692 KB |
Output is correct |
10 |
Correct |
76 ms |
10872 KB |
Output is correct |
11 |
Correct |
39 ms |
1656 KB |
Output is correct |
12 |
Correct |
49 ms |
2936 KB |
Output is correct |
13 |
Correct |
46 ms |
2808 KB |
Output is correct |
14 |
Correct |
103 ms |
10748 KB |
Output is correct |
15 |
Correct |
102 ms |
10704 KB |
Output is correct |
16 |
Correct |
94 ms |
10744 KB |
Output is correct |
17 |
Correct |
98 ms |
10744 KB |
Output is correct |
18 |
Correct |
106 ms |
10676 KB |
Output is correct |