#include<bits/stdc++.h>
using namespace std;
#define vec vector
#define int long long
const int INF = 1e17;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vec<int> A(N);
set<pair<int, int>> A_s;
for(int i = 0; i<N; i++) {
cin >> A[i];
A_s.insert({-A[i], i});
}
int Q;
cin >> Q;
while(Q--) {
//cerr << "f" << '\n';
int T;
cin >> T;
int X, Y;
cin >> X >> Y;
X--;
if(T==1) {
A_s.erase({-A[X], X});
A[X] = Y;
A_s.insert({-Y, X});
continue;
}
vec<int> l(N, -1);
vec<int> r(N, N);
vec<pair<int, int>> hi{{INF, -1}};
for(int i = X; i<Y; i++) {
while(hi.back().first <= A[i]) {
hi.pop_back();
//cerr << "here1" << '\n';
}
l[i] = hi.back().second;
//cerr << l[i] << ' ';
hi.push_back({A[i], i});
}
//cerr << '\n';
vec<pair<int, int>> hi_r{{INF, N}};
for(int i = Y-1; i>=X; i--) {
while(hi_r.back().first <= A[i]) {
//cerr << "here2" << '\n';
hi_r.pop_back();
}
r[i] = hi_r.back().second;
hi_r.push_back({A[i], i});
}
vec<bool> valid(N);
vec<int> prefixsums(N+2);
for(int i = 1; i<=N; i++) {
prefixsums[i] = prefixsums[i-1] + A[i-1];
}
prefixsums[N+1] = prefixsums[N];
//valid[(*A_s.begin()).second] = true;
int ans = 0;
for(auto [_, i] : A_s) {
if(i>=Y || i<X) continue;
int cl = l[i];
int cr = r[i];
int sum = prefixsums[min(cr, Y)]-prefixsums[max(cl+1, X)];
//cerr << i << ' ' << sum << '\n';
if(cl != -1) {
if(sum >= A[cl]) valid[i] = valid[i] | valid[cl];
}
if(cr != N) {
if(sum >= A[cr]) valid[i] = valid[i] | valid[cr];
}
if(cl == -1 && cr == N) valid[i] = true;
//cerr << i << ": " << valid[i] << '\n';
ans += valid[i];
}
cout << ans << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
4 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
600 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
7 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
42 ms |
10512 KB |
Output is correct |
3 |
Correct |
29 ms |
10068 KB |
Output is correct |
4 |
Correct |
37 ms |
10320 KB |
Output is correct |
5 |
Correct |
27 ms |
10064 KB |
Output is correct |
6 |
Correct |
52 ms |
10644 KB |
Output is correct |
7 |
Correct |
27 ms |
10076 KB |
Output is correct |
8 |
Correct |
42 ms |
10580 KB |
Output is correct |
9 |
Correct |
29 ms |
10040 KB |
Output is correct |
10 |
Correct |
36 ms |
10320 KB |
Output is correct |
11 |
Correct |
25 ms |
10072 KB |
Output is correct |
12 |
Correct |
34 ms |
10076 KB |
Output is correct |
13 |
Correct |
41 ms |
10032 KB |
Output is correct |
14 |
Correct |
41 ms |
10328 KB |
Output is correct |
15 |
Correct |
33 ms |
10368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
4 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
600 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
7 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
42 ms |
10512 KB |
Output is correct |
23 |
Correct |
29 ms |
10068 KB |
Output is correct |
24 |
Correct |
37 ms |
10320 KB |
Output is correct |
25 |
Correct |
27 ms |
10064 KB |
Output is correct |
26 |
Correct |
52 ms |
10644 KB |
Output is correct |
27 |
Correct |
27 ms |
10076 KB |
Output is correct |
28 |
Correct |
42 ms |
10580 KB |
Output is correct |
29 |
Correct |
29 ms |
10040 KB |
Output is correct |
30 |
Correct |
36 ms |
10320 KB |
Output is correct |
31 |
Correct |
25 ms |
10072 KB |
Output is correct |
32 |
Correct |
34 ms |
10076 KB |
Output is correct |
33 |
Correct |
41 ms |
10032 KB |
Output is correct |
34 |
Correct |
41 ms |
10328 KB |
Output is correct |
35 |
Correct |
33 ms |
10368 KB |
Output is correct |
36 |
Correct |
1144 ms |
10456 KB |
Output is correct |
37 |
Correct |
2074 ms |
10112 KB |
Output is correct |
38 |
Correct |
2641 ms |
10064 KB |
Output is correct |
39 |
Correct |
511 ms |
10376 KB |
Output is correct |
40 |
Correct |
2770 ms |
10064 KB |
Output is correct |
41 |
Correct |
3046 ms |
10864 KB |
Output is correct |
42 |
Correct |
3987 ms |
10832 KB |
Output is correct |
43 |
Correct |
2061 ms |
10068 KB |
Output is correct |
44 |
Correct |
2452 ms |
10076 KB |
Output is correct |
45 |
Correct |
1848 ms |
10736 KB |
Output is correct |
46 |
Correct |
2352 ms |
10436 KB |
Output is correct |
47 |
Correct |
2346 ms |
10156 KB |
Output is correct |
48 |
Correct |
982 ms |
10120 KB |
Output is correct |
49 |
Correct |
3007 ms |
10120 KB |
Output is correct |
50 |
Correct |
1655 ms |
10496 KB |
Output is correct |
51 |
Correct |
3985 ms |
10512 KB |
Output is correct |
52 |
Execution timed out |
4065 ms |
10508 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
42 ms |
10512 KB |
Output is correct |
3 |
Correct |
29 ms |
10068 KB |
Output is correct |
4 |
Correct |
37 ms |
10320 KB |
Output is correct |
5 |
Correct |
27 ms |
10064 KB |
Output is correct |
6 |
Correct |
52 ms |
10644 KB |
Output is correct |
7 |
Correct |
27 ms |
10076 KB |
Output is correct |
8 |
Correct |
42 ms |
10580 KB |
Output is correct |
9 |
Correct |
29 ms |
10040 KB |
Output is correct |
10 |
Correct |
36 ms |
10320 KB |
Output is correct |
11 |
Correct |
25 ms |
10072 KB |
Output is correct |
12 |
Correct |
34 ms |
10076 KB |
Output is correct |
13 |
Correct |
41 ms |
10032 KB |
Output is correct |
14 |
Correct |
41 ms |
10328 KB |
Output is correct |
15 |
Correct |
33 ms |
10368 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4090 ms |
10348 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
42 ms |
10512 KB |
Output is correct |
3 |
Correct |
29 ms |
10068 KB |
Output is correct |
4 |
Correct |
37 ms |
10320 KB |
Output is correct |
5 |
Correct |
27 ms |
10064 KB |
Output is correct |
6 |
Correct |
52 ms |
10644 KB |
Output is correct |
7 |
Correct |
27 ms |
10076 KB |
Output is correct |
8 |
Correct |
42 ms |
10580 KB |
Output is correct |
9 |
Correct |
29 ms |
10040 KB |
Output is correct |
10 |
Correct |
36 ms |
10320 KB |
Output is correct |
11 |
Correct |
25 ms |
10072 KB |
Output is correct |
12 |
Correct |
34 ms |
10076 KB |
Output is correct |
13 |
Correct |
41 ms |
10032 KB |
Output is correct |
14 |
Correct |
41 ms |
10328 KB |
Output is correct |
15 |
Correct |
33 ms |
10368 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
4059 ms |
10608 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
4 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
600 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
7 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
42 ms |
10512 KB |
Output is correct |
23 |
Correct |
29 ms |
10068 KB |
Output is correct |
24 |
Correct |
37 ms |
10320 KB |
Output is correct |
25 |
Correct |
27 ms |
10064 KB |
Output is correct |
26 |
Correct |
52 ms |
10644 KB |
Output is correct |
27 |
Correct |
27 ms |
10076 KB |
Output is correct |
28 |
Correct |
42 ms |
10580 KB |
Output is correct |
29 |
Correct |
29 ms |
10040 KB |
Output is correct |
30 |
Correct |
36 ms |
10320 KB |
Output is correct |
31 |
Correct |
25 ms |
10072 KB |
Output is correct |
32 |
Correct |
34 ms |
10076 KB |
Output is correct |
33 |
Correct |
41 ms |
10032 KB |
Output is correct |
34 |
Correct |
41 ms |
10328 KB |
Output is correct |
35 |
Correct |
33 ms |
10368 KB |
Output is correct |
36 |
Correct |
1144 ms |
10456 KB |
Output is correct |
37 |
Correct |
2074 ms |
10112 KB |
Output is correct |
38 |
Correct |
2641 ms |
10064 KB |
Output is correct |
39 |
Correct |
511 ms |
10376 KB |
Output is correct |
40 |
Correct |
2770 ms |
10064 KB |
Output is correct |
41 |
Correct |
3046 ms |
10864 KB |
Output is correct |
42 |
Correct |
3987 ms |
10832 KB |
Output is correct |
43 |
Correct |
2061 ms |
10068 KB |
Output is correct |
44 |
Correct |
2452 ms |
10076 KB |
Output is correct |
45 |
Correct |
1848 ms |
10736 KB |
Output is correct |
46 |
Correct |
2352 ms |
10436 KB |
Output is correct |
47 |
Correct |
2346 ms |
10156 KB |
Output is correct |
48 |
Correct |
982 ms |
10120 KB |
Output is correct |
49 |
Correct |
3007 ms |
10120 KB |
Output is correct |
50 |
Correct |
1655 ms |
10496 KB |
Output is correct |
51 |
Correct |
3985 ms |
10512 KB |
Output is correct |
52 |
Execution timed out |
4065 ms |
10508 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |