# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
615998 |
2022-07-31T17:40:18 Z |
cheissmart |
Fish 2 (JOI22_fish2) |
C++14 |
|
4000 ms |
60076 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#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 {
pi t[N * 4];
int lz[N * 4];
pi add(pi a, pi b) {
if(a.F != b.F) return min(a, b);
a.S += b.S;
return a;
}
void apply(int v, int x) {
t[v].F += x;
lz[v] += x;
}
void push(int v) {
apply(v * 2, lz[v]);
apply(v * 2 + 1, lz[v]);
lz[v] = 0;
}
void build(int v = 1, int tl = 1, int tr = n + 1) {
if(tr - tl == 1) {
t[v] = {0, 1};
return;
}
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm, tr);
t[v] = add(t[v * 2], t[v * 2 + 1]);
}
void add(int l, int r, int x, int v = 1, int tl = 1, int tr = n + 1) {
if(l <= tl && tr <= r) {
apply(v, x);
return;
}
push(v);
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] = add(t[v * 2], t[v * 2 + 1]);
}
pi qry(int l, int r, int v = 1, int tl = 1, int tr = n + 1) {
if(l <= tl && tr <= r)
return t[v];
push(v);
int tm = (tl + tr) / 2;
pi res = {100, 100};
if(l < tm) res = add(res, qry(l, r, v * 2, tl, tm));
if(r > tm) res = add(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];
V<pi> pull(int v) {
for(auto p:t[v * 2].bad_pref)
t[v].bad_pref.PB(p);
for(auto p:t[v * 2 + 1].bad_suff)
t[v].bad_suff.PB(p);
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);
V<pi> bad_seg;
for(int i = 0, j = 0; i < SZ(t[v * 2].bad_suff) && j < SZ(t[v * 2 + 1].bad_pref); ) {
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]))
bad_seg.EB(he.F, be.F);
if(a[he.F - 1] < a[be.F + 1])
i++;
else
j++;
}
t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
return bad_seg;
}
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);
} else {
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm, tr);
t[v].bad_seg = pull(v);
}
for(auto[l, r]:t[v].bad_seg)
cover::add(l, r + 1, 1);
}
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);
tt = pull(v);
for(auto[l, r]:tt) {
if(r < pos - 1 || l > pos + 1)
continue;
t[v].bad_seg.EB(l, r);
cover::add(l, r + 1, 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];
cover::build();
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);
auto p = cover::qry(l, r + 1);
cout << p.S << '\n';
if(l - 1 >= 1) upd(l - 1, tl);
if(r + 1 <= n) upd(r + 1, tr);
}
}
}
Compilation message
fish2.cpp: In function 'std::vector<std::pair<int, int> > seg::pull(int)':
fish2.cpp:87:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
87 | for(auto[pos, sum]:t[v * 2 + 1].bad_pref) if(sum + t[v * 2].sum < a[pos + 1])
| ^
fish2.cpp:89:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
89 | 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::build(int, int, int)':
fish2.cpp:119:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
119 | for(auto[l, r]:t[v].bad_seg)
| ^
fish2.cpp: In function 'void seg::upd(int, int, int, int)':
fish2.cpp:124:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
124 | for(auto[l, r]:t[v].bad_seg) {
| ^
fish2.cpp:150:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
150 | for(auto[l, r]:tt) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31572 KB |
Output is correct |
2 |
Correct |
15 ms |
31572 KB |
Output is correct |
3 |
Correct |
18 ms |
31572 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
21 ms |
31656 KB |
Output is correct |
6 |
Correct |
31 ms |
31764 KB |
Output is correct |
7 |
Correct |
20 ms |
31700 KB |
Output is correct |
8 |
Correct |
30 ms |
31700 KB |
Output is correct |
9 |
Correct |
31 ms |
31756 KB |
Output is correct |
10 |
Correct |
18 ms |
31732 KB |
Output is correct |
11 |
Correct |
18 ms |
31648 KB |
Output is correct |
12 |
Correct |
18 ms |
31700 KB |
Output is correct |
13 |
Correct |
23 ms |
31716 KB |
Output is correct |
14 |
Correct |
18 ms |
31664 KB |
Output is correct |
15 |
Correct |
25 ms |
31700 KB |
Output is correct |
16 |
Correct |
24 ms |
31700 KB |
Output is correct |
17 |
Correct |
25 ms |
31736 KB |
Output is correct |
18 |
Correct |
28 ms |
31724 KB |
Output is correct |
19 |
Correct |
19 ms |
31756 KB |
Output is correct |
20 |
Correct |
20 ms |
31700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31568 KB |
Output is correct |
2 |
Correct |
103 ms |
50720 KB |
Output is correct |
3 |
Correct |
86 ms |
48972 KB |
Output is correct |
4 |
Correct |
87 ms |
50588 KB |
Output is correct |
5 |
Correct |
83 ms |
49104 KB |
Output is correct |
6 |
Correct |
63 ms |
43968 KB |
Output is correct |
7 |
Correct |
50 ms |
42700 KB |
Output is correct |
8 |
Correct |
62 ms |
43936 KB |
Output is correct |
9 |
Correct |
53 ms |
42700 KB |
Output is correct |
10 |
Correct |
75 ms |
50380 KB |
Output is correct |
11 |
Correct |
65 ms |
46056 KB |
Output is correct |
12 |
Correct |
55 ms |
43416 KB |
Output is correct |
13 |
Correct |
56 ms |
43360 KB |
Output is correct |
14 |
Correct |
69 ms |
46044 KB |
Output is correct |
15 |
Correct |
76 ms |
46008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31572 KB |
Output is correct |
2 |
Correct |
15 ms |
31572 KB |
Output is correct |
3 |
Correct |
18 ms |
31572 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
21 ms |
31656 KB |
Output is correct |
6 |
Correct |
31 ms |
31764 KB |
Output is correct |
7 |
Correct |
20 ms |
31700 KB |
Output is correct |
8 |
Correct |
30 ms |
31700 KB |
Output is correct |
9 |
Correct |
31 ms |
31756 KB |
Output is correct |
10 |
Correct |
18 ms |
31732 KB |
Output is correct |
11 |
Correct |
18 ms |
31648 KB |
Output is correct |
12 |
Correct |
18 ms |
31700 KB |
Output is correct |
13 |
Correct |
23 ms |
31716 KB |
Output is correct |
14 |
Correct |
18 ms |
31664 KB |
Output is correct |
15 |
Correct |
25 ms |
31700 KB |
Output is correct |
16 |
Correct |
24 ms |
31700 KB |
Output is correct |
17 |
Correct |
25 ms |
31736 KB |
Output is correct |
18 |
Correct |
28 ms |
31724 KB |
Output is correct |
19 |
Correct |
19 ms |
31756 KB |
Output is correct |
20 |
Correct |
20 ms |
31700 KB |
Output is correct |
21 |
Correct |
15 ms |
31568 KB |
Output is correct |
22 |
Correct |
103 ms |
50720 KB |
Output is correct |
23 |
Correct |
86 ms |
48972 KB |
Output is correct |
24 |
Correct |
87 ms |
50588 KB |
Output is correct |
25 |
Correct |
83 ms |
49104 KB |
Output is correct |
26 |
Correct |
63 ms |
43968 KB |
Output is correct |
27 |
Correct |
50 ms |
42700 KB |
Output is correct |
28 |
Correct |
62 ms |
43936 KB |
Output is correct |
29 |
Correct |
53 ms |
42700 KB |
Output is correct |
30 |
Correct |
75 ms |
50380 KB |
Output is correct |
31 |
Correct |
65 ms |
46056 KB |
Output is correct |
32 |
Correct |
55 ms |
43416 KB |
Output is correct |
33 |
Correct |
56 ms |
43360 KB |
Output is correct |
34 |
Correct |
69 ms |
46044 KB |
Output is correct |
35 |
Correct |
76 ms |
46008 KB |
Output is correct |
36 |
Correct |
136 ms |
51148 KB |
Output is correct |
37 |
Correct |
156 ms |
49320 KB |
Output is correct |
38 |
Correct |
148 ms |
49172 KB |
Output is correct |
39 |
Correct |
123 ms |
51096 KB |
Output is correct |
40 |
Correct |
157 ms |
49068 KB |
Output is correct |
41 |
Correct |
77 ms |
44488 KB |
Output is correct |
42 |
Correct |
77 ms |
44572 KB |
Output is correct |
43 |
Correct |
83 ms |
43372 KB |
Output is correct |
44 |
Correct |
89 ms |
43308 KB |
Output is correct |
45 |
Correct |
117 ms |
50704 KB |
Output is correct |
46 |
Correct |
111 ms |
50836 KB |
Output is correct |
47 |
Correct |
118 ms |
44936 KB |
Output is correct |
48 |
Correct |
77 ms |
43724 KB |
Output is correct |
49 |
Correct |
98 ms |
43760 KB |
Output is correct |
50 |
Correct |
88 ms |
46404 KB |
Output is correct |
51 |
Correct |
89 ms |
46344 KB |
Output is correct |
52 |
Correct |
89 ms |
46456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31568 KB |
Output is correct |
2 |
Correct |
103 ms |
50720 KB |
Output is correct |
3 |
Correct |
86 ms |
48972 KB |
Output is correct |
4 |
Correct |
87 ms |
50588 KB |
Output is correct |
5 |
Correct |
83 ms |
49104 KB |
Output is correct |
6 |
Correct |
63 ms |
43968 KB |
Output is correct |
7 |
Correct |
50 ms |
42700 KB |
Output is correct |
8 |
Correct |
62 ms |
43936 KB |
Output is correct |
9 |
Correct |
53 ms |
42700 KB |
Output is correct |
10 |
Correct |
75 ms |
50380 KB |
Output is correct |
11 |
Correct |
65 ms |
46056 KB |
Output is correct |
12 |
Correct |
55 ms |
43416 KB |
Output is correct |
13 |
Correct |
56 ms |
43360 KB |
Output is correct |
14 |
Correct |
69 ms |
46044 KB |
Output is correct |
15 |
Correct |
76 ms |
46008 KB |
Output is correct |
16 |
Correct |
15 ms |
31572 KB |
Output is correct |
17 |
Execution timed out |
4065 ms |
54264 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31568 KB |
Output is correct |
2 |
Correct |
103 ms |
50720 KB |
Output is correct |
3 |
Correct |
86 ms |
48972 KB |
Output is correct |
4 |
Correct |
87 ms |
50588 KB |
Output is correct |
5 |
Correct |
83 ms |
49104 KB |
Output is correct |
6 |
Correct |
63 ms |
43968 KB |
Output is correct |
7 |
Correct |
50 ms |
42700 KB |
Output is correct |
8 |
Correct |
62 ms |
43936 KB |
Output is correct |
9 |
Correct |
53 ms |
42700 KB |
Output is correct |
10 |
Correct |
75 ms |
50380 KB |
Output is correct |
11 |
Correct |
65 ms |
46056 KB |
Output is correct |
12 |
Correct |
55 ms |
43416 KB |
Output is correct |
13 |
Correct |
56 ms |
43360 KB |
Output is correct |
14 |
Correct |
69 ms |
46044 KB |
Output is correct |
15 |
Correct |
76 ms |
46008 KB |
Output is correct |
16 |
Correct |
17 ms |
31700 KB |
Output is correct |
17 |
Correct |
1132 ms |
51996 KB |
Output is correct |
18 |
Correct |
928 ms |
56972 KB |
Output is correct |
19 |
Correct |
944 ms |
49492 KB |
Output is correct |
20 |
Correct |
709 ms |
57684 KB |
Output is correct |
21 |
Correct |
1087 ms |
53820 KB |
Output is correct |
22 |
Correct |
885 ms |
58916 KB |
Output is correct |
23 |
Correct |
1105 ms |
50760 KB |
Output is correct |
24 |
Correct |
867 ms |
58580 KB |
Output is correct |
25 |
Correct |
960 ms |
50852 KB |
Output is correct |
26 |
Correct |
313 ms |
49832 KB |
Output is correct |
27 |
Correct |
417 ms |
51184 KB |
Output is correct |
28 |
Correct |
638 ms |
52044 KB |
Output is correct |
29 |
Correct |
362 ms |
50308 KB |
Output is correct |
30 |
Correct |
446 ms |
50912 KB |
Output is correct |
31 |
Correct |
749 ms |
53148 KB |
Output is correct |
32 |
Correct |
856 ms |
56908 KB |
Output is correct |
33 |
Correct |
668 ms |
47912 KB |
Output is correct |
34 |
Correct |
829 ms |
60076 KB |
Output is correct |
35 |
Correct |
494 ms |
52468 KB |
Output is correct |
36 |
Correct |
730 ms |
55372 KB |
Output is correct |
37 |
Correct |
620 ms |
50772 KB |
Output is correct |
38 |
Correct |
443 ms |
49172 KB |
Output is correct |
39 |
Correct |
420 ms |
52168 KB |
Output is correct |
40 |
Correct |
216 ms |
50140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31572 KB |
Output is correct |
2 |
Correct |
15 ms |
31572 KB |
Output is correct |
3 |
Correct |
18 ms |
31572 KB |
Output is correct |
4 |
Correct |
16 ms |
31572 KB |
Output is correct |
5 |
Correct |
21 ms |
31656 KB |
Output is correct |
6 |
Correct |
31 ms |
31764 KB |
Output is correct |
7 |
Correct |
20 ms |
31700 KB |
Output is correct |
8 |
Correct |
30 ms |
31700 KB |
Output is correct |
9 |
Correct |
31 ms |
31756 KB |
Output is correct |
10 |
Correct |
18 ms |
31732 KB |
Output is correct |
11 |
Correct |
18 ms |
31648 KB |
Output is correct |
12 |
Correct |
18 ms |
31700 KB |
Output is correct |
13 |
Correct |
23 ms |
31716 KB |
Output is correct |
14 |
Correct |
18 ms |
31664 KB |
Output is correct |
15 |
Correct |
25 ms |
31700 KB |
Output is correct |
16 |
Correct |
24 ms |
31700 KB |
Output is correct |
17 |
Correct |
25 ms |
31736 KB |
Output is correct |
18 |
Correct |
28 ms |
31724 KB |
Output is correct |
19 |
Correct |
19 ms |
31756 KB |
Output is correct |
20 |
Correct |
20 ms |
31700 KB |
Output is correct |
21 |
Correct |
15 ms |
31568 KB |
Output is correct |
22 |
Correct |
103 ms |
50720 KB |
Output is correct |
23 |
Correct |
86 ms |
48972 KB |
Output is correct |
24 |
Correct |
87 ms |
50588 KB |
Output is correct |
25 |
Correct |
83 ms |
49104 KB |
Output is correct |
26 |
Correct |
63 ms |
43968 KB |
Output is correct |
27 |
Correct |
50 ms |
42700 KB |
Output is correct |
28 |
Correct |
62 ms |
43936 KB |
Output is correct |
29 |
Correct |
53 ms |
42700 KB |
Output is correct |
30 |
Correct |
75 ms |
50380 KB |
Output is correct |
31 |
Correct |
65 ms |
46056 KB |
Output is correct |
32 |
Correct |
55 ms |
43416 KB |
Output is correct |
33 |
Correct |
56 ms |
43360 KB |
Output is correct |
34 |
Correct |
69 ms |
46044 KB |
Output is correct |
35 |
Correct |
76 ms |
46008 KB |
Output is correct |
36 |
Correct |
136 ms |
51148 KB |
Output is correct |
37 |
Correct |
156 ms |
49320 KB |
Output is correct |
38 |
Correct |
148 ms |
49172 KB |
Output is correct |
39 |
Correct |
123 ms |
51096 KB |
Output is correct |
40 |
Correct |
157 ms |
49068 KB |
Output is correct |
41 |
Correct |
77 ms |
44488 KB |
Output is correct |
42 |
Correct |
77 ms |
44572 KB |
Output is correct |
43 |
Correct |
83 ms |
43372 KB |
Output is correct |
44 |
Correct |
89 ms |
43308 KB |
Output is correct |
45 |
Correct |
117 ms |
50704 KB |
Output is correct |
46 |
Correct |
111 ms |
50836 KB |
Output is correct |
47 |
Correct |
118 ms |
44936 KB |
Output is correct |
48 |
Correct |
77 ms |
43724 KB |
Output is correct |
49 |
Correct |
98 ms |
43760 KB |
Output is correct |
50 |
Correct |
88 ms |
46404 KB |
Output is correct |
51 |
Correct |
89 ms |
46344 KB |
Output is correct |
52 |
Correct |
89 ms |
46456 KB |
Output is correct |
53 |
Correct |
15 ms |
31572 KB |
Output is correct |
54 |
Execution timed out |
4065 ms |
54264 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |