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
| #include<bits/stdc++.h> using namespace std; const int max_n=100005,inf=2100000000; inline int read(){ int x=0;bool w=0;char c=getchar(); while(c<'0' || c>'9') w|=c=='-',c=getchar(); while(c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return w?-x:x; } inline void write(int x){ if(x<0) x=-x,putchar('-'); if(x>9) write(x/10); putchar(x%10^48); }
int lisan[max_n*4],cntls,R1,R2;
int n,m1,m2; struct plane{ int l,r; inline void init(int x,int y){ l=x,r=y; } }a[max_n],b[max_n]; inline bool cmp(plane a,plane b){ return a.l<b.l; }
struct segment_tree{ int L[max_n*8],R[max_n*8]; int mn[max_n*8];
#define ls(x) (x<<1) #define rs(x) (x<<1|1)
inline void pushup(int x){ mn[x]=min(mn[ls(x)],mn[rs(x)]); } inline void build(int x,int l,int r){ L[x]=l,R[x]=r,mn[x]=inf; if(l==r) return; int mid=(l+r)>>1; build(ls(x),l,mid), build(rs(x),mid+1,r); pushup(x); } inline void upd(int x,int pos,int val){ if(L[x]==pos && R[x]==pos){ mn[x]=val; return; } int mid=(L[x]+R[x])>>1; if(pos<=mid) upd(ls(x),pos,val); else upd(rs(x),pos,val); pushup(x); } inline int ask(int x,int l,int r){ if(l<=L[x] && R[x]<=r) return mn[x]; int mid=(L[x]+R[x])>>1,res=inf; if(l<=mid) res=min(res,ask(ls(x),l,r)); if(r>mid) res=min(res,ask(rs(x),l,r)); pushup(x); return res; } }seg;
int ls[max_n],id[max_n]; int f1[max_n],f2[max_n];
inline void sol1(){ int cnt=0; seg.build(1,1,R1); for(register int i=1;i<=m1;++i){ int l=a[i].l,r=a[i].r; int ask=seg.ask(1,1,l); if(ask==inf){ id[i]=++cnt,ls[cnt]=r; seg.upd(1,r,cnt); } else{ id[i]=ask,seg.upd(1,ls[ask],inf); ls[ask]=r,seg.upd(1,r,ask); } } for(register int i=1;i<=m1;++i) ++f1[id[i]]; for(register int i=1;i<=m1;++i) f1[i]+=f1[i-1]; } inline void sol2(){ int cnt=0; memset(ls,0,sizeof(ls)); seg.build(1,1,R2); for(register int i=1;i<=m2;++i){ int l=b[i].l,r=b[i].r; int ask=seg.ask(1,1,l); if(ask==inf){ id[i]=++cnt,ls[cnt]=r; seg.upd(1,r,cnt); } else{ id[i]=ask,seg.upd(1,ls[ask],inf); ls[ask]=r,seg.upd(1,r,ask); } } for(register int i=1;i<=m2;++i) ++f2[id[i]]; for(register int i=1;i<=m2;++i) f2[i]+=f2[i-1]; }
signed main(){ n=read(),m1=read(),m2=read(); for(register int i=1;i<=m1;++i){ int l=read(),r=read(); a[i].init(l,r); lisan[++cntls]=l,lisan[++cntls]=r; } sort(lisan+1,lisan+1+cntls),R1=cntls; for(register int i=1;i<=m1;++i){ a[i].l=lower_bound(lisan+1,lisan+1+cntls,a[i].l)-lisan; a[i].r=lower_bound(lisan+1,lisan+1+cntls,a[i].r)-lisan; } cntls=0; for(register int i=1;i<=m2;++i){ int l=read(),r=read(); b[i].init(l,r); lisan[++cntls]=l,lisan[++cntls]=r; } sort(lisan+1,lisan+1+cntls),R2=cntls; for(register int i=1;i<=m2;++i){ b[i].l=lower_bound(lisan+1,lisan+1+cntls,b[i].l)-lisan; b[i].r=lower_bound(lisan+1,lisan+1+cntls,b[i].r)-lisan; }
sort(a+1,a+1+m1,cmp), sort(b+1,b+1+m2,cmp);
sol1(),sol2(); int ans=0; for(register int i=0;i<=n;++i) ans=max(ans,f1[i]+f2[n-i]); write(ans); return 0; }
|