답안 #999582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999582 2024-06-15T20:39:44 Z vjudge1 LIS (INOI20_lis) C++17
100 / 100
1543 ms 142164 KB
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"

using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 1e6 + 5;
ll t[N];
set<pair<ll, ll>> v[N];
void upd(ll v)
{
    for (; v < N; v |= (v + 1)) t[v]++;
}
ll sum(ll v)
{
    ll ans = 0;
    for (; v >= 0; v = (v & (v + 1)) - 1) ans += t[v];
    return ans;
}
ll ans = 1;
void f(pair<ll, ll> x, ll lis)
{
    ans = max(ans, lis);
    while (!v[lis].empty() and v[lis].lower_bound(make_pair(x.first, -1)) != v[lis].end() and v[lis].lower_bound(make_pair(x.first, -1))->second > x.second)
        f(*v[lis].lower_bound(make_pair(x.first, -1)), lis + 1), v[lis].erase(*v[lis].lower_bound(make_pair(x.first, -1)));
    v[lis].insert(x);
}
void solve()
{
    ll q;
    cin >> q;
    pair<ll, ll> qs[q];
    for (ll i = 0; i < q; i++)
        cin >> qs[i].first >> qs[i].second;
    for (ll i = q - 1; i >= 0; i--)
    {
        ll l = 1, r = q;
        while (l <= r)
        {
            ll mid = (l + r) >> 1;
            if (mid - sum(mid) >= qs[i].first) 
                r = mid - 1;
            else l = mid + 1;
        }
        qs[i].first = l;
        upd(qs[i].first);
    }
    for (auto [p, x] : qs)
    {
        ll mx = 1;
        for (ll i = x - 1; i >= 1; i--)
            if (!v[i].empty() and v[i].begin()->first < p)
            {
                auto pos = *--v[i].lower_bound(make_pair(p, -1));
                if (pos.second < x)
                {
                    mx = i + 1;
                    break;
                }
            }
        ans = max(ans, mx);
        f(make_pair(p, x), mx);
        cout << ans << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // precomp();
    // cin >> t;
    for (ll cs = 1; cs <= t; cs++)
        solve();
    // cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 51800 KB Output is correct
2 Correct 8 ms 51824 KB Output is correct
3 Correct 10 ms 52060 KB Output is correct
4 Correct 10 ms 51980 KB Output is correct
5 Correct 18 ms 52060 KB Output is correct
6 Correct 16 ms 52100 KB Output is correct
7 Correct 15 ms 52028 KB Output is correct
8 Correct 12 ms 52060 KB Output is correct
9 Correct 11 ms 52056 KB Output is correct
10 Correct 12 ms 52060 KB Output is correct
11 Correct 11 ms 52060 KB Output is correct
12 Correct 14 ms 51884 KB Output is correct
13 Correct 14 ms 52060 KB Output is correct
14 Correct 15 ms 52060 KB Output is correct
15 Correct 14 ms 52092 KB Output is correct
16 Correct 13 ms 52056 KB Output is correct
17 Correct 13 ms 52060 KB Output is correct
18 Correct 14 ms 52044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 51800 KB Output is correct
2 Correct 8 ms 51824 KB Output is correct
3 Correct 10 ms 52060 KB Output is correct
4 Correct 10 ms 51980 KB Output is correct
5 Correct 18 ms 52060 KB Output is correct
6 Correct 16 ms 52100 KB Output is correct
7 Correct 15 ms 52028 KB Output is correct
8 Correct 12 ms 52060 KB Output is correct
9 Correct 11 ms 52056 KB Output is correct
10 Correct 12 ms 52060 KB Output is correct
11 Correct 11 ms 52060 KB Output is correct
12 Correct 14 ms 51884 KB Output is correct
13 Correct 14 ms 52060 KB Output is correct
14 Correct 15 ms 52060 KB Output is correct
15 Correct 14 ms 52092 KB Output is correct
16 Correct 13 ms 52056 KB Output is correct
17 Correct 13 ms 52060 KB Output is correct
18 Correct 14 ms 52044 KB Output is correct
19 Correct 108 ms 66912 KB Output is correct
20 Correct 114 ms 67032 KB Output is correct
21 Correct 289 ms 66128 KB Output is correct
22 Correct 374 ms 66384 KB Output is correct
23 Correct 190 ms 66896 KB Output is correct
24 Correct 206 ms 66912 KB Output is correct
25 Correct 186 ms 67152 KB Output is correct
26 Correct 189 ms 66900 KB Output is correct
27 Correct 186 ms 66896 KB Output is correct
28 Correct 185 ms 66900 KB Output is correct
29 Correct 189 ms 66944 KB Output is correct
30 Correct 188 ms 67204 KB Output is correct
31 Correct 211 ms 66960 KB Output is correct
32 Correct 217 ms 66936 KB Output is correct
33 Correct 226 ms 66896 KB Output is correct
34 Correct 217 ms 66900 KB Output is correct
35 Correct 211 ms 66952 KB Output is correct
36 Correct 218 ms 66908 KB Output is correct
37 Correct 215 ms 66896 KB Output is correct
38 Correct 219 ms 67124 KB Output is correct
39 Correct 214 ms 66900 KB Output is correct
40 Correct 209 ms 66948 KB Output is correct
41 Correct 92 ms 63324 KB Output is correct
42 Correct 23 ms 54364 KB Output is correct
43 Correct 220 ms 62348 KB Output is correct
44 Correct 193 ms 59996 KB Output is correct
45 Correct 21 ms 53084 KB Output is correct
46 Correct 13 ms 52192 KB Output is correct
47 Correct 63 ms 55756 KB Output is correct
48 Correct 50 ms 55888 KB Output is correct
49 Correct 17 ms 52828 KB Output is correct
50 Correct 11 ms 52060 KB Output is correct
51 Correct 54 ms 55684 KB Output is correct
52 Correct 124 ms 60752 KB Output is correct
53 Correct 101 ms 60500 KB Output is correct
54 Correct 88 ms 57836 KB Output is correct
55 Correct 27 ms 53596 KB Output is correct
56 Correct 82 ms 58192 KB Output is correct
57 Correct 38 ms 54612 KB Output is correct
58 Correct 40 ms 54360 KB Output is correct
59 Correct 15 ms 52568 KB Output is correct
60 Correct 122 ms 59692 KB Output is correct
61 Correct 10 ms 52056 KB Output is correct
62 Correct 57 ms 56448 KB Output is correct
63 Correct 34 ms 54364 KB Output is correct
64 Correct 82 ms 56832 KB Output is correct
65 Correct 77 ms 57812 KB Output is correct
66 Correct 26 ms 53596 KB Output is correct
67 Correct 60 ms 56656 KB Output is correct
68 Correct 40 ms 55120 KB Output is correct
69 Correct 71 ms 55892 KB Output is correct
70 Correct 21 ms 53084 KB Output is correct
71 Correct 1543 ms 141992 KB Output is correct
72 Correct 1428 ms 142140 KB Output is correct
73 Correct 1403 ms 142100 KB Output is correct
74 Correct 1381 ms 142056 KB Output is correct
75 Correct 1438 ms 142092 KB Output is correct
76 Correct 1413 ms 142164 KB Output is correct