13552022-05-22 13:48:23Szin AttilaHadjáratcpp14Elfogadva 100/10097ms21416 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;
stack <int> ki; //NEM VAGYOK ERETNEK

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(cur);
        cur = p[cur];
    }

    while(!ki.empty()) {
        cout << ki.top() << ' ';
        ki.pop();
    }

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base100/100
1Elfogadva0/02ms1772 KiB
2Elfogadva0/041ms7824 KiB
3Elfogadva4/41ms2440 KiB
4Elfogadva4/41ms2448 KiB
5Elfogadva4/41ms2448 KiB
6Elfogadva4/41ms2456 KiB
7Elfogadva4/41ms2460 KiB
8Elfogadva4/42ms2468 KiB
9Elfogadva4/42ms2484 KiB
10Elfogadva4/42ms2540 KiB
11Elfogadva4/44ms2936 KiB
12Elfogadva4/48ms3500 KiB
13Elfogadva6/68ms3620 KiB
14Elfogadva6/616ms4888 KiB
15Elfogadva6/624ms6240 KiB
16Elfogadva6/643ms9320 KiB
17Elfogadva6/656ms11200 KiB
18Elfogadva6/678ms13172 KiB
19Elfogadva6/671ms15288 KiB
20Elfogadva6/693ms18708 KiB
21Elfogadva6/697ms20192 KiB
22Elfogadva6/697ms21416 KiB