社区讨论
求助3760贴海报
P3740[HAOI2014] 贴海报参与者 2已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @lo14qc62
- 此快照首次捕获于
- 2023/10/22 15:10 2 年前
- 此快照最后确认于
- 2023/11/02 14:42 2 年前
这个代码前4个测试点没过,请问有什么问题吗谢谢
CPP#include<bits/stdc++.h>
using namespace std;
const int Inf=9999999;
int n,m;
int a[Inf],b[Inf];
long long d[Inf],ddd,c[Inf],ccc;
int book[Inf];
int kkk=1;
int main(){
//离散化
cin>>n>>m;
if(n==0||m==0)cout<<0<<endl;
else{
for(int i=1;i<=m;i++){
cin>>a[i]>>b[i];
d[++ddd]=a[i];
d[++ddd]=b[i];
}
//去重
sort(d+1,d+1+ddd);
c[++ccc]=d[1];
for(int i=2;i<=ddd;i++){
if(d[i-1]!=d[i])c[++ccc]=d[i];
}
for(int i=1;i<=m;i++){
int x=lower_bound(c+1,c+1+ccc,a[i])-c;
int y=lower_bound(c+1,c+1+ccc,b[i])-c;
for(int j=x;j<=y;j++){
book[j]=i;
}
}
sort(book+1,book+1+ccc);
for(int i=2;i<=ccc;i++){
if(book[i-1]!=book[i])++kkk;
}
cout<<kkk;
}
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...