Submission #74224

#TimeUsernameProblemLanguageResultExecution timeMemory
74224TadijaSebezPort Facility (JOI17_port_facility)C++11
100 / 100
3085 ms562856 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back const int N=2000050; const int M=N*2; const int mod=1e9+7; int pos(int x){ return x<<1;} int neg(int x){ return x<<1|1;} struct DSU { int p[M]; void init(){ for(int i=0;i<N;i++) p[i]=i;} DSU(){ init();} int Find(int x){ return p[x]==x?x:p[x]=Find(p[x]);} void Union(int x, int y){ p[Find(x)]=Find(y);} } Tree; set<pair<int,int> > st; int l[N],r[N],id[N]; bool comp(int i, int j){ return l[i]<l[j] || l[i]==l[j] && r[i]<r[j];} int main() { int n,i; scanf("%i",&n); for(i=1;i<=n;i++) scanf("%i %i",&l[i],&r[i]),id[i]=i; sort(id+1,id+1+n,comp); for(i=1;i<=n;i++) { int j=id[i]; set<pair<int,int> >::iterator it; it=st.upper_bound(mp(r[j],j)); int lst=0; if(it!=st.begin()){ it--;lst=it->second;} for(it=st.lower_bound(mp(l[j],j));it!=st.upper_bound(mp(r[j],j));it++) { Tree.Union(pos(it->second),neg(j)); Tree.Union(neg(it->second),pos(j)); if(Tree.Find(pos(j))==Tree.Find(neg(lst))) break; } st.insert(mp(r[j],j)); } int sol=1; for(i=1;i<=n;i++) { if(Tree.Find(pos(i))==pos(i)) sol=sol*2%mod; if(Tree.Find(pos(i))==Tree.Find(neg(i))) sol=0; } printf("%i\n",sol); return 0; }

Compilation message (stderr)

port_facility.cpp: In function 'bool comp(int, int)':
port_facility.cpp:21:57: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
 bool comp(int i, int j){ return l[i]<l[j] || l[i]==l[j] && r[i]<r[j];}
                                              ~~~~~~~~~~~^~~~~~~~~~~~
port_facility.cpp: In function 'int main()':
port_facility.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
port_facility.cpp:26:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1;i<=n;i++) scanf("%i %i",&l[i],&r[i]),id[i]=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...