Submission #286474

#TimeUsernameProblemLanguageResultExecution timeMemory
286474YJUPort Facility (JOI17_port_facility)C++14
22 / 100
6097 ms16112 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() set<ll> ck[3],idx; ll n,x[N],y[N],g[N],col[N],ans=1; vector<pair<pll,ll> > ed; void DFS(ll nd){ for(ll i=*idx.lwb(x[nd]);i<y[nd];i=*idx.lwb(i+1)){ ll tmp=0; if(x[g[i]]&&y[g[i]]>y[nd])tmp=g[i]; if(y[g[i]]&&x[g[i]]<x[nd])tmp=g[i]; if(!tmp)continue; col[tmp]=3-col[nd]; idx.erase(x[tmp]);idx.erase(y[tmp]); DFS(tmp); } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; idx.insert(2*n+1);idx.insert(0); REP1(i,n){ idx.insert(i*2-1);idx.insert(i*2); cin>>x[i]>>y[i]; ed.pb(mp(mp(x[i],y[i]),i)); g[x[i]]=g[y[i]]=i; } sort(ed.begin(),ed.end(),[](pair<pll,ll> A,pair<pll,ll> B){ if(A.X.Y-A.X.X!=B.X.Y-B.X.X)return (A.X.Y-A.X.X<B.X.Y-B.X.X); return (A.X.X<B.X.X); }); for(auto i:ed){ if(!col[i.Y]){ ans=ans*2%MOD; col[i.Y]=1; idx.erase(i.X.X);idx.erase(i.X.Y); DFS(i.Y); } } sort(ed.begin(),ed.end()); for(auto i:ed){ int ty=col[i.Y]; if(ck[ty].lwb(i.X.X)!=ck[ty].end()&&*ck[ty].lwb(i.X.X)<i.X.Y){ cout<<"0\n";return 0; } ck[ty].insert(i.X.Y); } 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...