Submission #1027703

# Submission time Handle Problem Language Result Execution time Memory
1027703 2024-07-19T09:20:54 Z a_l_i_r_e_z_a LIS (INOI20_lis) C++17
100 / 100
1125 ms 68832 KB
#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC optimize("avx2")

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
// #define int long long
#define S second
#define F first
#define mp make_pair
#define smax(xyxy, yxy) (xyxy) = max((xyxy), (yxy))
#define smin(xyxy, yxy) (xyxy) = min((xyxy), (yxy))
#define all(xyxy) (xyxy).begin(), (xyxy).end()
#define len(xyxy) ((int)(xyxy).size())

const int maxn = 1e6 + 5, maxsq = 2e3 + 5, lg = 20;
const int inf = 1e9 + 7;
int n, ans, p[maxn], x[maxn], fen[maxn];
set<pii> st[maxsq];

void upd(int i, int x){
    for(; i < maxn; i += i & -i) fen[i] += x;
}

int get(int x){
    int cur = 0;
    for(int b = lg - 1; b >= 0; b--){
        if(fen[cur + (1ll << b)] < x){
            cur += (1ll << b);
            x -= fen[cur];
        }
    }
    return cur + 1;
}

void dfs(int x, int y, int l){
    smax(ans, l);
    while(st[l].size()){
        auto it = st[l].lower_bound(mp(y, 0));
        if(it == st[l].end()) break;
        if((*it).S > x){
            pii xx = (*it);
            st[l].erase(it);
            dfs(xx.S, xx.F, l + 1);
        }
        else break;
    }
    st[l].insert(mp(y, x));
}

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    for(int i = 0; i < n; i++) cin >> p[i] >> x[i];
    for(int i = 1; i <= n; i++) upd(i, 1);
    for(int i = n - 1; i >= 0; i--){
        p[i] = get(p[i]);
        upd(p[i], -1);
    }
    st[0].insert(mp(0, 0));
    for(int i = 0; i < n; i++){
        int l = 0, r = maxsq;
        while(r - l > 1){
            int mid = (l + r) / 2;
            auto it = st[mid].lower_bound(mp(p[i], 0));
            if(st[mid].size() && it != st[mid].begin()){
                it--;
                if((*it).S < x[i]){
                    l = mid;
                }
                else r = mid;
            }
            else r = mid;
        }
        l++;
        dfs(x[i], p[i], l);
        cout << ans << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 7 ms 732 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 708 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 4 ms 568 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 7 ms 732 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 708 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 4 ms 568 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
19 Correct 104 ms 13096 KB Output is correct
20 Correct 87 ms 13064 KB Output is correct
21 Correct 178 ms 12372 KB Output is correct
22 Correct 244 ms 12372 KB Output is correct
23 Correct 163 ms 12996 KB Output is correct
24 Correct 161 ms 13092 KB Output is correct
25 Correct 171 ms 13112 KB Output is correct
26 Correct 154 ms 13136 KB Output is correct
27 Correct 159 ms 13140 KB Output is correct
28 Correct 156 ms 13112 KB Output is correct
29 Correct 157 ms 13088 KB Output is correct
30 Correct 192 ms 13140 KB Output is correct
31 Correct 235 ms 13144 KB Output is correct
32 Correct 218 ms 12960 KB Output is correct
33 Correct 222 ms 13140 KB Output is correct
34 Correct 224 ms 13236 KB Output is correct
35 Correct 235 ms 13120 KB Output is correct
36 Correct 236 ms 13176 KB Output is correct
37 Correct 247 ms 13140 KB Output is correct
38 Correct 236 ms 13140 KB Output is correct
39 Correct 267 ms 13100 KB Output is correct
40 Correct 232 ms 13184 KB Output is correct
41 Correct 58 ms 10324 KB Output is correct
42 Correct 16 ms 2396 KB Output is correct
43 Correct 137 ms 9648 KB Output is correct
44 Correct 120 ms 6740 KB Output is correct
45 Correct 12 ms 1628 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 55 ms 5136 KB Output is correct
48 Correct 44 ms 3764 KB Output is correct
49 Correct 8 ms 1372 KB Output is correct
50 Correct 3 ms 604 KB Output is correct
51 Correct 34 ms 3320 KB Output is correct
52 Correct 103 ms 8756 KB Output is correct
53 Correct 86 ms 7252 KB Output is correct
54 Correct 76 ms 6436 KB Output is correct
55 Correct 20 ms 1876 KB Output is correct
56 Correct 86 ms 5332 KB Output is correct
57 Correct 32 ms 2652 KB Output is correct
58 Correct 28 ms 2520 KB Output is correct
59 Correct 7 ms 1116 KB Output is correct
60 Correct 134 ms 7840 KB Output is correct
61 Correct 2 ms 604 KB Output is correct
62 Correct 61 ms 3912 KB Output is correct
63 Correct 27 ms 2348 KB Output is correct
64 Correct 73 ms 5716 KB Output is correct
65 Correct 65 ms 5220 KB Output is correct
66 Correct 18 ms 1900 KB Output is correct
67 Correct 54 ms 4180 KB Output is correct
68 Correct 36 ms 3040 KB Output is correct
69 Correct 69 ms 5124 KB Output is correct
70 Correct 13 ms 1628 KB Output is correct
71 Correct 1057 ms 68692 KB Output is correct
72 Correct 977 ms 68780 KB Output is correct
73 Correct 1125 ms 68804 KB Output is correct
74 Correct 1101 ms 68828 KB Output is correct
75 Correct 1054 ms 68692 KB Output is correct
76 Correct 1098 ms 68832 KB Output is correct