社区讨论
三分过了?
P7913[CSP-S 2021] 廊桥分配参与者 6已保存回复 14
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 14 条
- 当前快照
- 1 份
- 快照标识符
- @m2j3lys7
- 此快照首次捕获于
- 2024/10/21 22:14 去年
- 此快照最后确认于
- 2025/11/04 23:49 4 个月前
看题解和讨论好像没有用三分过的,不知道我这个为什么能过(码风巨丑,凑合看吧
CPP#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
int n,m1,m2,s1[maxn],e1[maxn],s2[maxn],e2[maxn],cnt1,cnt2,sta1[maxn],sta2[maxn],a[maxn],ans;
struct node{
int st;
int ed;
bool operator<(const node& y) const{
return ed>y.ed;
}
};
struct node2{
int st;
int ed;
bool operator<(const node2& y) const{
return st<y.st;
}
};
node2 p1[maxn],p2[maxn];
priority_queue<node> q;
int check(int i){
while(!q.empty()) q.pop();
int ans1=0;
int l1=i,l2=n-i;
if(l1)
for(int j=1;j<=m1;++j){
node x;
x.st=p1[j].st;x.ed=p1[j].ed;
if(q.empty()) q.push(x),ans1++;
else {
while(!q.empty()&&q.top().ed<p1[j].st) q.pop();
if(q.size()<l1) q.push(x),ans1++;
}
}
while(!q.empty()) q.pop();
if(l2)
for(int j=1;j<=m2;++j){
node x;
x.st=p2[j].st;x.ed=p2[j].ed;
if(q.empty()) q.push(x),ans1++;
else {
while(!q.empty()&&q.top().ed<p2[j].st) q.pop();
if(q.size()<l2) q.push(x),ans1++;
}
}
return ans1;
}
int main(){
cin>>n>>m1>>m2;
for(int i=1;i<=m1;++i){
cin>>s1[i]>>e1[i];
a[++cnt1]=s1[i];
a[++cnt1]=e1[i];
}
sort(a+1,a+cnt1+1);
for(int i=1;i<=m1;++i){
int x,y;
p1[i].st=x=lower_bound(a+1,a+cnt1+1,s1[i])-a;
p1[i].ed=y=lower_bound(a+1,a+cnt1+1,e1[i])-a;
}
sort(p1+1,p1+m1+1);
memset(a,0,sizeof(a));
for(int i=1;i<=m2;++i){
cin>>s2[i]>>e2[i];
a[++cnt2]=s2[i];
a[++cnt2]=e2[i];
}
sort(a+1,a+cnt2+1);
for(int i=1;i<=m2;++i){
int x,y;
p2[i].st=x=lower_bound(a+1,a+cnt2+1,s2[i])-a;
p2[i].ed=y=lower_bound(a+1,a+cnt2+1,e2[i])-a;
}
sort(p2+1,p2+m2+1);
int l=0,r=n;
while(r-l>10){
int midl=l+(r-l)/3,midr=r-(r-l)/3;
if(check(midl)<=check(midr)) l=midl;
else r=midr;
}
for(int i=l;i<=r;++i){
ans=max(ans,check(i));
}
cout<<ans;
return 0;
}
回复
共 14 条回复,欢迎继续交流。
正在加载回复...