AT_abc354_c 题解

思路

我们可以先以 cc 为第一关键字从小到大排序,aa 为第二关键字从小到大排序,此时我们就只要删去 ai<aja_i<a_ji<ji<j 的元素即可,剩下的数下标从小到大排序输出就行。

代码

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
struct node {
	int x, y, id;
	bool operator < (const node& t) const {
		return y != t.y ? y < t.y : x < t.x;
	}
} a[200005];
int n, now;
vector <int> ans;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> n;
	for (int i = 0; i < n; ++ i)
		cin >> a[i].x >> a[i].y, a[i].id = i + 1;
	sort (a, a + n);
	for (int i = 0; i < n; ++ i)
		if (now <= a[i].x)
			ans.emplace_back (a[i].id), now = a[i].x;
	cout << ans.size () << '\n';
	sort (ans.begin (), ans.end ());
	for (int& i : ans)
		cout << i << ' ';
	return 0;
}
posted @ 2024-05-19 16:11  Vitamin_B  阅读(8)  评论(0)    收藏  举报  来源