98992024-03-17 14:56:29gortomiHadjáratcpp17Time limit exceeded 82/100226ms36768 KiB
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
#define fi first
#define se second
vector<set<pair<int, int> > > dp;
bool can(int ind, int r, int a)
{
    auto it = dp[ind].lower_bound(make_pair(r, 0));
    if(it == dp[ind].begin()) return 0;
    it--;
    return it -> second < a;
}
static inline int getint() {
    int x, y, m = 1;
    while((x = getchar_unlocked()) < '-') {}
    if(x == '-') {
        m = -1;
        x = 0;
    } else {
        x -= '0';
    }
    while((y = getchar_unlocked()) >= '0') { x = x * 10 + y - '0'; }
    return x * m;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    n = getint();
    dp.resize(n + 1);
    dp[0].insert({0, 0});
    const int INF = 1e6 + 1;
    for(int i = 1; i <= n; i++) dp[i].insert({INF, INF});
    int maxi = 0;
    map<pair<int, int>, int> ind;
    vector<int> p(n + 1);
    for(int i = 1; i <= n; i++)
    {
        int r, a;
        r = getint(); a = getint();
        if(!ind.count(make_pair(r, a))) ind[{r, a}] = i;
        int l = 0, ri = i;
        while(l + 1 != ri)
        {
            int m = (l + ri) / 2;
            if(can(m, r, a)) l = m;
            else ri = m;
        }

        auto it2 = dp[l].lower_bound(make_pair(r, 0));
        it2--;//cout << "ok" << endl;
        p[i] = ind[*it2];
        auto pind = dp[l + 1].lower_bound(make_pair(r, 0));
        if(pind != dp[l + 1].end() && pind -> fi == r && pind -> se <= a)
        {
            continue;
        }

        while(1)
        {
            auto it = dp[l + 1].upper_bound(make_pair(r, a));
            if(it != dp[l + 1].end() && it -> second >= a)
            {
                dp[l + 1].erase(it);
            }
            else break;
        }
        dp[l + 1].insert(make_pair(r, a));
        maxi = max(maxi, l + 1);
    }
    cout << maxi << "\n";
    vector<int> ans;
    for(int i = ind[*dp[maxi].begin()]; i != 0; i = p[i]) ans.push_back(i);
    reverse(ans.begin(), ans.end());
    for(auto x : ans) cout << x << " ";
}
SubtaskSumTestVerdictTimeMemory
base82/100
1Accepted0/03ms1832 KiB
2Accepted0/0100ms18160 KiB
3Accepted4/43ms2424 KiB
4Accepted4/43ms2384 KiB
5Accepted4/43ms2596 KiB
6Accepted4/43ms2828 KiB
7Accepted4/43ms3028 KiB
8Accepted4/43ms3120 KiB
9Accepted4/43ms3136 KiB
10Accepted4/44ms3400 KiB
11Accepted4/48ms4788 KiB
12Accepted4/417ms6724 KiB
13Accepted6/617ms6752 KiB
14Accepted6/635ms10128 KiB
15Accepted6/654ms13464 KiB
16Accepted6/6101ms19852 KiB
17Accepted6/6123ms23096 KiB
18Accepted6/6144ms26344 KiB
19Accepted6/6170ms29832 KiB
20Time limit exceeded0/6226ms36440 KiB
21Time limit exceeded0/6221ms36768 KiB
22Time limit exceeded0/6219ms36768 KiB