set做法:f1/2[]表示分开的答案
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
LL n,m1,m2,f1[100005],f2[100005],ans;
struct node{
LL l,r;
bool operator<(const node &p)const{
return l<p.l;
}
}a[100005],b[100005];
set<node> st;
int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
cin>>n>>m1>>m2;
for(int i=1;i<=m1;i++) cin>>a[i].l>>a[i].r;
for(int i=1;i<=m2;i++) cin>>b[i].l>>b[i].r;
st.clear();
for(int i=1;i<=m1;i++) st.insert(a[i]);
for(int i=1;i<=n;i++){
LL loc=0,cnt=0;
while(1){
auto it=lower_bound(st.begin(),st.end(),node{loc,0});
if(it==st.end()) break;
loc=it->r;
st.erase(it);cnt++;
}
f1[i]=f1[i-1]+cnt;
}
st.clear();
for(int i=1;i<=m2;i++) st.insert(b[i]);
for(int i=1;i<=n;i++){
LL loc=0,cnt=0;
while(1){
auto it=lower_bound(st.begin(),st.end(),node{loc,0});
if(it==st.end()) break;
loc=it->r;
st.erase(it);cnt++;
}
f2[i]=f2[i-1]+cnt;
}
for(int i=0;i<=n;i++){
//cout<<f1[i]<<' '<<f2[i]<<endl;
ans=max(ans,f1[i]+f2[n-i]);
}
cout<<ans;
return 0;
}