ABC 354
C. AtCoder Magics
碰到这种有两个变量的,一般是对一个变量排序,然后去判断另一个变量。
将成本值从小到大排序,然后枚举,一旦出现当前的力量值不是最高,那当前这个就会删掉。因为在它之前有成本更低(排序已经决定),力量更高的卡牌。因此只需实时维护一个之前出现过的力量最大值即可。
也可以将逻辑反过来,将力量值从小到大排序,去看后面有没有成本值更低的。这样就需要提前维护一个后缀成本最低值数组。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5, INF = 1e18;struct node
{int id, a, c;bool operator < (const node & other) const{if (a != other.a)return a < other.a;return c < other.c;}
}p[N];int T, n, cnt, ans, maxn, g[N], vis[N];signed main()
{cin >> n;for (int i = 1; i <= n; i ++){cin >> p[i].a >> p[i].c;p[i].id = i;}sort(p + 1, p + n + 1);g[n] = p[n].c;for (int i = n - 1; i >= 1; i --)g[i] = min(g[i + 1], p[i].c);ans = n;for (int i = 1; i <= n; i ++)if (p[i].c > g[i]){vis[p[i].id] = 1;ans --;}cout << ans << '\n';for (int i = 1; i <= n; i ++)if (vis[i] == 0)cout << i << ' ';return 0;
}