The government decided to build some cities in a newly developping area. Now they had N different locations to select from, while there were M factories in this newly developping area.
The area was blowing northwest wind, so if we choose a location that located on the southeast quadrant of one of the factory (including the boundary), the fog from the factory would pollute the city heavily.Now it's your job to choose all the city locations that will not get pollution by the factories.
Input
The first line of a input block contains the numbers N, M (1 <= N, M <= 200000). Line 2 ~ N + 1 will each contain two integers(x, y) the location of a city. Line N + 2 ~ M + N + 1 will each contains two integers(x, y) the location of a factory. The x and y co-ordinates of the locations will be between -1000000000 and 1000000000, inclusive. There're no more than 10 test cases in the input data.
Output
The first line of your output block should be an integer K represent the number of city locations which the government can choose from. The next K lines should contain the co-ordinates of the cities. The co-ordinates should be sorted in ascending order of x co-ordinates, and in case of tie, ascending order of y co-ordinates.
Sample Input
3 3 0 1 -2 2 1 3 -2 2 2 0 4 4
Sample Output
1 1 3
#include <stdio.h> #include <string> #include <string.h> #include <algorithm> #include <map> using namespace std; struct build { int x,y; }; int cmp(build a,build b) { if(a.x!=b.x) return a.x<b.x; return a.y>b.y;////////////////////// } int cmp2(build a,build b) { if(a.x!=b.x) return a.x<b.x; return a.y<b.y;////////////////////// } int max__(int a,int b) { return a>b?a:b; } build city[200010],fact[200010]; map<int ,int>my; int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) //scanf("%d%d",&n,&m); { my.clear(); for(int i=0;i<n;i++) { scanf("%d%d",&city[i].x,&city[i].y); } for(int i=0;i<m;i++)//gongchang { scanf("%d%d",&fact[i].x,&fact[i].y); } sort(fact,fact+m,cmp); int maxx=fact[0].y; my[fact[0].x]=maxx; for(int i=1;i<m;i++) { if(fact[i].x!=fact[i-1].x) maxx=my[fact[i].x]=max__(fact[i].y,maxx); } int k=0;//cheng for(int i=0;i<n;i++)// keyongcheng { map<int,int>::iterator it=my.upper_bound(city[i].x); if(it==my.begin()) { city[k].x=city[i].x; city[k++].y=city[i].y; continue; } it--; if((it->second)<city[i].y) { city[k].x=city[i].x; city[k++].y=city[i].y; } } printf("%d\n",k); sort(city,city+k,cmp2); for(int i=0;i<k;i++) { printf("%d %d\n",city[i].x,city[i].y); } } return 0; } /* //up zhuyi begin city fact 3 3 0 1 -2 2 1 3 -2 2 2 0 4 4 3 1 1 2 2 2 2 1 1 1 */