bzoj 1113
思路:对于两张高度一样的海报 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 + 10; const int M = 10 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-6; int n, x[N], y[N], sk[N], head, rear; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d%d", &x[i], &y[i]); } int ans = n; for(int i = 1; i <= n; i++) { while(head < rear && y[i] <= sk[rear - 1]) { if(sk[rear - 1] == y[i]) ans--; rear--; } sk[rear++] = y[i]; } printf("%d\n", ans); return 0; } /* */