subtask0 100分AK subtask1前两个TLE
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
struct plane {
int ar,le;
} pl[maxn];
int lst[maxn],layer,num[maxn],tot[maxn][2];
int n,m1,m2,tmp;
bool cmp(plane x,plane y) {
return x.ar<y.ar;
}
int main() {
cin>>n>>m1>>m2;
for(int i=1; i<=m1; i++){
cin>>pl[i].ar>>pl[i].le;
}
sort(pl+1,pl+m1+1,cmp);
for(int i=1; i<=m1; i++) {
tmp=0;
for(int j=1; j<=layer; j++){
if(pl[i].ar>lst[j]) {
tmp=j;
break;
}
}
if(!tmp){
layer++;
lst[layer]=pl[i].le;
num[layer]++;
} else{
lst[tmp]=pl[i].le;
num[tmp]++;
}
}
for(int i=1; i<=n; ++i){
tot[i][0]=num[i]+tot[i-1][0];
}
layer=0;
memset(num,0,sizeof(num));
for(int i=1; i<=m2; i++){
cin>>pl[i].ar>>pl[i].le;
}
sort(pl+1,pl+m2+1,cmp);
for(int i=1; i<=m2; i++) {
tmp=0;
for(int j=1; j<=layer; j++){
if(pl[i].ar>lst[j]) {
tmp=j;
break;
}
}
if(!tmp){
layer++;
lst[layer]=pl[i].le;
num[layer]++;
} else{
lst[tmp]=pl[i].le;
num[tmp]++;
}
}
for(int i=1; i<=n; ++i){
tot[i][1]=num[i]+tot[i-1][1];
}
int ans=-1;
for(int i=0; i<=n; ++i){
ans=max(ans,tot[i][0]+tot[n-i][1]);
}
cout<<ans<<endl;
return 0;
}
前缀和做法求助