Submission #427889

#TimeUsernameProblemLanguageResultExecution timeMemory
427889errorgornPort Facility (JOI17_port_facility)C++17
100 / 100
1755 ms288008 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<int,int> #define fi first #define se second #define endl '\n' #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void rage(){ cout<<0<<endl; exit(0); } const int MOD=1000000007; int n; ii arr[1000005]; vector<int> al[1000005]; bool col[1000005]; bool vis[1000005]; struct UFDS{ int p[1000005]; int par[1000005]; UFDS(){ rep(x,0,1000005){ p[x]=x; par[x]=0; } } ii parent(int i){ if (p[i]==i) return ii(i,0); else{ ii temp=parent(p[i]); if (par[i]) temp.se^=1; tie(p[i],par[i])=temp; return temp; } } void unions(int i,int j){ ii pi=parent(i),pj=parent(j); if (pi.fi==pj.fi){ if (pi.se==pj.se) rage(); } else{ p[pi.fi]=pj.fi; par[pi.fi]=pi.se^pj.se^1; } } } ufds; struct node{ vector<int> v[4000010]; const int BUF=2000005; node (){ } void update(int i,int j,int k){ i+=BUF,j+=BUF+1; for (;i<j;i>>=1,j>>=1){ if (i&1){ v[i].pub(k); i++; } if (j&1){ j--; v[j].pub(k); } } } void query(int i,int k,int idx){ i+=BUF; while (i){ for (auto &it:v[i]){ ufds.unions(it,idx); } while (sz(v[i])>1) v[i].pob(); i>>=1; } } } root=node(); int ans=1; int main(){ cin.tie(0); cout.tie(0); cin.sync_with_stdio(false); cin>>n; rep(x,0,n){ cin>>arr[x].fi>>arr[x].se; } sort(arr,arr+n,[](ii i,ii j){ return i.se<j.se; }); rep(x,0,n){ //cout<<"arr: "<<x<<" "<<arr[x].fi<<" "<<arr[x].se<<endl; root.query(arr[x].fi,arr[x].se,x); root.update(arr[x].fi,arr[x].se,x); } rep(x,0,n) if (ufds.p[x]==x){ ans=2*ans%MOD; } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...