题意:
给n个点,一个点(x,y)有优势时满足不存在点(fx,fy)使得fx<x,fy<=y或fx<=x,fy<y;问当前有多少个有优势点;
思路:
学习BST的入门题,代码是白书上的;
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9+10;
const int N=1e5+10;
const int maxn=1e3+20;
const double eps=1e-12; struct PO
{
int x,y;
bool operator< (const PO& rhs) const
{
return x<rhs.x||(x==rhs.x&&y<rhs.y);
}
};
multiset<PO>s;
multiset<PO>::iterator it;
int main()
{
int t,Case=0;
read(t);
while(t--)
{
s.clear();
if(Case)printf("\n");
printf("Case #%d:\n",++Case);
int n,x,y;
read(n);
For(i,1,n)
{
read(x);read(y);
PO temp=(PO){x,y};
it=s.lower_bound(temp);
if(it == s.begin()||(--it)->y > y)
{
s.insert(temp);
it=s.upper_bound(temp);
while(it!=s.end()&&it->y >= y)s.erase(it++);
}
printf("%d\n",s.size());
}
}
return 0;
}