#include <bits/stdc++.h>
#define int long long
// using ll = long long;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
using pii = pair<int, int>;
vector<int> ll, rr, v, p, ok;
void dfs(int x, int l, int r)
{
ok[x] = 1;
if (ll[x] != -1 && v[x] <= p[x - 1] - p[l - 1])
dfs(ll[x], l, x - 1);
if (rr[x] != -1 && v[x] <= p[r] - p[x])
dfs(rr[x], x + 1, r);
}
void solve()
{
int n;
cin >> n;
v.assign(n + 1, 0);
for (int i = 1; i <= n; ++i)
cin >> v[i];
auto v0 = v;
int n0 = n;
int q;
cin >> q;
while (q--)
{
int t, a, b;
cin >> t >> a >> b;
if (t == 1)
{
v0[a] = b;
continue;
}
v.assign(1, 0);
for (int i = a; i <= b; ++i)
v.emplace_back(v0[i]);
n = sz(v) - 1;
p = v;
for (int i = 1; i <= n; ++i)
p[i] += p[i - 1];
v[0] = INT_MAX, v.emplace_back(INT_MAX);
--v[0];
vector<int> l(n + 2, -1), r(n + 2, -1);
vector<int> stk;
stk.emplace_back(0);
for (int i = 1; i <= n; ++i)
{
while (v[stk.back()] < v[i])
stk.pop_back();
l[i] = stk.back();
stk.emplace_back(i);
}
stk.clear();
stk.emplace_back(n + 1);
for (int i = n; i >= 1; --i)
{
while (v[stk.back()] <= v[i])
stk.pop_back();
r[i] = stk.back();
stk.emplace_back(i);
}
ll.assign(n + 2, -1), rr = ll;
for (int i = 1; i <= n; ++i)
{
if (v[l[i]] < v[r[i]])
{
assert(rr[l[i]] == -1);
rr[l[i]] = i;
}
else
{
assert(ll[r[i]] == -1);
ll[r[i]] = i;
}
}
ok.assign(n + 1, 0);
dfs(rr[0], 1, n);
cout << accumulate(all(ok), 0) << '\n';
}
}
/*
*/
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
Compilation message
fish2.cpp: In function 'void solve()':
fish2.cpp:28:9: warning: unused variable 'n0' [-Wunused-variable]
28 | int n0 = n;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
6616 KB |
Output is correct |
3 |
Correct |
8 ms |
6984 KB |
Output is correct |
4 |
Correct |
9 ms |
6732 KB |
Output is correct |
5 |
Correct |
10 ms |
6676 KB |
Output is correct |
6 |
Correct |
14 ms |
6612 KB |
Output is correct |
7 |
Correct |
9 ms |
6732 KB |
Output is correct |
8 |
Correct |
14 ms |
6616 KB |
Output is correct |
9 |
Correct |
9 ms |
6732 KB |
Output is correct |
10 |
Correct |
10 ms |
6732 KB |
Output is correct |
11 |
Correct |
8 ms |
6732 KB |
Output is correct |
12 |
Correct |
10 ms |
6728 KB |
Output is correct |
13 |
Correct |
12 ms |
6732 KB |
Output is correct |
14 |
Correct |
10 ms |
6732 KB |
Output is correct |
15 |
Correct |
13 ms |
6608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
10 ms |
6616 KB |
Output is correct |
23 |
Correct |
8 ms |
6984 KB |
Output is correct |
24 |
Correct |
9 ms |
6732 KB |
Output is correct |
25 |
Correct |
10 ms |
6676 KB |
Output is correct |
26 |
Correct |
14 ms |
6612 KB |
Output is correct |
27 |
Correct |
9 ms |
6732 KB |
Output is correct |
28 |
Correct |
14 ms |
6616 KB |
Output is correct |
29 |
Correct |
9 ms |
6732 KB |
Output is correct |
30 |
Correct |
10 ms |
6732 KB |
Output is correct |
31 |
Correct |
8 ms |
6732 KB |
Output is correct |
32 |
Correct |
10 ms |
6728 KB |
Output is correct |
33 |
Correct |
12 ms |
6732 KB |
Output is correct |
34 |
Correct |
10 ms |
6732 KB |
Output is correct |
35 |
Correct |
13 ms |
6608 KB |
Output is correct |
36 |
Correct |
209 ms |
8576 KB |
Output is correct |
37 |
Correct |
360 ms |
8592 KB |
Output is correct |
38 |
Correct |
408 ms |
8124 KB |
Output is correct |
39 |
Correct |
93 ms |
8432 KB |
Output is correct |
40 |
Correct |
468 ms |
8292 KB |
Output is correct |
41 |
Correct |
863 ms |
9716 KB |
Output is correct |
42 |
Correct |
1104 ms |
8692 KB |
Output is correct |
43 |
Correct |
664 ms |
8816 KB |
Output is correct |
44 |
Correct |
781 ms |
8580 KB |
Output is correct |
45 |
Correct |
236 ms |
8372 KB |
Output is correct |
46 |
Correct |
368 ms |
8920 KB |
Output is correct |
47 |
Correct |
460 ms |
8924 KB |
Output is correct |
48 |
Correct |
270 ms |
7340 KB |
Output is correct |
49 |
Correct |
879 ms |
8472 KB |
Output is correct |
50 |
Correct |
445 ms |
9272 KB |
Output is correct |
51 |
Correct |
2033 ms |
8708 KB |
Output is correct |
52 |
Correct |
2103 ms |
9220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
6616 KB |
Output is correct |
3 |
Correct |
8 ms |
6984 KB |
Output is correct |
4 |
Correct |
9 ms |
6732 KB |
Output is correct |
5 |
Correct |
10 ms |
6676 KB |
Output is correct |
6 |
Correct |
14 ms |
6612 KB |
Output is correct |
7 |
Correct |
9 ms |
6732 KB |
Output is correct |
8 |
Correct |
14 ms |
6616 KB |
Output is correct |
9 |
Correct |
9 ms |
6732 KB |
Output is correct |
10 |
Correct |
10 ms |
6732 KB |
Output is correct |
11 |
Correct |
8 ms |
6732 KB |
Output is correct |
12 |
Correct |
10 ms |
6728 KB |
Output is correct |
13 |
Correct |
12 ms |
6732 KB |
Output is correct |
14 |
Correct |
10 ms |
6732 KB |
Output is correct |
15 |
Correct |
13 ms |
6608 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4058 ms |
9836 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
6616 KB |
Output is correct |
3 |
Correct |
8 ms |
6984 KB |
Output is correct |
4 |
Correct |
9 ms |
6732 KB |
Output is correct |
5 |
Correct |
10 ms |
6676 KB |
Output is correct |
6 |
Correct |
14 ms |
6612 KB |
Output is correct |
7 |
Correct |
9 ms |
6732 KB |
Output is correct |
8 |
Correct |
14 ms |
6616 KB |
Output is correct |
9 |
Correct |
9 ms |
6732 KB |
Output is correct |
10 |
Correct |
10 ms |
6732 KB |
Output is correct |
11 |
Correct |
8 ms |
6732 KB |
Output is correct |
12 |
Correct |
10 ms |
6728 KB |
Output is correct |
13 |
Correct |
12 ms |
6732 KB |
Output is correct |
14 |
Correct |
10 ms |
6732 KB |
Output is correct |
15 |
Correct |
13 ms |
6608 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
4019 ms |
7488 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
10 ms |
6616 KB |
Output is correct |
23 |
Correct |
8 ms |
6984 KB |
Output is correct |
24 |
Correct |
9 ms |
6732 KB |
Output is correct |
25 |
Correct |
10 ms |
6676 KB |
Output is correct |
26 |
Correct |
14 ms |
6612 KB |
Output is correct |
27 |
Correct |
9 ms |
6732 KB |
Output is correct |
28 |
Correct |
14 ms |
6616 KB |
Output is correct |
29 |
Correct |
9 ms |
6732 KB |
Output is correct |
30 |
Correct |
10 ms |
6732 KB |
Output is correct |
31 |
Correct |
8 ms |
6732 KB |
Output is correct |
32 |
Correct |
10 ms |
6728 KB |
Output is correct |
33 |
Correct |
12 ms |
6732 KB |
Output is correct |
34 |
Correct |
10 ms |
6732 KB |
Output is correct |
35 |
Correct |
13 ms |
6608 KB |
Output is correct |
36 |
Correct |
209 ms |
8576 KB |
Output is correct |
37 |
Correct |
360 ms |
8592 KB |
Output is correct |
38 |
Correct |
408 ms |
8124 KB |
Output is correct |
39 |
Correct |
93 ms |
8432 KB |
Output is correct |
40 |
Correct |
468 ms |
8292 KB |
Output is correct |
41 |
Correct |
863 ms |
9716 KB |
Output is correct |
42 |
Correct |
1104 ms |
8692 KB |
Output is correct |
43 |
Correct |
664 ms |
8816 KB |
Output is correct |
44 |
Correct |
781 ms |
8580 KB |
Output is correct |
45 |
Correct |
236 ms |
8372 KB |
Output is correct |
46 |
Correct |
368 ms |
8920 KB |
Output is correct |
47 |
Correct |
460 ms |
8924 KB |
Output is correct |
48 |
Correct |
270 ms |
7340 KB |
Output is correct |
49 |
Correct |
879 ms |
8472 KB |
Output is correct |
50 |
Correct |
445 ms |
9272 KB |
Output is correct |
51 |
Correct |
2033 ms |
8708 KB |
Output is correct |
52 |
Correct |
2103 ms |
9220 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Execution timed out |
4058 ms |
9836 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |