Submission #127338

#TimeUsernameProblemLanguageResultExecution timeMemory
127338baluteshihPort Facility (JOI17_port_facility)C++14
0 / 100
56 ms48120 KiB
#include <bits/stdc++.h> #include<ext/pb_ds/priority_queue.hpp> #define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define pb push_back #define MP make_pair #define F first #define S second #define MEM(i,j) memset(i,j,sizeof i) #define ALL(v) v.begin(),v.end() #define ET cout << "\n" #define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;} using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll MOD=1e9+7; __gnu_pbds::priority_queue<pii,greater<pii>,pairing_heap_tag> pq[1000005]; map<int,int> mp; pii seg[1000005]; int boss[2000005]; bitset<2000005> vis; int finds(int x) { if(boss[x]==x) return x; return boss[x]=finds(boss[x]); } void Union(int a,int b) { a=finds(a),b=finds(b); boss[a]=b; } void merge(int a,int b,int t) { if(t==0) Union(a<<1,b<<1),Union(a<<1|1,b<<1|1); else Union(a<<1,b<<1|1),Union(a<<1|1,b<<1); } int main() {jizz int n,flag=1,ans=1,cnt=0,tp=0; cin >> n; for(int i=0;i<n;++i) cin >> seg[i].F >> seg[i].S,boss[i<<1]=i<<1,boss[i<<1|1]=i<<1|1; sort(seg,seg+n); for(int i=0;i<n&&flag;++i) { while(!mp.empty()&&mp.begin()->F<seg[i].F) { int t=mp.begin()->S; mp.erase(mp.begin()),pq[t].pop(); if(!pq[t].empty()) mp.insert(MP(t,pq[t].top().F)); } int beg=-1; while(!mp.empty()&&mp.begin()->F<seg[i].S) { if(!~beg) beg=mp.begin()->S; else merge(pq[beg].top().S,pq[mp.begin()->S].top().S,0),pq[beg].join(pq[mp.begin()->S]); mp.erase(mp.begin()); } if(~beg) merge(i,pq[beg].top().S,1),mp.insert(MP(pq[beg].top().F,beg)); pq[tp].push(MP(seg[i].S,i)),mp.insert(MP(seg[i].S,tp)),++tp; } for(int i=0;i<n&&flag;++i) if(finds(i<<1)==finds(i<<1|1)) flag=0; else { if(!vis[finds(i<<1)]) ++cnt,vis[finds(i<<1)]=1; if(!vis[finds(i<<1|1)]) ++cnt,vis[finds(i<<1|1)]=1; } cnt/=2; for(int i=0;i<cnt;++i) ans=ans*2%MOD; if(flag) cout << ans << "\n"; else cout << "0\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...