Submission #286465

#TimeUsernameProblemLanguageResultExecution timeMemory
286465YJUPort Facility (JOI17_port_facility)C++14
22 / 100
6076 ms15964 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() map<pll,ll> col; ll seg[3][4*N],ans=1,n,x,y; ll r[N],l[N]; set<ll> idx; vector<pll> ed; ll Q(ll ty,ll id,ll l,ll r,ll ql,ll qr){ if(l>=ql&&r<=qr)return seg[ty][id]; if(l>=qr||r<=ql)return 0; ll mid=(l+r)/2; return Q(ty,id*2,l,mid,ql,qr)+Q(ty,id*2+1,mid,r,ql,qr); } void ins(ll ty,ll id,ll l,ll r,ll to,ll d){ if(l==r-1){seg[ty][id]+=d;return;} ll mid=(l+r)/2; if(to<mid){ ins(ty,id*2,l,mid,to,d); }else{ ins(ty,id*2+1,mid,r,to,d); } seg[ty][id]=seg[ty][id*2]+seg[ty][id*2+1]; } void DFS(pll nd){ for(ll i=*idx.lwb(nd.X);i<nd.Y;i=*idx.lwb(i+1)){ pll tmp; if(l[i]&&l[i]<nd.X)tmp=mp(l[i],i); if(r[i]&&r[i]>nd.Y)tmp=mp(i,r[i]); col[tmp]=3-col[nd]; idx.erase(tmp.X);idx.erase(tmp.Y); 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)cin>>x>>y,ed.pb(mp(x,y)),r[x]=y,l[y]=x,idx.insert(x),idx.insert(y); sort(ed.begin(),ed.end(),[](pll a,pll b){ if(a.Y-a.X!=b.Y-b.X)return (a.Y-a.X<b.Y-b.X); return (a.X<b.X); }); for(auto i:ed){ if(!col[i]){ ans=ans*2%MOD; col[i]=1; idx.erase(i.X);idx.erase(i.Y); DFS(i); } } sort(ed.begin(),ed.end()); for(auto i:ed){ int ty=col[i]; if(Q(ty,1,1,2*n+1,i.X,i.Y+1)){ cout<<"0\n";return 0; } ins(ty,1,1,2*n+1,i.Y,1); } 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...