# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
783009 |
2023-07-14T14:10:29 Z |
RushB |
LIS (INOI20_lis) |
C++17 |
|
1 ms |
340 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;
const int SQ = 3000;
const int SQQ = 2000 + 5;
int n, x[N], p[N], q, ans[N], mx, X[N], tmp[N], S[4 * N];
vector<int> V[N / SQ + 5];
ar M[SQQ], a[N], b[N];
void build(int v, int l, int r) {
if (l + 1 == r) {
S[v] = p[l];
return;
}
int m = l + r >> 1;
build(v << 1, l, m);
build(v << 1 | 1, m, r);
S[v] = min(S[v << 1], S[v << 1 | 1]);
}
int find(int v, int l, int r) {
if (l + 1 == r) {
S[v] = INF;
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]);
return x;
}
void seq() {
build(1, 0, q);
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 + SQQ, lis);
FOR(i, 0, q) {
ar p = *max_element(M, M + a[i][1]);
p[0]++, p[1] = min(p[1], -a[i][0]);
M[a[i][1]] = max(M[a[i][1]], p);
}
lis = *max_element(M, M + SQQ);
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;
}
assert(X.size() <= SQQ);
seq();
solve();
FOR(i, 0, tq) cout << ans[i] << '\n';
}
//12:54:46
Compilation message
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:19:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | int m = l + r >> 1;
| ~~^~~
Main.cpp: In function 'int find(int, int, int)':
Main.cpp:29:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
29 | int m = l + r >> 1, x;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |