제출 #367500

#제출 시각아이디문제언어결과실행 시간메모리
367500balbitPort Facility (JOI17_port_facility)C++14
100 / 100
1207 ms172776 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define y1 zck_is_king #define pii pair<int, int> #define ull unsigned ll #define f first #define s second #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() #define SQ(x) (x)*(x) #define MN(a,b) a = min(a,(__typeof__(a))(b)) #define MX(a,b) a = max(a,(__typeof__(a))(b)) #define pb push_back #define REP(i,n) for (int i = 0; i<n; ++i) #define RREP(i,n) for (int i = n-1; i>=0; --i) #define REP1(i,n) for (int i = 1; i<=n; ++i) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #ifdef BALBIT #define IOS() #define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__); template<typename T> void _do(T &&x){cerr<<x<<endl;} template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);} #else #define IOS() ios_base::sync_with_stdio(0);cin.tie(0); #define endl '\n' #define bug(...) #endif const int iinf = 1e9+10; const ll inf = 1ll<<60; const ll mod = 1e9+7 ; void GG(){cout<<"0\n"; exit(0);} ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod ll re=1; while (n>0){ if (n&1) re = re*a %mo; a = a*a %mo; n>>=1; } return re; } ll inv (ll b, ll mo = mod){ if (b==1) return b; return (mo-mo/b) * inv(mo%b,mo) % mo; } const int maxn = 2e6+5; int par[maxn]; int find(int x) {return x==par[x]?x:par[x] = find(par[x]);} int cc = 0; vector<int> g[maxn]; void mg(int a, int b) { int A=find(a), B=find(b); if (A!=B) { --cc; par[A] = B; g[a].pb(b); g[b].pb(a); bug(a,b); } } int col[maxn]; void dfs(int v) { for (int u : g[v]) { if (col[u] == -1) { col[u] = col[v] ^ 1; dfs(u); } } } struct seg{ int l,r,i; }; int who[maxn]; bool pluck[maxn]; signed main(){ IOS(); memset(col, -1, sizeof col); int n; cin>>n; REP(i,n) par[i] = i; vector<seg> v; cc = n; REP(i,n) { int a,b; cin>>a>>b; v.pb({a,b,i}); who[a]=who[b]=i; pluck[b] = 1; } REP(hi,2) { vector<seg>q; sort(ALL(v), [&](seg a, seg b){return a.r < b.r;}); REP(i,n) { while (!q.empty() && q.back().l > v[i].l) q.pop_back(); if (!q.empty() && q.back().r > v[i].l) { mg(v[i].i, q.back().i); // if (q.back().i==0 && v[i].i==2) { // bug(q.back().r, v[i].l); // } // q.back().r = v[i].r; q.back(). // }else{ } q.pb(v[i]); } // bug("HO"); for (seg & s : v) { s.l=-s.l; s.r=-s.r; swap(s.l, s.r); } } bug(cc); REP(i,n) { if (col[i] == -1) { col[i] = 0; dfs(i); } } REP(i,n) bug(i, col[i]); vector<int> s1,s2; s1.pb(-1); s2.pb(-1); REP1(i,2*n){ if (pluck[i]) { if (s1.back()==who[i]) s1.pop_back(); else if (s2.back()==who[i]) s2.pop_back(); else GG(); }else{ (col[who[i]]?s1:s2).pb(who[i]); } } cout<<mpow(2,cc)<<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...