跳到正文

题解

AT_abc354_c 题解

Vitamin_B约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年5月19日
收录
2025年12月12日
更新
2026年11月7日
篇幅
约 2 分钟

版本

  1. v1当前

思路

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

代码

C++
# 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;
}
原文