题意
有n个人,每个人有两个属性x和y。如果对于一个人P(x,y),不存在另外一个(x’,y’),使得x’<\x,y’<=y,或者x’<=x,y’<\y,我们说P是有优势的。
每次给出一个人的值,要求输出在只考虑当前已知的信息的前提下,多少人是有优势的。
题解
动态维护一个multiset,multiset内存结构体P(x,y),并按照x为第一优先级、y为第二优先级排序。要求multiset内的值都是有优势的,每插入一个P(x,y),我们需要判断是否存在一个在multiset内的值使得P不是优势的。
如果P是优势的,删除掉因为P的插入而丧失优势的值。
AC代码
#include <bits/stdc++.h>
using namespace std;
struct node
{
int x,y;
node(){}
node(int x,int y):x(x),y(y){}
bool operator<(const node &o)const
{
return x<o.x || x==o.x&&y<o.y;
}
};
multiset<node> st;
multiset<node>::iterator ite;
int main()
{
int T,kase=0;
scanf("%d",&T);
while(T--)
{
printf("Case #%d:\n",++kase);
int n;
st.clear();
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
node tmp=node(x,y);
ite=st.lower_bound(tmp);
if(ite==st.begin() || (--ite)->y>y)
{
st.insert(tmp);
ite=st.upper_bound(tmp);
while(ite!=st.end() && ite->y>=y) st.erase(ite++);
}
printf("%d\n",st.size());
}
if(T) putchar(10);
}
return 0;
}