代码:
// bug: 1.#3 28 => 32 finished on 7-17
// 2.Time limit error
#include <bits/stdc++.h>
using namespace std;
namespace fast_read
{ // copy from https://www.cnblogs.com/ucprer/p/13955479.html
const int MAXL((1 << 18) + 1);
int iof, iotp;
char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL], *iooS = ioof, *iooT = ioof + MAXL - 1, ioc, iost[55];
char Getchar()
{
if (ioiS == ioiT)
{
ioiS = ioif;
ioiT = ioiS + fread(ioif, 1, MAXL, stdin);
return (ioiS == ioiT ? EOF : *ioiS++);
}
else
return (*ioiS++);
}
void Write()
{
fwrite(ioof, 1, iooS - ioof, stdout);
iooS = ioof;
}
void Putchar(char x)
{
*iooS++ = x;
if (iooS == iooT)
Write();
}
inline int read()
{
int x = 0;
for (iof = 1, ioc = Getchar(); (ioc < '0' || ioc > '9') && ioc != EOF;)
iof = ioc == '-' ? -1 : 1, ioc = Getchar();
if (ioc == EOF)
Write(), exit(0);
for (x = 0; ioc <= '9' && ioc >= '0'; ioc = Getchar())
x = (x << 3) + (x << 1) + (ioc ^ 48);
return x * iof;
}
inline long long read_ll()
{
long long x = 0;
for (iof = 1, ioc = Getchar(); (ioc < '0' || ioc > '9') && ioc != EOF;)
iof = ioc == '-' ? -1 : 1, ioc = Getchar();
if (ioc == EOF)
Write(), exit(0);
for (x = 0; ioc <= '9' && ioc >= '0'; ioc = Getchar())
x = (x << 3) + (x << 1) + (ioc ^ 48);
return x * iof;
}
void Getstr(char *s, int &l)
{
for (ioc = Getchar(); ioc == ' ' || ioc == '\n' || ioc == '\t';)
ioc = Getchar();
if (ioc == EOF)
Write(), exit(0);
for (l = 0; !(ioc == ' ' || ioc == '\n' || ioc == '\t' || ioc == EOF); ioc = Getchar())
s[l++] = ioc;
s[l] = 0;
}
template <class Int>
void Print(Int x, char ch = '\0')
{
if (!x)
Putchar('0');
if (x < 0)
Putchar('-'), x = -x;
while (x)
iost[++iotp] = x % 10 + '0', x /= 10;
while (iotp)
Putchar(iost[iotp--]);
if (ch)
Putchar(ch);
}
void Putstr(const char *s)
{
for (int i = 0, n = strlen(s); i < n; ++i)
Putchar(s[i]);
}
}
#define MAXN 10000000
#define int long long
struct Time
{
int start;
int end;
bool flag;
};
int n, m1, m2; //廊桥数量,国内航班数量,国际航班数量
Time in[MAXN], out[MAXN]; //国内航班时刻表,国际航班时刻表
int _out = 0; //输出
bool cmp(Time a, Time b) //按照起始时间从小到大排序
{
return a.start < b.start;
}
int findin()
{
int lasttime = -1;
bool flag = true;
int out = 1;
for (int i = 1; i <= m1; i++)
{
if (!in[i].flag && lasttime <= in[i].start)
{
lasttime = in[i].end;
if (!flag)
{
out++;
}
else
{
flag = false;
}
}
}
return out;
}
int findout()
{
int lasttime = -1;
bool flag = true;
int ans = 1;
for (int i = 1; i <= m2; i++)
{
if (!out[i].flag && lasttime <= out[i].start)
{
lasttime = out[i].end;
if (!flag)
{
ans++;
}
else
{
flag = false;
}
}
}
return ans;
}
void makein()
{
int lasttime = -1;
bool flag = true;
_out++;
for (int i = 1; i <= m1; i++)
{
if (!in[i].flag && lasttime <= in[i].start)
{
lasttime = in[i].end;
if (!flag)
{
_out++;
}
else
{
flag = false;
}
in[i].flag = true;
}
}
return;
}
void makeout()
{
int lasttime = -1;
bool flag = true;
_out++;
for (int i = 1; i <= m2; i++)
{
if (!out[i].flag && lasttime <= out[i].start)
{
lasttime = out[i].end;
if (!flag)
{
_out++;
}
else
{
flag = false;
}
out[i].flag = true;
}
}
return;
}
signed main()
{
n = fast_read::read_ll();
m1 = fast_read::read_ll();
m2 = fast_read::read_ll();
// cin >> n >> m1 >> m2;
for (int i = 1; i <= m1; i++)
{
// cin >> in[i].start >> in[i].end;
in[i].start = fast_read::read_ll();
in[i].end = fast_read::read_ll();
}
for (int i = 1; i <= m2; i++)
{
out[i].start = fast_read::read_ll();
out[i].end = fast_read::read_ll();
// cin >> out[i].start >> out[i].end;
}
sort(in + 1, in + m1 + 1, cmp);
sort(out + 1, out + m2 + 1, cmp);
for (int i = 1; i <= n; i++)
{
if (findin() >= findout())
{
makein();
}
else
{
makeout();
}
}
cout << _out;
return 0;
}