// 花啊啊啊啊啊啊啊啊啊啊啊啊
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "no-stack-protector")
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 1e5 + 7;
const ll oo = 1e18;
ll a[N];
int n;
namespace cover {
int t[N * 4];
char tag[N * 4];
int sum(int v, int len) {
return tag[v] ? len : t[v];
}
void _add(int l, int r, int x, int v = 1, int tl = 1, int tr = n + 1) {
if(l <= tl && tr <= r) {
tag[v] += x;
return;
}
int tm = (tl + tr) / 2;
if(l < tm) _add(l, r, x, v * 2, tl, tm);
if(r > tm) _add(l, r, x, v * 2 + 1, tm, tr);
t[v] = sum(v * 2, tm - tl) + sum(v * 2 + 1, tr - tm);
}
void add(int l, int r, int x) {
if(l == 1 && r == n + 1) return;
_add(l, r, x);
}
int qry(int l, int r, int v = 1, int tl = 1, int tr = n + 1) {
if(l <= tl && tr <= r)
return sum(v, tr - tl);
int tm = (tl + tr) / 2, res = 0;
if(l < tm) res += qry(l, r, v * 2, tl, tm);
if(r > tm) res += qry(l, r, v * 2 + 1, tm, tr);
return res;
}
}
namespace seg {
struct node {
V<pair<int, ll>> bad_pref, bad_suff;
V<pi> bad_seg;
ll sum;
} t[N * 4];
void pull(int v, int posl = INF, int posr = 0) {
t[v].bad_pref = t[v * 2].bad_pref;
t[v].bad_suff = t[v * 2 + 1].bad_suff;
for(auto[pos, sum]:t[v * 2 + 1].bad_pref) if(sum + t[v * 2].sum < a[pos + 1])
t[v].bad_pref.EB(pos, sum + t[v * 2].sum);
for(auto[pos, sum]:t[v * 2].bad_suff) if(sum + t[v * 2 + 1].sum < a[pos - 1])
t[v].bad_suff.EB(pos, sum + t[v * 2 + 1].sum);
int szi = SZ(t[v * 2].bad_suff);
int szj = SZ(t[v * 2 + 1].bad_pref);
int i = 0, j = 0;
while(i < szi && t[v * 2].bad_suff[i].F > posl)
i++;
while(j < szj && t[v * 2 + 1].bad_pref[j].F < posr)
j++;
while(i < szi && j < szj) {
auto& he = t[v * 2].bad_suff[i], be = t[v * 2 + 1].bad_pref[j];
if(he.S + be.S < min(a[he.F - 1], a[be.F + 1])) {
t[v].bad_seg.EB(he.F, be.F);
cover::add(he.F, be.F + 1, 1);
}
if(a[he.F - 1] < a[be.F + 1])
i++;
else
j++;
}
t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}
void build(int v = 1, int tl = 1, int tr = n + 1) {
if(tr - tl == 1) {
t[v].sum = a[tl];
if(a[tl] < a[tl + 1])
t[v].bad_pref.EB(tl, a[tl]);
if(a[tl] < a[tl - 1])
t[v].bad_suff.EB(tl, a[tl]);
if(a[tl] < a[tl + 1] && a[tl] < a[tl - 1]) {
t[v].bad_seg.EB(tl, tl);
cover::add(tl, tl + 1, 1);
}
} else {
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm, tr);
pull(v);
}
}
void upd(int pos, int v = 1, int tl = 1, int tr = n + 1) {
V<pi> tt;
for(auto[l, r]:t[v].bad_seg) {
if(r < pos - 1 || l > pos + 1) {
tt.EB(l, r);
continue;
}
cover::add(l, r + 1, -1);
}
t[v].bad_seg = tt, t[v].bad_pref.clear(), t[v].bad_suff.clear();
if(tr - tl == 1) {
t[v].sum = a[tl];
if(a[tl] < a[tl + 1])
t[v].bad_pref.EB(tl, a[tl]);
if(a[tl] < a[tl - 1])
t[v].bad_suff.EB(tl, a[tl]);
if(a[tl] < a[tl + 1] && a[tl] < a[tl - 1]) {
t[v].bad_seg.EB(tl, tl);
cover::add(tl, tl + 1, 1);
}
} else {
int tm = (tl + tr) / 2;
if(pos - 1 < tm)
upd(pos, v * 2, tl, tm);
if(pos + 1 >= tm)
upd(pos, v * 2 + 1, tm, tr);
pull(v, pos + 1, pos - 1);
}
}
}
void upd(int pos, ll val) {
a[pos] = val;
seg::upd(pos);
}
signed main()
{
IO_OP;
cin >> n;
a[0] = a[n + 1] = oo;
for(int i = 1; i <= n; i++)
cin >> a[i];
seg::build();
int q;
cin >> q;
while(q--) {
int op;
cin >> op;
if(op == 1) {
int x, y;
cin >> x >> y;
upd(x, y);
} else {
int l, r;
cin >> l >> r;
ll tl = a[l - 1], tr = a[r + 1];
if(l - 1 >= 1) upd(l - 1, 1e15);
if(r + 1 <= n) upd(r + 1, 1e15);
if(l != 1 || r != n)
cover::add(l, r + 1, -1);
cout << r - l + 1 - cover::qry(l, r + 1) << '\n';
if(l != 1 || r != n)
cover::add(l, r + 1, 1);
if(l - 1 >= 1) upd(l - 1, tl);
if(r + 1 <= n) upd(r + 1, tr);
}
}
}
Compilation message
fish2.cpp: In function 'void seg::pull(int, int, int)':
fish2.cpp:66:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | for(auto[pos, sum]:t[v * 2 + 1].bad_pref) if(sum + t[v * 2].sum < a[pos + 1])
| ^
fish2.cpp:68:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
68 | for(auto[pos, sum]:t[v * 2].bad_suff) if(sum + t[v * 2 + 1].sum < a[pos - 1])
| ^
fish2.cpp: In function 'void seg::upd(int, int, int, int)':
fish2.cpp:111:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
111 | for(auto[l, r]:t[v].bad_seg) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
31532 KB |
Output is correct |
2 |
Correct |
23 ms |
31576 KB |
Output is correct |
3 |
Correct |
19 ms |
31640 KB |
Output is correct |
4 |
Correct |
19 ms |
31588 KB |
Output is correct |
5 |
Correct |
23 ms |
31728 KB |
Output is correct |
6 |
Correct |
27 ms |
31676 KB |
Output is correct |
7 |
Correct |
27 ms |
31704 KB |
Output is correct |
8 |
Correct |
27 ms |
31768 KB |
Output is correct |
9 |
Correct |
26 ms |
31756 KB |
Output is correct |
10 |
Correct |
24 ms |
31652 KB |
Output is correct |
11 |
Correct |
20 ms |
31716 KB |
Output is correct |
12 |
Correct |
19 ms |
31696 KB |
Output is correct |
13 |
Correct |
23 ms |
31752 KB |
Output is correct |
14 |
Correct |
18 ms |
31700 KB |
Output is correct |
15 |
Correct |
25 ms |
31700 KB |
Output is correct |
16 |
Correct |
24 ms |
31652 KB |
Output is correct |
17 |
Correct |
24 ms |
31700 KB |
Output is correct |
18 |
Correct |
21 ms |
31700 KB |
Output is correct |
19 |
Correct |
19 ms |
31760 KB |
Output is correct |
20 |
Correct |
21 ms |
31712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
31544 KB |
Output is correct |
2 |
Correct |
74 ms |
48076 KB |
Output is correct |
3 |
Correct |
86 ms |
46676 KB |
Output is correct |
4 |
Correct |
77 ms |
47980 KB |
Output is correct |
5 |
Correct |
78 ms |
46768 KB |
Output is correct |
6 |
Correct |
68 ms |
42104 KB |
Output is correct |
7 |
Correct |
66 ms |
40668 KB |
Output is correct |
8 |
Correct |
58 ms |
42336 KB |
Output is correct |
9 |
Correct |
61 ms |
40692 KB |
Output is correct |
10 |
Correct |
69 ms |
47752 KB |
Output is correct |
11 |
Correct |
75 ms |
43832 KB |
Output is correct |
12 |
Correct |
54 ms |
41368 KB |
Output is correct |
13 |
Correct |
51 ms |
41380 KB |
Output is correct |
14 |
Correct |
83 ms |
44380 KB |
Output is correct |
15 |
Correct |
73 ms |
44272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
31532 KB |
Output is correct |
2 |
Correct |
23 ms |
31576 KB |
Output is correct |
3 |
Correct |
19 ms |
31640 KB |
Output is correct |
4 |
Correct |
19 ms |
31588 KB |
Output is correct |
5 |
Correct |
23 ms |
31728 KB |
Output is correct |
6 |
Correct |
27 ms |
31676 KB |
Output is correct |
7 |
Correct |
27 ms |
31704 KB |
Output is correct |
8 |
Correct |
27 ms |
31768 KB |
Output is correct |
9 |
Correct |
26 ms |
31756 KB |
Output is correct |
10 |
Correct |
24 ms |
31652 KB |
Output is correct |
11 |
Correct |
20 ms |
31716 KB |
Output is correct |
12 |
Correct |
19 ms |
31696 KB |
Output is correct |
13 |
Correct |
23 ms |
31752 KB |
Output is correct |
14 |
Correct |
18 ms |
31700 KB |
Output is correct |
15 |
Correct |
25 ms |
31700 KB |
Output is correct |
16 |
Correct |
24 ms |
31652 KB |
Output is correct |
17 |
Correct |
24 ms |
31700 KB |
Output is correct |
18 |
Correct |
21 ms |
31700 KB |
Output is correct |
19 |
Correct |
19 ms |
31760 KB |
Output is correct |
20 |
Correct |
21 ms |
31712 KB |
Output is correct |
21 |
Correct |
19 ms |
31544 KB |
Output is correct |
22 |
Correct |
74 ms |
48076 KB |
Output is correct |
23 |
Correct |
86 ms |
46676 KB |
Output is correct |
24 |
Correct |
77 ms |
47980 KB |
Output is correct |
25 |
Correct |
78 ms |
46768 KB |
Output is correct |
26 |
Correct |
68 ms |
42104 KB |
Output is correct |
27 |
Correct |
66 ms |
40668 KB |
Output is correct |
28 |
Correct |
58 ms |
42336 KB |
Output is correct |
29 |
Correct |
61 ms |
40692 KB |
Output is correct |
30 |
Correct |
69 ms |
47752 KB |
Output is correct |
31 |
Correct |
75 ms |
43832 KB |
Output is correct |
32 |
Correct |
54 ms |
41368 KB |
Output is correct |
33 |
Correct |
51 ms |
41380 KB |
Output is correct |
34 |
Correct |
83 ms |
44380 KB |
Output is correct |
35 |
Correct |
73 ms |
44272 KB |
Output is correct |
36 |
Correct |
114 ms |
48908 KB |
Output is correct |
37 |
Correct |
133 ms |
47164 KB |
Output is correct |
38 |
Correct |
125 ms |
46844 KB |
Output is correct |
39 |
Correct |
115 ms |
48744 KB |
Output is correct |
40 |
Correct |
113 ms |
46860 KB |
Output is correct |
41 |
Correct |
73 ms |
42836 KB |
Output is correct |
42 |
Correct |
71 ms |
42928 KB |
Output is correct |
43 |
Correct |
107 ms |
41324 KB |
Output is correct |
44 |
Correct |
77 ms |
41228 KB |
Output is correct |
45 |
Correct |
114 ms |
48360 KB |
Output is correct |
46 |
Correct |
99 ms |
48492 KB |
Output is correct |
47 |
Correct |
113 ms |
42820 KB |
Output is correct |
48 |
Correct |
62 ms |
41624 KB |
Output is correct |
49 |
Correct |
79 ms |
41744 KB |
Output is correct |
50 |
Correct |
81 ms |
44764 KB |
Output is correct |
51 |
Correct |
100 ms |
44564 KB |
Output is correct |
52 |
Correct |
102 ms |
44768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
31544 KB |
Output is correct |
2 |
Correct |
74 ms |
48076 KB |
Output is correct |
3 |
Correct |
86 ms |
46676 KB |
Output is correct |
4 |
Correct |
77 ms |
47980 KB |
Output is correct |
5 |
Correct |
78 ms |
46768 KB |
Output is correct |
6 |
Correct |
68 ms |
42104 KB |
Output is correct |
7 |
Correct |
66 ms |
40668 KB |
Output is correct |
8 |
Correct |
58 ms |
42336 KB |
Output is correct |
9 |
Correct |
61 ms |
40692 KB |
Output is correct |
10 |
Correct |
69 ms |
47752 KB |
Output is correct |
11 |
Correct |
75 ms |
43832 KB |
Output is correct |
12 |
Correct |
54 ms |
41368 KB |
Output is correct |
13 |
Correct |
51 ms |
41380 KB |
Output is correct |
14 |
Correct |
83 ms |
44380 KB |
Output is correct |
15 |
Correct |
73 ms |
44272 KB |
Output is correct |
16 |
Correct |
18 ms |
31636 KB |
Output is correct |
17 |
Execution timed out |
4033 ms |
53528 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
31544 KB |
Output is correct |
2 |
Correct |
74 ms |
48076 KB |
Output is correct |
3 |
Correct |
86 ms |
46676 KB |
Output is correct |
4 |
Correct |
77 ms |
47980 KB |
Output is correct |
5 |
Correct |
78 ms |
46768 KB |
Output is correct |
6 |
Correct |
68 ms |
42104 KB |
Output is correct |
7 |
Correct |
66 ms |
40668 KB |
Output is correct |
8 |
Correct |
58 ms |
42336 KB |
Output is correct |
9 |
Correct |
61 ms |
40692 KB |
Output is correct |
10 |
Correct |
69 ms |
47752 KB |
Output is correct |
11 |
Correct |
75 ms |
43832 KB |
Output is correct |
12 |
Correct |
54 ms |
41368 KB |
Output is correct |
13 |
Correct |
51 ms |
41380 KB |
Output is correct |
14 |
Correct |
83 ms |
44380 KB |
Output is correct |
15 |
Correct |
73 ms |
44272 KB |
Output is correct |
16 |
Correct |
18 ms |
31572 KB |
Output is correct |
17 |
Correct |
847 ms |
49832 KB |
Output is correct |
18 |
Correct |
902 ms |
55420 KB |
Output is correct |
19 |
Correct |
682 ms |
47576 KB |
Output is correct |
20 |
Correct |
744 ms |
54220 KB |
Output is correct |
21 |
Correct |
819 ms |
49904 KB |
Output is correct |
22 |
Correct |
848 ms |
55084 KB |
Output is correct |
23 |
Correct |
856 ms |
47616 KB |
Output is correct |
24 |
Correct |
753 ms |
54824 KB |
Output is correct |
25 |
Correct |
926 ms |
47484 KB |
Output is correct |
26 |
Correct |
328 ms |
45964 KB |
Output is correct |
27 |
Correct |
525 ms |
46888 KB |
Output is correct |
28 |
Correct |
485 ms |
48868 KB |
Output is correct |
29 |
Correct |
339 ms |
46260 KB |
Output is correct |
30 |
Correct |
374 ms |
46872 KB |
Output is correct |
31 |
Correct |
567 ms |
49832 KB |
Output is correct |
32 |
Correct |
717 ms |
53468 KB |
Output is correct |
33 |
Correct |
450 ms |
44660 KB |
Output is correct |
34 |
Correct |
628 ms |
55404 KB |
Output is correct |
35 |
Correct |
360 ms |
48300 KB |
Output is correct |
36 |
Correct |
729 ms |
52136 KB |
Output is correct |
37 |
Correct |
485 ms |
47840 KB |
Output is correct |
38 |
Correct |
360 ms |
46284 KB |
Output is correct |
39 |
Correct |
420 ms |
48484 KB |
Output is correct |
40 |
Correct |
228 ms |
46744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
31532 KB |
Output is correct |
2 |
Correct |
23 ms |
31576 KB |
Output is correct |
3 |
Correct |
19 ms |
31640 KB |
Output is correct |
4 |
Correct |
19 ms |
31588 KB |
Output is correct |
5 |
Correct |
23 ms |
31728 KB |
Output is correct |
6 |
Correct |
27 ms |
31676 KB |
Output is correct |
7 |
Correct |
27 ms |
31704 KB |
Output is correct |
8 |
Correct |
27 ms |
31768 KB |
Output is correct |
9 |
Correct |
26 ms |
31756 KB |
Output is correct |
10 |
Correct |
24 ms |
31652 KB |
Output is correct |
11 |
Correct |
20 ms |
31716 KB |
Output is correct |
12 |
Correct |
19 ms |
31696 KB |
Output is correct |
13 |
Correct |
23 ms |
31752 KB |
Output is correct |
14 |
Correct |
18 ms |
31700 KB |
Output is correct |
15 |
Correct |
25 ms |
31700 KB |
Output is correct |
16 |
Correct |
24 ms |
31652 KB |
Output is correct |
17 |
Correct |
24 ms |
31700 KB |
Output is correct |
18 |
Correct |
21 ms |
31700 KB |
Output is correct |
19 |
Correct |
19 ms |
31760 KB |
Output is correct |
20 |
Correct |
21 ms |
31712 KB |
Output is correct |
21 |
Correct |
19 ms |
31544 KB |
Output is correct |
22 |
Correct |
74 ms |
48076 KB |
Output is correct |
23 |
Correct |
86 ms |
46676 KB |
Output is correct |
24 |
Correct |
77 ms |
47980 KB |
Output is correct |
25 |
Correct |
78 ms |
46768 KB |
Output is correct |
26 |
Correct |
68 ms |
42104 KB |
Output is correct |
27 |
Correct |
66 ms |
40668 KB |
Output is correct |
28 |
Correct |
58 ms |
42336 KB |
Output is correct |
29 |
Correct |
61 ms |
40692 KB |
Output is correct |
30 |
Correct |
69 ms |
47752 KB |
Output is correct |
31 |
Correct |
75 ms |
43832 KB |
Output is correct |
32 |
Correct |
54 ms |
41368 KB |
Output is correct |
33 |
Correct |
51 ms |
41380 KB |
Output is correct |
34 |
Correct |
83 ms |
44380 KB |
Output is correct |
35 |
Correct |
73 ms |
44272 KB |
Output is correct |
36 |
Correct |
114 ms |
48908 KB |
Output is correct |
37 |
Correct |
133 ms |
47164 KB |
Output is correct |
38 |
Correct |
125 ms |
46844 KB |
Output is correct |
39 |
Correct |
115 ms |
48744 KB |
Output is correct |
40 |
Correct |
113 ms |
46860 KB |
Output is correct |
41 |
Correct |
73 ms |
42836 KB |
Output is correct |
42 |
Correct |
71 ms |
42928 KB |
Output is correct |
43 |
Correct |
107 ms |
41324 KB |
Output is correct |
44 |
Correct |
77 ms |
41228 KB |
Output is correct |
45 |
Correct |
114 ms |
48360 KB |
Output is correct |
46 |
Correct |
99 ms |
48492 KB |
Output is correct |
47 |
Correct |
113 ms |
42820 KB |
Output is correct |
48 |
Correct |
62 ms |
41624 KB |
Output is correct |
49 |
Correct |
79 ms |
41744 KB |
Output is correct |
50 |
Correct |
81 ms |
44764 KB |
Output is correct |
51 |
Correct |
100 ms |
44564 KB |
Output is correct |
52 |
Correct |
102 ms |
44768 KB |
Output is correct |
53 |
Correct |
18 ms |
31636 KB |
Output is correct |
54 |
Execution timed out |
4033 ms |
53528 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |