제출 #286704

#제출 시각아이디문제언어결과실행 시간메모리
286704YJUPort Facility (JOI17_port_facility)C++14
100 / 100
1883 ms210668 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=2e6+5; const ld pi=3.14159265359; const ll INF=(1LL<<60); #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() ll n,d1[N],d2[N],a[N],b[N],to[N],col[N],ans=1; vector<ll> v[N]; ll f1(ll id){ return (id==d1[id]?id:d1[id]=f1(d1[id])); } ll f2(ll id){ return (id==d2[id]?id:d2[id]=f2(d2[id])); } void DFS(ll id){ for(auto i:v[id]){ if(col[i]){ if(col[i]==col[id])ans=0; continue; } col[i]=3-col[id]; DFS(i); } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; REP1(i,2*n+1)d1[i]=d2[i]=i; REP1(i,n){ cin>>a[i]>>b[i]; to[a[i]]=to[b[i]]=i; d1[b[i]]=b[i]+1; } REP1(i,2*n){ if(b[to[i]]==i){ ll lst=0; for(ll j=f1(a[to[i]]+1);j<=i;j=f1(j+1)){ j=f2(j); v[to[i]].pb(to[j]);v[to[j]].pb(to[i]); if(lst)d2[lst]=j; lst=j; } d1[a[to[i]]]=a[to[i]]+1; } } REP1(i,n){ if(col[i]==0){ col[i]=1; DFS(i); ans=ans*2%MOD; } } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...