98962024-03-17 14:45:22gortomiHadjáratcpp17Time limit exceeded 82/100243ms35552 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,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;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    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;
        cin >> r >> a;
        if(!ind.count(make_pair(r, a))) ind[{r, a}] = i;
        int l = 0, ri = n;
        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/03ms1824 KiB
2Accepted0/0112ms18204 KiB
3Accepted4/43ms2260 KiB
4Accepted4/43ms2336 KiB
5Accepted4/43ms2460 KiB
6Accepted4/43ms2536 KiB
7Accepted4/43ms2620 KiB
8Accepted4/43ms2768 KiB
9Accepted4/43ms2664 KiB
10Accepted4/44ms2928 KiB
11Accepted4/49ms4308 KiB
12Accepted4/419ms6120 KiB
13Accepted6/618ms6120 KiB
14Accepted6/641ms9244 KiB
15Accepted6/661ms12488 KiB
16Accepted6/6111ms18984 KiB
17Accepted6/6136ms22108 KiB
18Accepted6/6160ms25356 KiB
19Accepted6/6187ms29044 KiB
20Time limit exceeded0/6243ms35444 KiB
21Time limit exceeded0/6240ms35524 KiB
22Time limit exceeded0/6240ms35552 KiB