답안 #1060445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1060445 2024-08-15T14:32:29 Z vjudge1 LIS (INOI20_lis) C++14
100 / 100
1313 ms 152508 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 1e6+7;
ll n, st[mxn<<2], dp[mxn], a[mxn], ans = 0;
vector<pair<ll,ll>> qx;
vector<set<ll>> opt(mxn);
void build(ll id, ll l, ll r)
{
    st[id] = r-l+1;
    if (l == r) {return;}
    ll m = (r+l)>>1;
    build(id<<1,l,m); build(id<<1|1,m+1,r);
}
void upd(ll id, ll l, ll r, ll i)
{
    if (r < i || i < l) return;
    if (l == r) {st[id] = 0; return;}
    ll m = (r+l)>>1;
    upd(id<<1,l,m,i); upd(id<<1|1,m+1,r,i);
    st[id] = st[id<<1]+st[id<<1|1];
}
ll walk(ll id, ll l, ll r, ll x)
{
    if (l == r) return l;
    ll m = (r+l)>>1;
    if (st[id<<1] >= x) return walk(id<<1,l,m,x);
    return walk(id<<1|1,m+1,r,x-st[id<<1]);
}
void lis_update(ll p)
{
    ans = max(ans, dp[p]);
    set<ll>::iterator f = opt[dp[p]].upper_bound(p);
    while (f != opt[dp[p]].end() && a[*f] > a[p])
    {
        ll cpy = *f;
        opt[dp[p]].erase(cpy);
        dp[cpy] = dp[p]+1;
        lis_update(cpy);
        f = opt[dp[p]].upper_bound(p);
    }
    opt[dp[p]].insert(p);
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
    cin >> n; build(1,1,n); qx.emplace_back();
    for (ll i = 1; i <= n; i++) 
    {
        ll p, x; cin >> p >> x;
        qx.pb({p,x});
    }
    for (ll i = n; i >= 1; i--)
    {
        ll pos = walk(1,1,n,qx[i].fi);
        qx[i].fi = pos; a[pos] = qx[i].se;
        upd(1,1,n,pos);
    }
    for (ll i = 1; i <= n; i++)
    {
        dp[qx[i].fi] = 1; // lis up to i-th
        for (ll j = 1; j < qx[i].se; j++) 
        {
            set<ll>::iterator it = opt[j].lower_bound(qx[i].fi);
            if (it == opt[j].begin()) continue;
            --it;
            if (a[*it] < qx[i].se) dp[qx[i].fi] = j+1; 
        }
        lis_update(qx[i].fi);
        cout << ans << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 47196 KB Output is correct
2 Correct 26 ms 47424 KB Output is correct
3 Correct 20 ms 47556 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 26 ms 47452 KB Output is correct
6 Correct 24 ms 47652 KB Output is correct
7 Correct 22 ms 47520 KB Output is correct
8 Correct 22 ms 47704 KB Output is correct
9 Correct 22 ms 47452 KB Output is correct
10 Correct 22 ms 47600 KB Output is correct
11 Correct 22 ms 47604 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 26 ms 47452 KB Output is correct
14 Correct 24 ms 47448 KB Output is correct
15 Correct 23 ms 47528 KB Output is correct
16 Correct 23 ms 47452 KB Output is correct
17 Correct 24 ms 47452 KB Output is correct
18 Correct 24 ms 47452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 47196 KB Output is correct
2 Correct 26 ms 47424 KB Output is correct
3 Correct 20 ms 47556 KB Output is correct
4 Correct 20 ms 47452 KB Output is correct
5 Correct 26 ms 47452 KB Output is correct
6 Correct 24 ms 47652 KB Output is correct
7 Correct 22 ms 47520 KB Output is correct
8 Correct 22 ms 47704 KB Output is correct
9 Correct 22 ms 47452 KB Output is correct
10 Correct 22 ms 47600 KB Output is correct
11 Correct 22 ms 47604 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 26 ms 47452 KB Output is correct
14 Correct 24 ms 47448 KB Output is correct
15 Correct 23 ms 47528 KB Output is correct
16 Correct 23 ms 47452 KB Output is correct
17 Correct 24 ms 47452 KB Output is correct
18 Correct 24 ms 47452 KB Output is correct
19 Correct 169 ms 67520 KB Output is correct
20 Correct 145 ms 67780 KB Output is correct
21 Correct 226 ms 66756 KB Output is correct
22 Correct 301 ms 67028 KB Output is correct
23 Correct 172 ms 67600 KB Output is correct
24 Correct 177 ms 67520 KB Output is correct
25 Correct 172 ms 67780 KB Output is correct
26 Correct 174 ms 67524 KB Output is correct
27 Correct 174 ms 67524 KB Output is correct
28 Correct 183 ms 67620 KB Output is correct
29 Correct 171 ms 67516 KB Output is correct
30 Correct 179 ms 67604 KB Output is correct
31 Correct 303 ms 67600 KB Output is correct
32 Correct 306 ms 67596 KB Output is correct
33 Correct 299 ms 67592 KB Output is correct
34 Correct 311 ms 67780 KB Output is correct
35 Correct 306 ms 67780 KB Output is correct
36 Correct 297 ms 67592 KB Output is correct
37 Correct 312 ms 67528 KB Output is correct
38 Correct 305 ms 67520 KB Output is correct
39 Correct 301 ms 67528 KB Output is correct
40 Correct 304 ms 67664 KB Output is correct
41 Correct 140 ms 64196 KB Output is correct
42 Correct 34 ms 50388 KB Output is correct
43 Correct 170 ms 63428 KB Output is correct
44 Correct 158 ms 59080 KB Output is correct
45 Correct 31 ms 48928 KB Output is correct
46 Correct 21 ms 47708 KB Output is correct
47 Correct 71 ms 55276 KB Output is correct
48 Correct 53 ms 52656 KB Output is correct
49 Correct 25 ms 48608 KB Output is correct
50 Correct 21 ms 47708 KB Output is correct
51 Correct 49 ms 52176 KB Output is correct
52 Correct 110 ms 59852 KB Output is correct
53 Correct 95 ms 58060 KB Output is correct
54 Correct 87 ms 57224 KB Output is correct
55 Correct 33 ms 49620 KB Output is correct
56 Correct 111 ms 55760 KB Output is correct
57 Correct 53 ms 50644 KB Output is correct
58 Correct 51 ms 50388 KB Output is correct
59 Correct 26 ms 48088 KB Output is correct
60 Correct 165 ms 58820 KB Output is correct
61 Correct 20 ms 47452 KB Output is correct
62 Correct 84 ms 52944 KB Output is correct
63 Correct 53 ms 50300 KB Output is correct
64 Correct 120 ms 56012 KB Output is correct
65 Correct 104 ms 55244 KB Output is correct
66 Correct 38 ms 49620 KB Output is correct
67 Correct 84 ms 53184 KB Output is correct
68 Correct 62 ms 51664 KB Output is correct
69 Correct 103 ms 55384 KB Output is correct
70 Correct 33 ms 49088 KB Output is correct
71 Correct 1279 ms 152508 KB Output is correct
72 Correct 1234 ms 152484 KB Output is correct
73 Correct 1313 ms 152472 KB Output is correct
74 Correct 1237 ms 152464 KB Output is correct
75 Correct 1246 ms 152484 KB Output is correct
76 Correct 1244 ms 152484 KB Output is correct