#include<set>
#include<algorithm>
#include<cstdio>
#define N 100005
using namespace std;
struct Able;
struct Use
{
int ed, v, st;
Use() {}
Use(int a, int b, int c) :ed(a), v(b), st(c) {}
Use(Able t);
friend bool operator<(Use a, Use b)
{
return a.ed > b.ed;
}
};
struct Able
{
int ed, v, st;
Able() {}
Able(int a, int b, int c) :ed(a), v(b), st(c) {}
Able(Use t) :ed(t.ed), v(t.v), st(t.st) {}
friend bool operator<(Able a, Able b)
{
return a.st < b.st;
}
};
void read(int &x)
{
x = 0; char c = getchar();
while(c < '0' || c>'9')
c = getchar();
while('0' <= c && c <= '9')
x = (x << 3) + (x << 1) + c - '0', c = getchar();
}
Use::Use(Able t) :ed(t.ed), v(t.v), st(t.st) {}
int n, m[2];
pair<int, int>info[2][N];
int had;
int fin[2][N];
int main()
{
// freopen("airport.in","r",stdin);
// freopen("airport.out","w",stdout);
read(n), read(m[0]), read(m[1]);
for(int F = 0; F < 2; ++F)
{
for(int i = 1; i <= m[F]; ++i)
read(info[F][i].first), read(info[F][i].second);
sort(info[F] + 1, info[F] + m[F] + 1);
}
//处理国内
for(int F = 0; F < 2; ++F)
{
set<Use>stk;
set<Able>able;
stk.insert({ 0,0,0 }), had = -1;
for(int i = 1; i <= m[F]; ++i)
{
auto p = stk.lower_bound({ info[F][i].first,0,0 });
if(p == stk.end())
stk.insert({ info[F][i].second,1,info[F][i].first });
else
{
int mx = p->ed;
while(p != stk.end() && p->ed > had)
{
able.insert(*p);
++p;
}
had = max(had, mx);
auto chose = able.begin();
stk.erase(*chose), stk.insert({ info[F][i].second,chose->v + 1,chose->st });
able.erase(chose);
//if(able.empty())
// had = -1;
}
}
able.clear();
while(!stk.empty())
{
auto p = stk.begin();
able.insert(*p), stk.erase(p);
}
int i = 1;
for(auto p = able.begin(); p != able.end(); ++p, ++i)
{
fin[F][i] = fin[F][i - 1] + p->v;
}
while(i <= n)
{
fin[F][i] = fin[F][i - 1], ++i;
}
}
int ans = 0;
for(int i = 0; i <= n; ++i)
{
ans = max(ans, fin[0][i] + fin[1][n - i]);
}
printf("%d", ans);
return 0;
}
关于这个程序,如果把结构体里的构造函数注释掉,那就会T,如果写构造函数的话最慢的点70多毫秒