#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
return i << j.first << ' ' << j.second;
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
i << '{' << j.size() << ':';
for (T ii : j) i << ' ' << ii;
return i << '}';
}
typedef long long ll;
typedef pair<int, int> pi;
struct seg {
int l, r, v;
seg *ch[2]{};
seg(int _l, int _r) : l(_l), r(_r), v(0) {
if (l < r - 1) ch[0] = new seg(l, l + r >> 1), ch[1] = new seg(l + r >> 1, r);
}
void modify(int _l, int _r, int _d) {
if (_l >= _r) return;
if (_l <= l && r <= _r) {
v += _d;
return;
}
push();
if (_l < l + r >> 1) ch[0]->modify(_l, _r, _d);
if (l + r >> 1 < _r) ch[1]->modify(_l, _r, _d);
}
void push() {
ch[0]->v += v, ch[1]->v += v, v = 0;
}
int query(int i) {
if (l == r - 1) return v;
push();
return ch[i >= l + r >> 1]->query(i);
}
} rt(0, 1e6 + 5);
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
int a[n];
for (int &i : a) cin >> i;
for (int i = 1; i < n; ++i)
rt.modify(min(a[i - 1], a[i]) + 1, max(a[i - 1], a[i]), 1);
while (m--) {
int ty, x;
cin >> ty >> x;
if (ty == 1) {
int y;
cin >> y;
--x;
if (x) rt.modify(min(a[x - 1], a[x]) + 1, max(a[x - 1], a[x]), -1), rt.modify(min(a[x - 1], y) + 1, max(a[x - 1], y), 1);
if (x < n - 1) rt.modify(min(a[x + 1], a[x]) + 1, max(a[x + 1], a[x]), -1), rt.modify(min(a[x + 1], y) + 1, max(a[x + 1], y), 1);
a[x] = y;
}
else cout << rt.query(x) << '\n';
}
}
Compilation message
game.cpp: In constructor 'seg::seg(int, int)':
game.cpp:21:45: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | if (l < r - 1) ch[0] = new seg(l, l + r >> 1), ch[1] = new seg(l + r >> 1, r);
| ~~^~~
game.cpp:21:74: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | if (l < r - 1) ch[0] = new seg(l, l + r >> 1), ch[1] = new seg(l + r >> 1, r);
| ~~^~~
game.cpp: In member function 'void seg::modify(int, int, int)':
game.cpp:30:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | if (_l < l + r >> 1) ch[0]->modify(_l, _r, _d);
| ~~^~~
game.cpp:31:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | if (l + r >> 1 < _r) ch[1]->modify(_l, _r, _d);
| ~~^~~
game.cpp: In member function 'int seg::query(int)':
game.cpp:39:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | return ch[i >= l + r >> 1]->query(i);
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
94148 KB |
Output is correct |
2 |
Correct |
103 ms |
94236 KB |
Output is correct |
3 |
Correct |
104 ms |
94132 KB |
Output is correct |
4 |
Correct |
109 ms |
94340 KB |
Output is correct |
5 |
Correct |
102 ms |
94148 KB |
Output is correct |
6 |
Correct |
103 ms |
94136 KB |
Output is correct |
7 |
Correct |
100 ms |
94148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
94148 KB |
Output is correct |
2 |
Correct |
103 ms |
94236 KB |
Output is correct |
3 |
Correct |
104 ms |
94132 KB |
Output is correct |
4 |
Correct |
109 ms |
94340 KB |
Output is correct |
5 |
Correct |
102 ms |
94148 KB |
Output is correct |
6 |
Correct |
103 ms |
94136 KB |
Output is correct |
7 |
Correct |
100 ms |
94148 KB |
Output is correct |
8 |
Correct |
159 ms |
95268 KB |
Output is correct |
9 |
Correct |
301 ms |
95684 KB |
Output is correct |
10 |
Correct |
297 ms |
95624 KB |
Output is correct |
11 |
Correct |
143 ms |
95428 KB |
Output is correct |
12 |
Correct |
193 ms |
95676 KB |
Output is correct |
13 |
Correct |
246 ms |
95684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
94148 KB |
Output is correct |
2 |
Correct |
103 ms |
94236 KB |
Output is correct |
3 |
Correct |
104 ms |
94132 KB |
Output is correct |
4 |
Correct |
109 ms |
94340 KB |
Output is correct |
5 |
Correct |
102 ms |
94148 KB |
Output is correct |
6 |
Correct |
103 ms |
94136 KB |
Output is correct |
7 |
Correct |
100 ms |
94148 KB |
Output is correct |
8 |
Correct |
159 ms |
95268 KB |
Output is correct |
9 |
Correct |
301 ms |
95684 KB |
Output is correct |
10 |
Correct |
297 ms |
95624 KB |
Output is correct |
11 |
Correct |
143 ms |
95428 KB |
Output is correct |
12 |
Correct |
193 ms |
95676 KB |
Output is correct |
13 |
Correct |
246 ms |
95684 KB |
Output is correct |
14 |
Correct |
460 ms |
95336 KB |
Output is correct |
15 |
Correct |
467 ms |
95428 KB |
Output is correct |
16 |
Correct |
467 ms |
95428 KB |
Output is correct |
17 |
Correct |
472 ms |
95404 KB |
Output is correct |
18 |
Correct |
475 ms |
95428 KB |
Output is correct |