답안 #783018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
783018 2023-07-14T14:18:04 Z RushB LIS (INOI20_lis) C++17
100 / 100
933 ms 50864 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], delta[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]);
}
void add(int v, int l, int r, int L, int R) {
        if (R <= l || r <= L) return;
        if (L <= l && r <= R) {
                delta[v]--;
                S[v]--;
                return;
        }
        int m = l + r >> 1;
        add(v << 1, l, m, L, R);
        add(v << 1 | 1, m, r, L, R);
        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);
                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() {
        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';
}

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 'void add(int, int, int, int, int)':
Main.cpp:31:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         int m = l + r >> 1;
      |                 ~~^~~
Main.cpp: In function 'int find(int, int, int)':
Main.cpp:42:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |         int m = l + r >> 1, x;
      |                 ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 7 ms 536 KB Output is correct
4 Correct 6 ms 484 KB Output is correct
5 Correct 10 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 5 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 7 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 8 ms 468 KB Output is correct
14 Correct 8 ms 468 KB Output is correct
15 Correct 3 ms 424 KB Output is correct
16 Correct 7 ms 516 KB Output is correct
17 Correct 11 ms 520 KB Output is correct
18 Correct 7 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 7 ms 536 KB Output is correct
4 Correct 6 ms 484 KB Output is correct
5 Correct 10 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 5 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 7 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 8 ms 468 KB Output is correct
14 Correct 8 ms 468 KB Output is correct
15 Correct 3 ms 424 KB Output is correct
16 Correct 7 ms 516 KB Output is correct
17 Correct 11 ms 520 KB Output is correct
18 Correct 7 ms 468 KB Output is correct
19 Correct 87 ms 10480 KB Output is correct
20 Correct 89 ms 9504 KB Output is correct
21 Correct 88 ms 10384 KB Output is correct
22 Correct 87 ms 10124 KB Output is correct
23 Correct 109 ms 10740 KB Output is correct
24 Correct 128 ms 10872 KB Output is correct
25 Correct 109 ms 10852 KB Output is correct
26 Correct 110 ms 10796 KB Output is correct
27 Correct 113 ms 10852 KB Output is correct
28 Correct 114 ms 10864 KB Output is correct
29 Correct 110 ms 10796 KB Output is correct
30 Correct 112 ms 10772 KB Output is correct
31 Correct 115 ms 10752 KB Output is correct
32 Correct 121 ms 10744 KB Output is correct
33 Correct 114 ms 10828 KB Output is correct
34 Correct 121 ms 10832 KB Output is correct
35 Correct 110 ms 10820 KB Output is correct
36 Correct 121 ms 10836 KB Output is correct
37 Correct 116 ms 10816 KB Output is correct
38 Correct 109 ms 10764 KB Output is correct
39 Correct 111 ms 10840 KB Output is correct
40 Correct 113 ms 10876 KB Output is correct
41 Correct 132 ms 10512 KB Output is correct
42 Correct 17 ms 2152 KB Output is correct
43 Correct 68 ms 9512 KB Output is correct
44 Correct 63 ms 6168 KB Output is correct
45 Correct 17 ms 1292 KB Output is correct
46 Correct 3 ms 612 KB Output is correct
47 Correct 62 ms 5276 KB Output is correct
48 Correct 47 ms 3408 KB Output is correct
49 Correct 13 ms 1092 KB Output is correct
50 Correct 6 ms 616 KB Output is correct
51 Correct 41 ms 3280 KB Output is correct
52 Correct 92 ms 7500 KB Output is correct
53 Correct 85 ms 6600 KB Output is correct
54 Correct 80 ms 6284 KB Output is correct
55 Correct 20 ms 1876 KB Output is correct
56 Correct 53 ms 5580 KB Output is correct
57 Correct 23 ms 2272 KB Output is correct
58 Correct 22 ms 2176 KB Output is correct
59 Correct 7 ms 844 KB Output is correct
60 Correct 82 ms 6968 KB Output is correct
61 Correct 2 ms 468 KB Output is correct
62 Correct 36 ms 3588 KB Output is correct
63 Correct 27 ms 2076 KB Output is correct
64 Correct 59 ms 5628 KB Output is correct
65 Correct 52 ms 5216 KB Output is correct
66 Correct 14 ms 1748 KB Output is correct
67 Correct 40 ms 3684 KB Output is correct
68 Correct 32 ms 2932 KB Output is correct
69 Correct 48 ms 5312 KB Output is correct
70 Correct 12 ms 1276 KB Output is correct
71 Correct 814 ms 50864 KB Output is correct
72 Correct 880 ms 50772 KB Output is correct
73 Correct 813 ms 50716 KB Output is correct
74 Correct 898 ms 50788 KB Output is correct
75 Correct 881 ms 50776 KB Output is correct
76 Correct 933 ms 50796 KB Output is correct