#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
const int N = 1e5 + 10, INF = 0x3f3f3f3f;
int left_[N], right_[N];
ll pref[N];
pair<int, int> go[N];
int balance[N];
int get(int *a, int n) {
for (int i = 0; i < n; ++i) {
pref[i + 1] = pref[i] + a[i];
}
for (int i = 0; i < n; ++i) {
left_[i] = i - 1;
while (left_[i] >= 0 && pair{a[left_[i]], left_[i]} < pair{a[i], i}) {
left_[i] = left_[left_[i]];
}
}
for (int i = n; i--; ) {
right_[i] = i + 1;
while (right_[i] < n && pair{a[right_[i]], right_[i]} < pair{a[i], i}) {
right_[i] = right_[right_[i]];
}
}
fill(balance, balance + n + 1, 0);
auto ai = [&](int i) {
if (i < 0 || i >= n) {
return +INF;
}
return a[i];
};
for (int i = 0; i < n; ++i) {
int lef = left_[i], rig = right_[i];
if (pref[rig] - pref[lef + 1] < min(ai(lef), ai(rig)) && (lef != -1 || rig != n)) {
++balance[lef + 1];
--balance[rig];
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
balance[i + 1] += balance[i];
if (!balance[i]) {
++ans;
}
}
return ans;
}
int a[N];
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int queries;
cin >> queries;
while (queries--) {
int type, l, r;
cin >> type >> l >> r;
if (type == 1) {
a[l - 1] = r;
} else {
cout << get(a + l - 1, r - l + 1) << "\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
12 ms |
3120 KB |
Output is correct |
3 |
Correct |
10 ms |
2956 KB |
Output is correct |
4 |
Correct |
13 ms |
3196 KB |
Output is correct |
5 |
Correct |
10 ms |
2908 KB |
Output is correct |
6 |
Correct |
15 ms |
3540 KB |
Output is correct |
7 |
Correct |
13 ms |
2792 KB |
Output is correct |
8 |
Correct |
16 ms |
3532 KB |
Output is correct |
9 |
Correct |
10 ms |
2760 KB |
Output is correct |
10 |
Correct |
12 ms |
3156 KB |
Output is correct |
11 |
Correct |
10 ms |
2960 KB |
Output is correct |
12 |
Correct |
13 ms |
2928 KB |
Output is correct |
13 |
Correct |
11 ms |
2904 KB |
Output is correct |
14 |
Correct |
14 ms |
3212 KB |
Output is correct |
15 |
Correct |
13 ms |
3156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
12 ms |
3120 KB |
Output is correct |
23 |
Correct |
10 ms |
2956 KB |
Output is correct |
24 |
Correct |
13 ms |
3196 KB |
Output is correct |
25 |
Correct |
10 ms |
2908 KB |
Output is correct |
26 |
Correct |
15 ms |
3540 KB |
Output is correct |
27 |
Correct |
13 ms |
2792 KB |
Output is correct |
28 |
Correct |
16 ms |
3532 KB |
Output is correct |
29 |
Correct |
10 ms |
2760 KB |
Output is correct |
30 |
Correct |
12 ms |
3156 KB |
Output is correct |
31 |
Correct |
10 ms |
2960 KB |
Output is correct |
32 |
Correct |
13 ms |
2928 KB |
Output is correct |
33 |
Correct |
11 ms |
2904 KB |
Output is correct |
34 |
Correct |
14 ms |
3212 KB |
Output is correct |
35 |
Correct |
13 ms |
3156 KB |
Output is correct |
36 |
Correct |
207 ms |
3200 KB |
Output is correct |
37 |
Correct |
396 ms |
2852 KB |
Output is correct |
38 |
Correct |
430 ms |
2892 KB |
Output is correct |
39 |
Correct |
89 ms |
2916 KB |
Output is correct |
40 |
Correct |
461 ms |
2860 KB |
Output is correct |
41 |
Correct |
654 ms |
3532 KB |
Output is correct |
42 |
Correct |
827 ms |
3624 KB |
Output is correct |
43 |
Correct |
732 ms |
2816 KB |
Output is correct |
44 |
Correct |
866 ms |
2772 KB |
Output is correct |
45 |
Correct |
230 ms |
3208 KB |
Output is correct |
46 |
Correct |
361 ms |
3272 KB |
Output is correct |
47 |
Correct |
485 ms |
2928 KB |
Output is correct |
48 |
Correct |
264 ms |
2804 KB |
Output is correct |
49 |
Correct |
904 ms |
2892 KB |
Output is correct |
50 |
Correct |
370 ms |
3224 KB |
Output is correct |
51 |
Correct |
1867 ms |
3252 KB |
Output is correct |
52 |
Correct |
1850 ms |
3376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
12 ms |
3120 KB |
Output is correct |
3 |
Correct |
10 ms |
2956 KB |
Output is correct |
4 |
Correct |
13 ms |
3196 KB |
Output is correct |
5 |
Correct |
10 ms |
2908 KB |
Output is correct |
6 |
Correct |
15 ms |
3540 KB |
Output is correct |
7 |
Correct |
13 ms |
2792 KB |
Output is correct |
8 |
Correct |
16 ms |
3532 KB |
Output is correct |
9 |
Correct |
10 ms |
2760 KB |
Output is correct |
10 |
Correct |
12 ms |
3156 KB |
Output is correct |
11 |
Correct |
10 ms |
2960 KB |
Output is correct |
12 |
Correct |
13 ms |
2928 KB |
Output is correct |
13 |
Correct |
11 ms |
2904 KB |
Output is correct |
14 |
Correct |
14 ms |
3212 KB |
Output is correct |
15 |
Correct |
13 ms |
3156 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Execution timed out |
4070 ms |
3292 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
12 ms |
3120 KB |
Output is correct |
3 |
Correct |
10 ms |
2956 KB |
Output is correct |
4 |
Correct |
13 ms |
3196 KB |
Output is correct |
5 |
Correct |
10 ms |
2908 KB |
Output is correct |
6 |
Correct |
15 ms |
3540 KB |
Output is correct |
7 |
Correct |
13 ms |
2792 KB |
Output is correct |
8 |
Correct |
16 ms |
3532 KB |
Output is correct |
9 |
Correct |
10 ms |
2760 KB |
Output is correct |
10 |
Correct |
12 ms |
3156 KB |
Output is correct |
11 |
Correct |
10 ms |
2960 KB |
Output is correct |
12 |
Correct |
13 ms |
2928 KB |
Output is correct |
13 |
Correct |
11 ms |
2904 KB |
Output is correct |
14 |
Correct |
14 ms |
3212 KB |
Output is correct |
15 |
Correct |
13 ms |
3156 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Execution timed out |
4058 ms |
3668 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
12 ms |
3120 KB |
Output is correct |
23 |
Correct |
10 ms |
2956 KB |
Output is correct |
24 |
Correct |
13 ms |
3196 KB |
Output is correct |
25 |
Correct |
10 ms |
2908 KB |
Output is correct |
26 |
Correct |
15 ms |
3540 KB |
Output is correct |
27 |
Correct |
13 ms |
2792 KB |
Output is correct |
28 |
Correct |
16 ms |
3532 KB |
Output is correct |
29 |
Correct |
10 ms |
2760 KB |
Output is correct |
30 |
Correct |
12 ms |
3156 KB |
Output is correct |
31 |
Correct |
10 ms |
2960 KB |
Output is correct |
32 |
Correct |
13 ms |
2928 KB |
Output is correct |
33 |
Correct |
11 ms |
2904 KB |
Output is correct |
34 |
Correct |
14 ms |
3212 KB |
Output is correct |
35 |
Correct |
13 ms |
3156 KB |
Output is correct |
36 |
Correct |
207 ms |
3200 KB |
Output is correct |
37 |
Correct |
396 ms |
2852 KB |
Output is correct |
38 |
Correct |
430 ms |
2892 KB |
Output is correct |
39 |
Correct |
89 ms |
2916 KB |
Output is correct |
40 |
Correct |
461 ms |
2860 KB |
Output is correct |
41 |
Correct |
654 ms |
3532 KB |
Output is correct |
42 |
Correct |
827 ms |
3624 KB |
Output is correct |
43 |
Correct |
732 ms |
2816 KB |
Output is correct |
44 |
Correct |
866 ms |
2772 KB |
Output is correct |
45 |
Correct |
230 ms |
3208 KB |
Output is correct |
46 |
Correct |
361 ms |
3272 KB |
Output is correct |
47 |
Correct |
485 ms |
2928 KB |
Output is correct |
48 |
Correct |
264 ms |
2804 KB |
Output is correct |
49 |
Correct |
904 ms |
2892 KB |
Output is correct |
50 |
Correct |
370 ms |
3224 KB |
Output is correct |
51 |
Correct |
1867 ms |
3252 KB |
Output is correct |
52 |
Correct |
1850 ms |
3376 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Execution timed out |
4070 ms |
3292 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |