13542022-05-22 13:44:16Szin AttilaHadjáratcpp14Accepted 100/10093ms21580 KiB
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;

const int maxN = 2e5 + 5;
const int MOD = 1e9 + 7;

struct city {
    int a,b,ind;


    bool operator<(const city& temp) const {
        return a < temp.a;
    }
};


int n, mo, moind;
vector<set<city>> v;
vector<int> p, ki;

int main() {

#pragma region
#ifndef ONLINE_JUDGE
   freopen("../input.txt", "r", stdin);
   freopen("../output.txt", "w", stdout);
#endif

   InTheNameOfGod;
#pragma endregion
    
    cin >> n;

    v.resize(n+2);
    p.resize(n+2, -1);

    v[0].insert({0, 0, 0});

    for(int i = 1; i <= n; i++) {
        int a,b;
        cin >> a >> b;

        city cur = {a, b, i};

        int l = 0, r = mo, veg = 0, id = -1;
        while(l <= r) {
            int mid = (l + r) / 2, temp = -1;
            
            auto it = v[mid].lower_bound(cur);
            if(it != v[mid].begin() && (--it) -> b < b) temp = it -> ind;
            /*cout << "lower_bound: " << it -> ind << endl;    
            cout << mid << ": " << temp << endl;*/

            if(temp != -1) {
                veg = mid;
                l = mid+1;
                id = temp;
            }
            else {
                r = mid-1;
            }
        }

        //cout << i << ": " << veg << endl;

        p[i] = id;
        veg++;
        if(veg > mo) {
            mo = veg;
            moind = i;
        }
        auto it = v[veg].lower_bound(cur);
        while (it != v[veg].end() && it -> b >= b) {
            it = v[veg].erase(it);
        }
        if(it == v[veg].end() || it->a > a) v[veg].insert(cur);
    }

    cout << mo << "\n";
    int cur = moind;
    while(cur != 0) {
        ki.push_back(cur);
        cur = p[cur];
    }

    reverse(ki.begin(), ki.end());
    for(int i : ki) cout << i << ' ';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/02ms1852 KiB
2Accepted0/043ms7972 KiB
3Accepted4/41ms2524 KiB
4Accepted4/41ms2528 KiB
5Accepted4/41ms2540 KiB
6Accepted4/41ms2548 KiB
7Accepted4/41ms2548 KiB
8Accepted4/41ms2568 KiB
9Accepted4/41ms2576 KiB
10Accepted4/42ms2628 KiB
11Accepted4/44ms2980 KiB
12Accepted4/48ms3636 KiB
13Accepted6/67ms3736 KiB
14Accepted6/617ms5004 KiB
15Accepted6/624ms6704 KiB
16Accepted6/641ms9400 KiB
17Accepted6/654ms11272 KiB
18Accepted6/661ms13280 KiB
19Accepted6/672ms15428 KiB
20Accepted6/693ms18892 KiB
21Accepted6/693ms20252 KiB
22Accepted6/693ms21580 KiB