Submission #286466

#TimeUsernameProblemLanguageResultExecution timeMemory
286466YJUPort Facility (JOI17_port_facility)C++14
0 / 100
1 ms384 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 seg[3][4*N],ans=1,n,col[N]; ll r[N],l[N],x[N],y[N]; set<ll> idx; vector<pair<pll,ll> > 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(ll nd){ for(ll i=*idx.lwb(x[nd]);i<y[nd];i=*idx.lwb(i+1)){ ll tmp=max(l[i],r[i]); 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)cin>>x[i]>>y[i],ed.pb(mp(mp(x[i],y[i]),i)),r[x[i]]=l[y[i]]=i,idx.insert(x[i]),idx.insert(y[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(Q(ty,1,1,2*n+1,i.X.X,i.X.Y+1)){ cout<<"0\n";return 0; } ins(ty,1,1,2*n+1,i.X.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...