记录编号 |
565886 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
[CSP 2021S]廊桥分配 |
最终得分 |
100 |
用户昵称 |
遥时_彼方 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.597 s |
提交时间 |
2021-10-26 21:15:34 |
内存使用 |
9.55 MiB |
显示代码纯文本
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
struct ql
{
int st;
int ed;
int p;
}a1[100001],a2[100001];
struct cmp2
{
bool operator()(ql x,ql y)
{
return x.ed>y.ed;
}
};
priority_queue<ql,vector<ql>,cmp2> t1;//以ed为关键词的小根堆
priority_queue<int,vector<int>,greater<int> > p1;
priority_queue<ql,vector<ql>,cmp2> t2;//以ed为关键词的小根堆
priority_queue<int,vector<int>,greater<int> > p2;
int nc,m1,m2;
bool cmp(ql x,ql y)
{
return x.st<y.st;
}
int b1[200001];
int b2[200001];
int ans;
int main()
{
freopen("2021airport.in","r",stdin);
freopen("2021airport.out","w",stdout);
cin>>nc>>m1>>m2;
// if(nc==10&&m1==100&&m2==100)
// {
// cout<<"32\n";
// return 0;
// }
for(int i=1;i<=m1;i++)
{
scanf("%d%d",&a1[i].st,&a1[i].ed);
}
for(int i=1;i<=m2;i++)
{
scanf("%d%d",&a2[i].st,&a2[i].ed);
}
sort(a1+1,a1+m1+1,cmp);
sort(a2+1,a2+m2+1,cmp);
// cout<<"PA1\n";
ql s3;
for(int i=1;i<=m1;i++)
{
if(t1.size()) s3=t1.top();
while(a1[i].st>s3.ed&&t1.size())
{
p1.push(s3.p);
t1.pop();
s3=t1.top();
}
if(p1.size())
{
a1[i].p=p1.top();
b1[a1[i].p]++;
t1.push(a1[i]);
p1.pop();
}
else
{
a1[i].p=t1.size()+1;
b1[a1[i].p]++;
t1.push(a1[i]);
}
}
// cout<<"PA2\n";
// for(int i=1;i<=3;i++) cout<<i<<":1: "<<b1[i]<<endl;
for(int i=1;i<=m2;i++)
{
if(t2.size()) s3=t2.top();
while(a2[i].st>s3.ed&&t2.size())
{
p2.push(s3.p);
t2.pop();
s3=t2.top();
}
if(p2.size())
{
a2[i].p=p2.top();
b2[a2[i].p]++;
t2.push(a2[i]);
p2.pop();
}
else
{
a2[i].p=t2.size()+1;
b2[a2[i].p]++;
t2.push(a2[i]);
}
}
// cout<<"PA2\n";
// for(int i=1;i<=3;i++) cout<<i<<":2: "<<b2[i]<<endl;
int j1=0;
int j2=0;
for(int i=m2;i>nc;i--) j2+=b2[i];
for(int i=0;i<=nc;i++)
{
j1+=b1[i];
ans=max(ans,j1+(m2-j2));
j2+=b2[nc-i];
}
cout<<ans<<endl;
return 0;
}
//3 5 0
//1 8
//2 6
//3 5
//9 18
//12 15
//3 5 0
//1 20
//4 30
//7 40
//2 8
//3 6