RT,考场上太菜了只会暴力,结果只有20pts……
O(n(logn+m1+m2)) 过不了5000吗……
#include <bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
const int INF = 2147483647;
const int S = 100000+5;
int n,m1,m2,fir,sec,maxx = -1,res;
struct node {int x,y;};
node li[S],wai[S];
struct node2 {int xx,yy;};
node2 px[S],py[S];
bool cmp(const node& a,const node& b) {return a.x==b.x?a.y<b.y:a.x<b.x;}
// O(nlogn+nm)
int main(int argc,char *argv[])
{
//freopen("airport.in","r",stdin);
//freopen("airport.out","w",stdout);
scanf("%d%d%d",&n,&m1,&m2);
for(int i = 1;i <= m1;++i) scanf("%d%d",&li[i].x,&li[i].y);
for(int i = 1;i <= m2;++i) scanf("%d%d",&wai[i].x,&wai[i].y);
sort(li+1,li+m1+1,cmp);
sort(wai+1,wai+m2+1,cmp);
for(int i = 0;i < n+1;++i)
{
//shabi:
for(int wdy = 0;wdy < n+10;++wdy) px[wdy].xx = py[wdy].xx = px[wdy].yy = py[wdy].yy = 0;
fir = i;sec = n-i;res = 0;
//cout<<fir<<" "<<sec<<'\n';
for(int i = 1;i <= m1;++i)
{
for(int j = 1;j <= fir;++j)
{
if(li[i].x > px[j].yy)
{
++res;
px[j].xx = li[i].x;
px[j].yy = li[i].y;
break;
}
} //cout<<res<<'\n';
}
if(res+m2 < maxx) continue;
for(int i = 1;i <= m2;++i)
{
for(int j = 1;j <= sec;++j)
{
if(wai[i].x > py[j].yy)
{
++res;
py[j].xx = wai[i].x;
py[j].yy = wai[i].y;
//if(res+(m2-i) < maxx) goto shabi;
break;
}
} //cout<<res<<'\n';
}
maxx = max(res,maxx);
}
printf("%d\n",maxx);
return 0;
}