盒子
盒子

airport

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}

inline bool read(int& a){
int s=0,w=1;
char ch=getchar();
if(ch==EOF) return false;
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
s=s*10+ch-'0';
ch=getchar();
}
a=s*w;
return true;
}

inline void write(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}

inline void writeln(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
puts("");
}

inline void writesp(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
printf(" ");
}

template<typename...args>bool read(int &a,args&...x){
return (read(a)&&read(x...));
}

const int N=100010;
int n,m1,m2;
struct node{
int a,b;
}x1[N],x2[N];
int a1[N],b1[N],a2[N],b2[N];
int sum1[N],sum2[N];
int f1[N],f2[N];
int l1[N],l2[N];
int len1[N],len2[N];

bool operator<(const node &x,const node &y){
return x.a<y.a;
}

signed main(){
read(n,m1,m2);
for(int i=1;i<=m1;i++)
read(x1[i].a,x1[i].b);
for(int i=1;i<=m2;i++)
read(x2[i].a,x2[i].b);

sort(x1+1,x1+m1+1);
sort(x2+1,x2+m2+1);
for(int i=1;i<=m1;i++){
a1[i]=x1[i].a;
b1[i]=x1[i].b;
}

for(int i=1;i<=m2;i++){
a2[i]=x2[i].a;
b2[i]=x2[i].b;
}

int tot1=0,tot2=0;

for(int i=1;i<=m1;i++){
if(f1[i]) continue;
l1[i]=1;
int tmp=i;
int pos=upper_bound(a1+1,a1+m1+1,b1[tmp])-a1;
while(pos<=m1){
if(f1[pos]){
while(f1[pos]) pos++;
if(pos>m1) break;
}
l1[i]++;
f1[pos]=true;
tmp=pos;
pos=upper_bound(a1+1,a1+m1+1,b1[tmp])-a1;
if(pos>m1) break;
}
len1[++tot1]=l1[i];
}

for(int i=1;i<=m2;i++){
if(f2[i]) continue;
l2[i]=1;
int tmp=i;
int pos=upper_bound(a2+1,a2+m2+1,b2[tmp])-a2;
while(pos<=m2){
if(f2[pos]){
while(f2[pos]) pos++;
if(pos>m2) break;
}
l2[i]++;
f2[pos]=true;
tmp=pos;
pos=upper_bound(a2+1,a2+m2+1,b2[tmp])-a2;
if(pos>m2) break;
}
len2[++tot2]=l2[i];
}

for(int i=1;i<=n;i++) sum1[i]=sum1[i-1]+len1[i];
for(int i=1;i<=n;i++) sum2[i]=sum2[i-1]+len2[i];

int ans=-1;
for(int i=0;i<=n;i++){
ans=max(ans,sum1[i]+sum2[n-i]);
}

writeln(ans);
return 0;
}

本文作者:Zhao Yiming Zhao Yiming

本文链接: https://zhaoyiming313.github.io/2021/10/31/airport/

版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 4.0 国际许可协议,转载请注明。