13542022-05-22 13:44:16Szin AttilaHadjáratcpp14Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base100/100
1Elfogadva0/02ms1852 KiB
2Elfogadva0/043ms7972 KiB
3Elfogadva4/41ms2524 KiB
4Elfogadva4/41ms2528 KiB
5Elfogadva4/41ms2540 KiB
6Elfogadva4/41ms2548 KiB
7Elfogadva4/41ms2548 KiB
8Elfogadva4/41ms2568 KiB
9Elfogadva4/41ms2576 KiB
10Elfogadva4/42ms2628 KiB
11Elfogadva4/44ms2980 KiB
12Elfogadva4/48ms3636 KiB
13Elfogadva6/67ms3736 KiB
14Elfogadva6/617ms5004 KiB
15Elfogadva6/624ms6704 KiB
16Elfogadva6/641ms9400 KiB
17Elfogadva6/654ms11272 KiB
18Elfogadva6/661ms13280 KiB
19Elfogadva6/672ms15428 KiB
20Elfogadva6/693ms18892 KiB
21Elfogadva6/693ms20252 KiB
22Elfogadva6/693ms21580 KiB