# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
783037 |
2023-07-14T14:26:30 Z |
RushB |
LIS (INOI20_lis) |
C++17 |
|
1084 ms |
43152 KB |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using ar = array<int, 2>;
const int INF = 1ll << 30;
const int N = 1e6 + 6;
int n, x[N], p[N], q, ans[N], S[4 * N], delta[4 * N];
ar M[1500], a[N], b[N];
void add(int v, int l, int r, int L, int R, int d) {
if (R <= l || r <= L) return;
if (L <= l && r <= R) {
delta[v] += d, S[v] += d;
return;
}
int m = l + r >> 1;
add(v << 1, l, m, L, R, d), add(v << 1 | 1, m, r, L, R, d);
S[v] = min(S[v << 1], S[v << 1 | 1]) + delta[v];
}
int find(int v, int l, int r) {
if (l + 1 == r) {
S[v] = INF;
if (l + 1 != q) add(1, 0, q, l + 1, q, -1);
return l;
}
int m = l + r >> 1, x;
if (S[v << 1 | 1] <= S[v << 1]) x = find(v << 1 | 1, m, r);
else x = find(v << 1, l, m);
S[v] = min(S[v << 1], S[v << 1 | 1]) + delta[v];
return x;
}
void seq() {
FOR(i, 0, q) add(1, 0, q, i, i + 1, p[i]);
FOR(i, 0, q) {
int t = find(1, 0, q);
a[i][0] = t, a[i][1] = x[t];
}
}
void solve() {
while (true) {
ar lis = {0, INF};
fill(M, M + 1500, lis);
FOR(i, 0, q) {
ar p = *max_element(M, M + a[i][1]);
M[a[i][1]] = max(M[a[i][1]], ar{p[0] + 1, min(p[1], -a[i][0])});
}
lis = *max_element(M, M + 1500);
for (int i = q - 1; i >= -lis[1]; i--) ans[i] = lis[0];
if (!lis[1]) return;
int ptr = 0;
FOR(i, 0, q) if (a[i][0] < -lis[1]) b[ptr++] = a[i];
q = ptr;
copy(b, b + ptr, a);
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> q;
int tq = q;
vector<int> X;
FOR(i, 0, q) {
cin >> p[i] >> x[i];
X.push_back(x[i]);
}
sort(X.begin(), X.end());
X.resize(unique(X.begin(), X.end()) - X.begin());
FOR(i, 0, q)
x[i] = lower_bound(X.begin(), X.end(), x[i]) - X.begin() + 1;
seq(), solve();
FOR(i, 0, tq) cout << ans[i] << '\n';
}
Compilation message
Main.cpp: In function 'void add(int, int, int, int, int, int)':
Main.cpp:16:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
16 | int m = l + r >> 1;
| ~~^~~
Main.cpp: In function 'int find(int, int, int)':
Main.cpp:26:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | int m = l + r >> 1, x;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
472 KB |
Output is correct |
4 |
Correct |
6 ms |
464 KB |
Output is correct |
5 |
Correct |
10 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
6 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
508 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
7 ms |
468 KB |
Output is correct |
14 |
Correct |
8 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
7 ms |
468 KB |
Output is correct |
17 |
Correct |
9 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
472 KB |
Output is correct |
4 |
Correct |
6 ms |
464 KB |
Output is correct |
5 |
Correct |
10 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
6 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
508 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
7 ms |
468 KB |
Output is correct |
14 |
Correct |
8 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
7 ms |
468 KB |
Output is correct |
17 |
Correct |
9 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
728 KB |
Output is correct |
19 |
Correct |
119 ms |
10740 KB |
Output is correct |
20 |
Correct |
114 ms |
9800 KB |
Output is correct |
21 |
Correct |
113 ms |
10668 KB |
Output is correct |
22 |
Correct |
112 ms |
10124 KB |
Output is correct |
23 |
Correct |
137 ms |
10196 KB |
Output is correct |
24 |
Correct |
135 ms |
10116 KB |
Output is correct |
25 |
Correct |
136 ms |
10196 KB |
Output is correct |
26 |
Correct |
151 ms |
10084 KB |
Output is correct |
27 |
Correct |
135 ms |
10188 KB |
Output is correct |
28 |
Correct |
136 ms |
10096 KB |
Output is correct |
29 |
Correct |
139 ms |
10168 KB |
Output is correct |
30 |
Correct |
136 ms |
10192 KB |
Output is correct |
31 |
Correct |
137 ms |
10184 KB |
Output is correct |
32 |
Correct |
137 ms |
10200 KB |
Output is correct |
33 |
Correct |
142 ms |
10244 KB |
Output is correct |
34 |
Correct |
139 ms |
10168 KB |
Output is correct |
35 |
Correct |
139 ms |
10184 KB |
Output is correct |
36 |
Correct |
154 ms |
10184 KB |
Output is correct |
37 |
Correct |
137 ms |
10184 KB |
Output is correct |
38 |
Correct |
135 ms |
10112 KB |
Output is correct |
39 |
Correct |
140 ms |
10184 KB |
Output is correct |
40 |
Correct |
153 ms |
10200 KB |
Output is correct |
41 |
Correct |
162 ms |
10088 KB |
Output is correct |
42 |
Correct |
21 ms |
2084 KB |
Output is correct |
43 |
Correct |
87 ms |
9512 KB |
Output is correct |
44 |
Correct |
74 ms |
6216 KB |
Output is correct |
45 |
Correct |
22 ms |
1408 KB |
Output is correct |
46 |
Correct |
4 ms |
596 KB |
Output is correct |
47 |
Correct |
73 ms |
5296 KB |
Output is correct |
48 |
Correct |
56 ms |
3484 KB |
Output is correct |
49 |
Correct |
15 ms |
1064 KB |
Output is correct |
50 |
Correct |
6 ms |
596 KB |
Output is correct |
51 |
Correct |
50 ms |
3224 KB |
Output is correct |
52 |
Correct |
122 ms |
7260 KB |
Output is correct |
53 |
Correct |
100 ms |
6620 KB |
Output is correct |
54 |
Correct |
85 ms |
6124 KB |
Output is correct |
55 |
Correct |
23 ms |
1872 KB |
Output is correct |
56 |
Correct |
62 ms |
5580 KB |
Output is correct |
57 |
Correct |
27 ms |
2228 KB |
Output is correct |
58 |
Correct |
25 ms |
2092 KB |
Output is correct |
59 |
Correct |
7 ms |
852 KB |
Output is correct |
60 |
Correct |
99 ms |
6844 KB |
Output is correct |
61 |
Correct |
2 ms |
468 KB |
Output is correct |
62 |
Correct |
42 ms |
3660 KB |
Output is correct |
63 |
Correct |
26 ms |
2160 KB |
Output is correct |
64 |
Correct |
68 ms |
5644 KB |
Output is correct |
65 |
Correct |
60 ms |
5180 KB |
Output is correct |
66 |
Correct |
16 ms |
1692 KB |
Output is correct |
67 |
Correct |
47 ms |
3696 KB |
Output is correct |
68 |
Correct |
32 ms |
3104 KB |
Output is correct |
69 |
Correct |
56 ms |
5196 KB |
Output is correct |
70 |
Correct |
15 ms |
1236 KB |
Output is correct |
71 |
Correct |
983 ms |
43088 KB |
Output is correct |
72 |
Correct |
1000 ms |
43136 KB |
Output is correct |
73 |
Correct |
1004 ms |
43040 KB |
Output is correct |
74 |
Correct |
960 ms |
43152 KB |
Output is correct |
75 |
Correct |
983 ms |
43052 KB |
Output is correct |
76 |
Correct |
1084 ms |
43056 KB |
Output is correct |