原题链接
Problem Description
The princess of Centauri Prime is the galaxy’s most eligible bachelorette of the year. She has hopeful
grooms lined up in front of the royal palace for a chance to spend 5 minutes to try and impress her.
After 5 minutes, the gentleman is carried out of the royal chambers by the palace guards, and the
princess makes a decision. She rates the lad on his lineage and charm by giving him a score for each of
the two properties. On Centauri Prime, low scores are better than high scores.
Suppose that she observes two gentlemen - A and B. She assigns A the scores LA and CA (for
lineage and charm, respectively). B receives scores LB and CB. Then A is dominated by B if either
• LB < LA and CB ≤ CA, or
• LB ≤ LA and CB < CA.
In other words, if at least one of B’s scores is better than A’s, and the other score is not worse. She
considers a gentleman to be efficient (or Pareto-optimal) if she has not yet met any other gentleman who
dominates him. She maintains a list of efficient grooms and updates it after each 5-minute presentation.
Given the queue of bachelors and the scores assigned to them by the princess, determine the number
of entries in the list of efficient grooms after each performance.
Input
The first line of input gives the number of cases, N (0 < N < 40). N test cases follow.
Each one starts with a line containing n (0 ≤ n ≤ 15000) — the size of the queue. The next n lines
will each contain two scores (integers in the range [0, 109
]). Initially, the list is empty.
Output
For each test case, output one line containing ‘Case #x:’ followed by n lines, line i containing the size
of the list of efficient grooms after the i-th update. Print an empty line between test cases.
Sample Input
4
1
100 200
2
100 200
101 202
2
100 200
200 100
5
11 20
20 10
20 10
100 20
1 1
Sample Output
Case #1:
1
Case #2:
1
1
Case #3:
1
2
Case #4:
1
2
3
3
1
题目大意
题意可以理解为,每次给出一个点的坐标(a,b),如果它不在“死区”(雾),就往坐标平面上放,放上去后,给平面新增一个(x>=a&&y>=b)的“死区”。每次给出坐标后都要求输出平面上点的总数。
解题思路
利用STL中set的插入自动排序特性,维护平面上的点集,通过lower_bound , upper_bound在set中快速定位,每次加入点后,就删除在“死区”中的点。
注意输出的最后一行不要输出多余的回车,否则会PE。。。
AC代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<list>
#include<stack>
#include<set>
#include<map>
#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define pb push_back
#define PI 3.1415927
#define inf 0x3f3f3f3f
#define fi first
#define se second
using namespace std;
struct Point
{
int x,y;
Point(int xx,int yy)
{
x=xx;
y=yy;
}
bool operator <(const Point&pt) const
{
return (x<pt.x||(x==pt.x&&y<pt.y));
}
};
int main(void)
{
int kase,n,px,py;
cin>>kase;
for(int z=1;z<=kase;z++)
{
multiset<Point> gg;
multiset<Point>::iterator it;
scanf("%d",&n);
printf("Case #%d:\n",z);
rep(i,0,n)
{
scanf("%d%d",&px,&py);
Point pt(px,py);
it=gg.lower_bound(pt);
if(it==gg.begin()||(--it)->y>pt.y)
{
gg.insert(pt);
it=gg.upper_bound(pt);
while(it!=gg.end()&&it->y>=pt.y) it=gg.erase(it);
}
printf("%d\n",gg.size());
}
if(z!=kase) printf("\n");
}
return 0;
}