49522023-04-07 19:55:46Valaki2Hadjáratcpp14Time limit exceeded 6/100279ms8676 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 1e5;

int n;
vector<int> v, w;

int dp[1 + maxn];

// segtree
int tree[1 + 4 * maxn];

void update(int i, int vl, int vr, int pos, int val) {
    if(vl == vr) {
        tree[i] = val;
    } else {
        int mid = (vl + vr) / 2;
        if(pos <= mid) {
            update(2 * i, vl, mid, pos, val);
        } else {
            update(2 * i + 1, mid + 1, vr, pos, val);
        }
        if(dp[tree[2 * i]] >= dp[tree[2 * i + 1]]) {
            tree[i] = tree[2 * i];
        } else {
            tree[i] = tree[2 * i + 1];
        }
    }
}

int query(int i, int vl, int vr, int ql, int qr) {
    if(vr < ql || vl > qr) {
        return 0;
    }
    if(vl == ql && vr == qr) {
        return tree[i];
    } else {
        int mid = (vl + vr) / 2;
        int x = query(2 * i, vl, mid, ql, min(qr, mid)), y = query(2 * i + 1, mid + 1, vr, max(ql, mid + 1), qr);
        if(dp[x] > dp[y]) {
            return x;
        } else {
            return y;
        }
    }
}

int from[1 + maxn];

bool strangesrt(int i, int j) {
    return v[i] < v[j];
}

void calc(int vl, int vr) {
    //cout << "here" << " " << vl << " " << vr << endl;
    int mid = (vl + vr) / 2;
    if(vl == vr) {
        if(dp[vl] == 0) {
            dp[vr] = 1;
            from[vl] = from[vr] = 0;
        }
        return;
    }
    calc(vl, mid);
    vector<int> a, b;
    for(int i = vl; i <= mid; i++) {
        a.pb(i);
    }
    for(int i = mid + 1; i <= vr; i++) {
        b.pb(i);
    }
    sort(a.begin(), a.end(), strangesrt);
    sort(b.begin(), b.end(), strangesrt);
    int ptr = 0;
    vector<int> to_remove = a;
    for(int idx : b) {
        while(ptr < a.size() && v[a[ptr]] < v[idx]) {
            update(1, 1, maxn, w[a[ptr]], a[ptr]);
            ptr++;
        }
        int prv = query(1, 1, maxn, 1, w[idx]);
        // to_remuuv :)
        if(dp[idx] < dp[prv] + 1) {
            //cout << idx << " " << prv << "\n";
            dp[idx] = dp[prv] + 1;
            from[idx] = prv;
        }
    }
    for(int idx : to_remove) {
        update(1, 1, maxn, idx, 0);
    }
    calc(mid + 1, vr);
}

void solve() {
    cin >> n;
    v.assign(1 + n, 0ll);
    w.assign(1 + n, 0ll);
    for(int i = 1; i <= n; i++) {
        cin >> v[i] >> w[i];
    }
    auto vcomp = v, wcomp = w;
    vcomp.resize(unique(vcomp.begin(), vcomp.end()) - vcomp.begin());
    wcomp.resize(unique(wcomp.begin(), wcomp.end()) - wcomp.begin());
    for(int i = 1; i <= n; i++) {
        v[i] = (lower_bound(vcomp.begin(), vcomp.end(), v[i]) - vcomp.begin());
        w[i] = (lower_bound(wcomp.begin(), wcomp.end(), w[i]) - wcomp.begin());
    }
    //cout << "here" << endl;
    calc(1, n);
    /*for(int i = 1; i <= n; i++) {
        cout << dp[i] << " ";
    }
    cout << "\n";*/
    int best = 0;
    for(int i = 1; i <= n; i++) {
        if(best == 0 || dp[best] < dp[i]) {
            best = i;
        }
    }
    cout << dp[best] << "\n";
    stack<int> s;
    while(best != 0) {
        s.push(best);
        best = from[best];
    }
    while(!s.empty()) {
        cout << s.top() << " ";
        s.pop();
    }
    cout << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/100
1Accepted0/03ms2152 KiB
2Time limit exceeded0/0263ms6892 KiB
3Accepted4/43ms2552 KiB
4Wrong answer0/43ms2860 KiB
5Partially correct2/43ms2984 KiB
6Wrong answer0/43ms2940 KiB
7Wrong answer0/43ms2936 KiB
8Wrong answer0/43ms3072 KiB
9Wrong answer0/43ms3284 KiB
10Wrong answer0/46ms3544 KiB
11Wrong answer0/421ms3960 KiB
12Wrong answer0/448ms4652 KiB
13Wrong answer0/646ms4612 KiB
14Wrong answer0/697ms5856 KiB
15Wrong answer0/6153ms6676 KiB
16Time limit exceeded0/6259ms8676 KiB
17Time limit exceeded0/6275ms5928 KiB
18Time limit exceeded0/6246ms5992 KiB
19Time limit exceeded0/6268ms6292 KiB
20Time limit exceeded0/6279ms6476 KiB
21Time limit exceeded0/6252ms6328 KiB
22Time limit exceeded0/6261ms6332 KiB