이 제출은 이전 버전의 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]);
}
set<int> dsuid[N];
set<pair<int,int> >minid;
int sz[N];
void push(int x,int y){
minid.erase(make_pair(*dsuid[y].begin(),y));
minid.erase(make_pair(*dsuid[x].begin(),x));
while(dsuid[y].size()>0){
dsuid[x].insert(*dsuid[y].begin());
dsuid[y].erase(dsuid[y].begin());
}
minid.insert(make_pair(*dsuid[x].begin(),x) );
}
void make(int v,int a){
if(v!=-1 && sz[v]>sz[a]){
par[a]= v;
sz[v]+=sz[a];
push(v,a);
}
else if(v!=-1){
par[v]= a;
sz[a]+=sz[v];
push(a,v);
}
}
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);
}
make(v,a);
make(u,b);
enemy[a]= b;
enemy[b]= a;
}
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,sz[i]= 1;
dsuid[i].insert(R[i]);
}
set<pair<int,int> >s;
set<pair<int,int> >::iterator it,jt;
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));
}
minid.insert(make_pair(R[id],id));
vector<int> Q;
for(it = minid.begin();it!= minid.end();++it){
if( (*it).first>=R[id])break;
Q.push_back((*it).second);
}
while(!Q.empty()){
make_enemy(Q.back(),id);
Q.pop_back();
}
}
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:84:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();++i){
~^~~~~~~~~
port_facility.cpp:69: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... |