#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 100005;
int n, q, a[MXN];
struct SMG {
#define mid ((l + r) >> 1)
pii val[MXN * 4];
void build(int id, int l, int r) {
if (l + 1 == r) {
val[id] = mp(a[l], l);
return;
}
build(id * 2 + 1, l, mid);
build(id * 2 + 2, mid, r);
val[id] = max(val[id * 2 + 1], val[id * 2 + 2]);
}
void modify(int id, int l, int r, int p) {
if (l + 1 == r) {
val[id] = mp(a[l], l);
return;
}
if (p < mid) modify(id * 2 + 1, l, mid, p);
else modify(id * 2 + 2, mid, r, p);
val[id] = max(val[id * 2 + 1], val[id * 2 + 2]);
}
pii query(int id, int l, int r, int _l, int _r) {
if (_r <= l || r <= _l) return mp(0LL, -1LL);
if (_l <= l && r <= _r) return val[id];
return max(query(id * 2 + 1, l, mid, _l, _r), query(id * 2 + 2, mid, r, _l, _r));
}
} smg;
struct BIT {
int n, val[MXN];
void init(int _n) {
n = _n;
fill(val + 1, val + n + 1, 0);
}
void modify(int id, int v) {
for (id++; id <= n; id += (id & -id)) val[id] += v;
}
int query(int id) {
int ans = 0;
for (; id > 0; id -= (id & -id)) ans += val[id];
return ans;
}
int query(int l, int r) {
return query(r) - query(l);
}
} B;
int calc(int l, int r) {
if (l >= r) return 0;
auto [big, rt] = smg.query(0, 0, n, l, r);
int ans = 1;
debug(l, r, rt, B.query(l, rt), B.query(rt + 1, r));
if (B.query(l, rt) >= big) ans += calc(l, rt);
if (B.query(rt + 1, r) >= big) ans += calc(rt + 1, r);
return ans;
}
void miku() {
int t, x, y;
cin >> n;
FOR(i, 0, n) cin >> a[i];
smg.build(0, 0, n);
B.init(n);
FOR(i, 0, n) B.modify(i, a[i]);
FOR(i, 0, n) debug(i, B.query(i, i + 1));
cin >> q;
FOR(i, 0, q) {
cin >> t >> x >> y;
if (t == 1) {
x--;
B.modify(x, y - a[x]);
a[x] = y;
smg.modify(0, 0, n, x);
} else {
cout << calc(--x, y) << '\n';
}
}
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
Compilation message
fish2.cpp: In function 'long long int calc(long long int, long long int)':
fish2.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
fish2.cpp:75:5: note: in expansion of macro 'debug'
75 | debug(l, r, rt, B.query(l, rt), B.query(rt + 1, r));
| ^~~~~
fish2.cpp: In function 'void miku()':
fish2.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
fish2.cpp:88:18: note: in expansion of macro 'debug'
88 | FOR(i, 0, n) debug(i, B.query(i, i + 1));
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2516 KB |
Output is correct |
5 |
Correct |
2 ms |
2508 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
5 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
6 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
10 ms |
8028 KB |
Output is correct |
3 |
Correct |
8 ms |
7872 KB |
Output is correct |
4 |
Correct |
10 ms |
8024 KB |
Output is correct |
5 |
Correct |
7 ms |
7772 KB |
Output is correct |
6 |
Correct |
21 ms |
8276 KB |
Output is correct |
7 |
Correct |
7 ms |
7772 KB |
Output is correct |
8 |
Correct |
22 ms |
8160 KB |
Output is correct |
9 |
Correct |
7 ms |
7772 KB |
Output is correct |
10 |
Correct |
11 ms |
8088 KB |
Output is correct |
11 |
Correct |
8 ms |
7772 KB |
Output is correct |
12 |
Correct |
7 ms |
7772 KB |
Output is correct |
13 |
Correct |
7 ms |
7772 KB |
Output is correct |
14 |
Correct |
15 ms |
8540 KB |
Output is correct |
15 |
Correct |
15 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2516 KB |
Output is correct |
5 |
Correct |
2 ms |
2508 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
5 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
6 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
10 ms |
8028 KB |
Output is correct |
23 |
Correct |
8 ms |
7872 KB |
Output is correct |
24 |
Correct |
10 ms |
8024 KB |
Output is correct |
25 |
Correct |
7 ms |
7772 KB |
Output is correct |
26 |
Correct |
21 ms |
8276 KB |
Output is correct |
27 |
Correct |
7 ms |
7772 KB |
Output is correct |
28 |
Correct |
22 ms |
8160 KB |
Output is correct |
29 |
Correct |
7 ms |
7772 KB |
Output is correct |
30 |
Correct |
11 ms |
8088 KB |
Output is correct |
31 |
Correct |
8 ms |
7772 KB |
Output is correct |
32 |
Correct |
7 ms |
7772 KB |
Output is correct |
33 |
Correct |
7 ms |
7772 KB |
Output is correct |
34 |
Correct |
15 ms |
8540 KB |
Output is correct |
35 |
Correct |
15 ms |
8540 KB |
Output is correct |
36 |
Correct |
152 ms |
8284 KB |
Output is correct |
37 |
Correct |
78 ms |
7896 KB |
Output is correct |
38 |
Correct |
50 ms |
7772 KB |
Output is correct |
39 |
Correct |
75 ms |
8284 KB |
Output is correct |
40 |
Correct |
52 ms |
7768 KB |
Output is correct |
41 |
Correct |
2265 ms |
8784 KB |
Output is correct |
42 |
Correct |
2877 ms |
8536 KB |
Output is correct |
43 |
Correct |
14 ms |
7772 KB |
Output is correct |
44 |
Correct |
13 ms |
7772 KB |
Output is correct |
45 |
Correct |
212 ms |
8176 KB |
Output is correct |
46 |
Correct |
337 ms |
8392 KB |
Output is correct |
47 |
Correct |
26 ms |
7772 KB |
Output is correct |
48 |
Correct |
11 ms |
7872 KB |
Output is correct |
49 |
Correct |
42 ms |
7848 KB |
Output is correct |
50 |
Correct |
1056 ms |
8688 KB |
Output is correct |
51 |
Correct |
3878 ms |
8708 KB |
Output is correct |
52 |
Execution timed out |
4035 ms |
8696 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
10 ms |
8028 KB |
Output is correct |
3 |
Correct |
8 ms |
7872 KB |
Output is correct |
4 |
Correct |
10 ms |
8024 KB |
Output is correct |
5 |
Correct |
7 ms |
7772 KB |
Output is correct |
6 |
Correct |
21 ms |
8276 KB |
Output is correct |
7 |
Correct |
7 ms |
7772 KB |
Output is correct |
8 |
Correct |
22 ms |
8160 KB |
Output is correct |
9 |
Correct |
7 ms |
7772 KB |
Output is correct |
10 |
Correct |
11 ms |
8088 KB |
Output is correct |
11 |
Correct |
8 ms |
7772 KB |
Output is correct |
12 |
Correct |
7 ms |
7772 KB |
Output is correct |
13 |
Correct |
7 ms |
7772 KB |
Output is correct |
14 |
Correct |
15 ms |
8540 KB |
Output is correct |
15 |
Correct |
15 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
3986 ms |
9460 KB |
Output is correct |
18 |
Execution timed out |
4051 ms |
9308 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
10 ms |
8028 KB |
Output is correct |
3 |
Correct |
8 ms |
7872 KB |
Output is correct |
4 |
Correct |
10 ms |
8024 KB |
Output is correct |
5 |
Correct |
7 ms |
7772 KB |
Output is correct |
6 |
Correct |
21 ms |
8276 KB |
Output is correct |
7 |
Correct |
7 ms |
7772 KB |
Output is correct |
8 |
Correct |
22 ms |
8160 KB |
Output is correct |
9 |
Correct |
7 ms |
7772 KB |
Output is correct |
10 |
Correct |
11 ms |
8088 KB |
Output is correct |
11 |
Correct |
8 ms |
7772 KB |
Output is correct |
12 |
Correct |
7 ms |
7772 KB |
Output is correct |
13 |
Correct |
7 ms |
7772 KB |
Output is correct |
14 |
Correct |
15 ms |
8540 KB |
Output is correct |
15 |
Correct |
15 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Execution timed out |
4045 ms |
8196 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2516 KB |
Output is correct |
5 |
Correct |
2 ms |
2508 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
5 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
6 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
10 ms |
8028 KB |
Output is correct |
23 |
Correct |
8 ms |
7872 KB |
Output is correct |
24 |
Correct |
10 ms |
8024 KB |
Output is correct |
25 |
Correct |
7 ms |
7772 KB |
Output is correct |
26 |
Correct |
21 ms |
8276 KB |
Output is correct |
27 |
Correct |
7 ms |
7772 KB |
Output is correct |
28 |
Correct |
22 ms |
8160 KB |
Output is correct |
29 |
Correct |
7 ms |
7772 KB |
Output is correct |
30 |
Correct |
11 ms |
8088 KB |
Output is correct |
31 |
Correct |
8 ms |
7772 KB |
Output is correct |
32 |
Correct |
7 ms |
7772 KB |
Output is correct |
33 |
Correct |
7 ms |
7772 KB |
Output is correct |
34 |
Correct |
15 ms |
8540 KB |
Output is correct |
35 |
Correct |
15 ms |
8540 KB |
Output is correct |
36 |
Correct |
152 ms |
8284 KB |
Output is correct |
37 |
Correct |
78 ms |
7896 KB |
Output is correct |
38 |
Correct |
50 ms |
7772 KB |
Output is correct |
39 |
Correct |
75 ms |
8284 KB |
Output is correct |
40 |
Correct |
52 ms |
7768 KB |
Output is correct |
41 |
Correct |
2265 ms |
8784 KB |
Output is correct |
42 |
Correct |
2877 ms |
8536 KB |
Output is correct |
43 |
Correct |
14 ms |
7772 KB |
Output is correct |
44 |
Correct |
13 ms |
7772 KB |
Output is correct |
45 |
Correct |
212 ms |
8176 KB |
Output is correct |
46 |
Correct |
337 ms |
8392 KB |
Output is correct |
47 |
Correct |
26 ms |
7772 KB |
Output is correct |
48 |
Correct |
11 ms |
7872 KB |
Output is correct |
49 |
Correct |
42 ms |
7848 KB |
Output is correct |
50 |
Correct |
1056 ms |
8688 KB |
Output is correct |
51 |
Correct |
3878 ms |
8708 KB |
Output is correct |
52 |
Execution timed out |
4035 ms |
8696 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |