제출 #532816

#제출 시각아이디문제언어결과실행 시간메모리
532816couplefirePort Facility (JOI17_port_facility)C++17
100 / 100
1475 ms182968 KiB
#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(){ 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:77:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |  for(int i=0;i<v.size();++i){
      |              ~^~~~~~~~~
port_facility.cpp:62:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |      scanf("%d%d",&L[i],&R[i]);
      |      ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...