98982024-03-17 14:47:41gortomiHadjáratcpp17Time limit exceeded 82/100246ms36048 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 = 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/03ms1828 KiB
2Accepted0/0112ms18168 KiB
3Accepted4/43ms2236 KiB
4Accepted4/43ms2444 KiB
5Accepted4/43ms2652 KiB
6Accepted4/43ms2740 KiB
7Accepted4/43ms2868 KiB
8Accepted4/43ms2968 KiB
9Accepted4/43ms2980 KiB
10Accepted4/44ms3516 KiB
11Accepted4/49ms4544 KiB
12Accepted4/419ms6460 KiB
13Accepted6/618ms6464 KiB
14Accepted6/641ms9944 KiB
15Accepted6/663ms13204 KiB
16Accepted6/6111ms19540 KiB
17Accepted6/6137ms22660 KiB
18Accepted6/6163ms25908 KiB
19Accepted6/6192ms29440 KiB
20Time limit exceeded0/6246ms35932 KiB
21Time limit exceeded0/6245ms35892 KiB
22Time limit exceeded0/6245ms36048 KiB