#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using namespace std;
using pt = complex<f80>;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 100000
int n, m, h[100000], t[1000001];
void upd(int p, int k) { for (; p < sizeof t / sizeof *t; p+=p&-p) t[p]+=k; }
int qry(int p) { int z{0}; for(; p;p-=p&-p)z+=t[p];return z; }
void cal(int i, int k)
{
if (h[i] > h[i-1]) upd(h[i-1]+1, k), upd(h[i]+1, -k);
else if (h[i] < h[i-1]) upd(h[i]+1, k), upd(h[i-1]+1, -k);
}
int main()
{
ShinLena;
cin >> n >> m >> h[0];
for (int i = 1; i < n; ++i) cin >> h[i], cal(i, 1);
for (int t, x, y; m--;)
{
cin >> t >> x;
if (t == 1)
{
--x; cin >> y;
if (x) cal(x, -1);
if (x + 1 < n) cal(x+1, -1);
h[x] = y;
if (x) cal(x, 1);
if (x + 1 < n) cal(x+1, 1);
}
else
{
cout << qry(x) << '\n';
}
}
return 0;
}
Compilation message
game.cpp: In function 'void upd(int, int)':
game.cpp:28:35: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
28 | void upd(int p, int k) { for (; p < sizeof t / sizeof *t; p+=p&-p) t[p]+=k; }
| ~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4572 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4572 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
25 ms |
5460 KB |
Output is correct |
9 |
Correct |
30 ms |
6772 KB |
Output is correct |
10 |
Correct |
34 ms |
6884 KB |
Output is correct |
11 |
Correct |
21 ms |
5456 KB |
Output is correct |
12 |
Correct |
28 ms |
6492 KB |
Output is correct |
13 |
Correct |
28 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4572 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
25 ms |
5460 KB |
Output is correct |
9 |
Correct |
30 ms |
6772 KB |
Output is correct |
10 |
Correct |
34 ms |
6884 KB |
Output is correct |
11 |
Correct |
21 ms |
5456 KB |
Output is correct |
12 |
Correct |
28 ms |
6492 KB |
Output is correct |
13 |
Correct |
28 ms |
6480 KB |
Output is correct |
14 |
Correct |
42 ms |
6740 KB |
Output is correct |
15 |
Correct |
41 ms |
6944 KB |
Output is correct |
16 |
Correct |
42 ms |
6740 KB |
Output is correct |
17 |
Correct |
42 ms |
6740 KB |
Output is correct |
18 |
Correct |
41 ms |
6740 KB |
Output is correct |