이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6+15,mod = 1e9+7;
int L[N],R[N];
int par[N],enemy[N];
int find(int a){
if(a==-1)return -1;
if(a==par[a])return a;
return par[a]= find(par[a]);
}
void make_enemy(int a,int b){
a = find(a),b = find(b);
int u = find(enemy[a]), v = find(enemy[b]);
if(a==b || (u!=-1 && u==v)){
printf("0\n");
exit(0);
}
if(v!=-1)par[v]= a;
if(u!=-1)par[u]= b;
enemy[a]= b;
enemy[b]= a;
}
set<int> dsuid[N];
int main(){
//freopen("input.txt","r",stdin);
int n;
cin>>n;
vector<pair<int,int> >v;
for(int i=1;i<=n;++i){
scanf("%d%d",&L[i],&R[i]);
v.push_back(make_pair(L[i],i));
}
sort(v.begin(),v.end());
for(int i=1;i<=n;++i){
par[i]= i,enemy[i]= -1;
dsuid[i].insert(R[i]);
}
set<pair<int,int> >s;
set<pair<int,int> >::iterator it,jt;
set<pair<int,int> >minid;
vector<pair<int,int> > temp;
set<int>::iterator nx;
int u;
for(int i=0;i<v.size();++i){
int l = v[i].first, id = v[i].second;
while(minid.size()>0){
it = minid.begin();
if((*it).first>l)break;
u = (*it).second;
minid.erase(it);
while(dsuid[u].size()>0){
if( *dsuid[u].begin()>l)break;
else
dsuid[u].erase(dsuid[u].begin());
}
if(dsuid[u].size()>0)
minid.insert(make_pair(*dsuid[u].begin(),u));
}
temp.clear();
u = -1;
for(it =minid.begin();it!= minid.end();){
if( (*it).first>=R[id])break;
jt = it;
u = (*it).second;
temp.push_back(*it);
make_enemy(id,u);
it = ++jt;
}
u = find(u);
for(int j=0;j<temp.size();++j){
pair<int,int> val = temp[j];
if(val.second == u)continue;
int v= val.second;
minid.erase(val);
while(!dsuid[v].empty()){
dsuid[u].insert(*dsuid[v].begin());
dsuid[v].erase(dsuid[v].begin());
}
}
if(find(id)==id){
minid.insert(make_pair(R[id],id));
}
}
long long ret= 1;
for(int i=1;i<=n;++i){
if(find(i)==i&& find(enemy[i])<i){
ret= (ret*2)%mod;
}
}
cout<<ret<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
port_facility.cpp: In function 'int main()':
port_facility.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();++i){
~^~~~~~~~~
port_facility.cpp:95:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<temp.size();++j){
~^~~~~~~~~~~~
port_facility.cpp:40:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&L[i],&R[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |