13532022-05-22 13:39:57Szin AttilaHadjáratcpp14Wrong answer 79/100116ms21420 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 || (a == temp.a && b < temp.b);
    }
};


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 < cur.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
base79/100
1Accepted0/02ms1820 KiB
2Accepted0/041ms7788 KiB
3Accepted4/41ms2448 KiB
4Accepted4/41ms2448 KiB
5Accepted4/41ms2456 KiB
6Accepted4/41ms2464 KiB
7Accepted4/41ms2464 KiB
8Wrong answer0/42ms2480 KiB
9Partially correct2/41ms2488 KiB
10Accepted4/42ms2548 KiB
11Accepted4/44ms2940 KiB
12Accepted4/48ms3512 KiB
13Accepted6/68ms3624 KiB
14Wrong answer0/614ms4888 KiB
15Accepted6/625ms6252 KiB
16Partially correct3/643ms9328 KiB
17Partially correct3/671ms11204 KiB
18Accepted6/659ms13184 KiB
19Partially correct3/670ms15292 KiB
20Accepted6/690ms18736 KiB
21Accepted6/6116ms20080 KiB
22Accepted6/687ms21420 KiB