제출 #1062420

#제출 시각아이디문제언어결과실행 시간메모리
106242012345678Port Facility (JOI17_port_facility)C++17
100 / 100
2551 ms228980 KiB
#include <bits/stdc++.h> using namespace std; const int nx=2e6+5, mod=1e9+7; int n, l[nx], r[nx], res=1, cnt, c[nx], f, vs[nx]; vector<int> d[nx]; pair<int, int> v[2*nx]; struct mnsegtree { pair<int, int> d[4*nx]; void update(int l, int r, int i, int idx, int vl, int id) { if (idx<l||r<idx) return; if (l==r) return d[i]={vl, id}, void(); int md=(l+r)/2; update(l, md, 2*i, idx, vl, id); update(md+1, r, 2*i+1, idx, vl, id); d[i]=min(d[2*i], d[2*i+1]); } pair<int, int> query(int l, int r, int i, int ql, int qr) { //cout<<"debug "<<l<<' '<<r<<' '<<ql<<' '<<qr<<'\n'; if (qr<l||r<ql||qr<ql) return {1e9, 1e9}; if (ql<=l&&r<=qr) return d[i]; int md=(l+r)/2; return min(query(l, md, 2*i, ql, qr), query(md+1, r, 2*i+1, ql, qr)); } } smn; struct mxsegtree { pair<int, int> d[4*nx]; void update(int l, int r, int i, int idx, int vl, int id) { if (idx<l||r<idx) return; if (l==r) return d[i]={vl, id}, void(); int md=(l+r)/2; update(l, md, 2*i, idx, vl, id); update(md+1, r, 2*i+1, idx, vl, id); d[i]=max(d[2*i], d[2*i+1]); } pair<int, int> query(int l, int r, int i, int ql, int qr) { if (qr<l||r<ql||qr<ql) return {-1e9, -1e9}; if (ql<=l&&r<=qr) return d[i]; int md=(l+r)/2; return max(query(l, md, 2*i, ql, qr), query(md+1, r, 2*i+1, ql, qr)); } } smx; void dfs(int u) { vs[u]=1; for (auto v:d[u]) { if (vs[v]) { if (c[v]==c[u]) f=1; continue; } c[v]=!c[u]; dfs(v); } } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) { cin>>l[i]>>r[i]; smn.update(1, 2*n, 1, l[i], r[i], i); smx.update(1, 2*n, 1, l[i], r[i], i); smn.update(1, 2*n, 1, r[i], l[i], i); smx.update(1, 2*n, 1, r[i], l[i], i); } for (int i=1; i<=n; i++) { auto mn=smn.query(1, 2*n, 1, l[i]+1, r[i]-1), mx=smx.query(1, 2*n, 1, l[i]+1, r[i]-1); //cout<<"mn "<<mn.first<<' '<<mn.second<<'\n'; if (mn.first<l[i]) d[i].push_back(mn.second), d[mn.second].push_back(i); if (mx.first>r[i] )d[i].push_back(mx.second), d[mx.second].push_back(i); } for (int i=1; i<=n; i++) if (!vs[i]) dfs(i), res=(res*2)%mod; if (f) cout<<0; else cout<<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...