13492022-05-22 13:29:26Szin AttilaHadjáratcpp14Wrong answer 79/100101ms21516 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/03ms1816 KiB
2Accepted0/046ms7908 KiB
3Accepted4/41ms2440 KiB
4Accepted4/41ms2444 KiB
5Accepted4/41ms2456 KiB
6Accepted4/41ms2456 KiB
7Accepted4/41ms2460 KiB
8Wrong answer0/41ms2472 KiB
9Partially correct2/41ms2472 KiB
10Accepted4/42ms2532 KiB
11Accepted4/44ms2932 KiB
12Accepted4/48ms3500 KiB
13Accepted6/68ms3620 KiB
14Wrong answer0/616ms4884 KiB
15Accepted6/624ms6508 KiB
16Partially correct3/643ms9316 KiB
17Partially correct3/657ms11196 KiB
18Accepted6/661ms13172 KiB
19Partially correct3/689ms15288 KiB
20Accepted6/6100ms18824 KiB
21Accepted6/697ms20184 KiB
22Accepted6/6101ms21516 KiB