114392024-09-24 18:50:11HoraHadjáratcpp14Wrong answer 96/100166ms2432 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <array>

using namespace std;

vector<set<array<int, 3>>> lis;

int query(array<int, 3> q) { //mire helyezheto ra
	int lo = 0, hi = lis.size();
	while (lo + 1 < hi) {
		int mid = (lo + hi) / 2;
		auto it = lis[mid].upper_bound({ q[0], -1, -1 });
		if (it == lis[mid].begin()) hi = mid;
		else {
			it--;
			if ((*it)[1] < q[1])	lo = mid;
			else hi = mid;
		}
	}
	return lo;
}

int ind(array<int, 3> q, int mid) {
	auto it = lis[mid].upper_bound({ q[0], -1, -1 });
	it--;
	return (*it)[2];
}

void add(array<int, 3> q, int x) {
	lis[x].insert(q);
	auto it = lis[x].upper_bound(q);
	while (it != lis[x].end()) {
		if ((*it)[1] >= q[1]) it = lis[x].erase(it);
		else break;
	}
}

int main() {
	int n;
	cin >> n;
	lis = { {{0, 0, 0}} };
	vector<int> p(n + 1); //for backtrack
	p[0] = 0;
	array<int, 3> a;
	for (int i = 1; i <= n; i++) {
		a[2] = i;
		cin >> a[0] >> a[1];
		int x = query(a);
		if (x == lis.size() - 1) {
			lis.push_back({ a });
		}
		else add(a, x + 1);
		p[i] = ind(a, x);
	}
	vector<int> ans;
	int c = (*lis.back().begin())[2];
	while (c != 0) {
		ans.push_back(c);
		c = p[c];
	}
	cout << lis.size() - 1 << "\n";
	reverse(ans.begin(), ans.end());
	for (auto x : ans) cout << x << " ";
}
SubtaskSumTestVerdictTimeMemory
base96/100
1Accepted0/03ms504 KiB
2Accepted0/076ms1376 KiB
3Accepted4/43ms528 KiB
4Accepted4/43ms504 KiB
5Accepted4/43ms420 KiB
6Accepted4/43ms504 KiB
7Accepted4/42ms376 KiB
8Wrong answer0/43ms504 KiB
9Accepted4/43ms376 KiB
10Accepted4/44ms376 KiB
11Accepted4/48ms376 KiB
12Accepted4/416ms748 KiB
13Accepted6/614ms616 KiB
14Accepted6/628ms892 KiB
15Accepted6/645ms952 KiB
16Accepted6/676ms1440 KiB
17Accepted6/697ms1640 KiB
18Accepted6/6114ms1704 KiB
19Accepted6/6130ms1996 KiB
20Accepted6/6166ms2408 KiB
21Accepted6/6166ms2408 KiB
22Accepted6/6165ms2432 KiB