思路:对于两张高度一样的海报 i, j, 即 y[ i ] = y[ j ], 如果对于任意i < k < j 有y[ k ] > y[ i ] && y[ k ] > y[ j ] 那么i 和 j 就能用同一张海报覆盖
那么我们就能用单调栈维护这个过程。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int> >using namespace std;const int N = 3e5 + ;
const int M = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;int n, x[N], y[N], sk[N], head, rear;
int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d%d", &x[i], &y[i]);
} int ans = n; for(int i = ; i <= n; i++) {
while(head < rear && y[i] <= sk[rear - ]) {
if(sk[rear - ] == y[i]) ans--;
rear--;
} sk[rear++] = y[i];
} printf("%d\n", ans);
return ;
}
/*
*/