제출 #999328

#제출 시각아이디문제언어결과실행 시간메모리
999328AdamGSPort Facility (JOI17_port_facility)C++17
0 / 100
1 ms2396 KiB
#include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const ll MOD=1e9+7; const int LIM=1e6+7; pair<int,int>T[LIM]; int F[LIM], S[2*LIM], odw[LIM], sum[LIM]; int fnd(int x) { if(F[x]==x) return x; return F[x]=fnd(F[x]); } void uni(int a, int b) { if(fnd(a)==fnd(b)) return; F[fnd(b)]=fnd(a); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; rep(i, n) { cin >> T[i].st >> T[i].nd; --T[i].st; --T[i].nd; } sort(T, T+n); vector<int>A, B; A.pb(MOD); B.pb(MOD); rep(i, n) { while(A.back()<T[i].st) A.pop_back(); while(B.back()<T[i].st) B.pop_back(); if(T[i].nd>max(A.back(), B.back())) { cout << 0 << '\n'; return 0; } if(A.back()<=B.back()) { if(T[i].nd<A.back()) A.pb(T[i].nd); else B.pb(T[i].nd); } else { if(T[i].nd<B.back()) B.pb(T[i].nd); else A.pb(T[i].nd); } } rep(i, n) F[i]=i; rep(i, n) { S[T[i].st]=i+1; S[T[i].nd]=-i-1; } vector<int>P; rep(i, 2*n) { int p=abs(S[i])-1; if(S[i]>0) { P.pb(p); continue; } vector<int>C; while(P.back()!=p) { C.pb(P.back()); P.pop_back(); } P.pop_back(); while(C.size()>0) { P.pb(C.back()); uni(p, C.back()); C.pop_back(); } } ll ans=1; rep(i, n) if(fnd(i)==i) ans=(ans*2)%MOD; cout << ans << '\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...