Submission #955164

#TimeUsernameProblemLanguageResultExecution timeMemory
955164edogawa_somethingPort Facility (JOI17_port_facility)C++17
0 / 100
29 ms51804 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vii; typedef long double ld; typedef pair<ll,ll> pii; #define F first #define S second #define pb push_back #define eb emplace_back #define all(v) v.begin(),v.end() #define pow poww const ll M=1e6+10; const ll inf=2e18; const ll mod=1e9+7; ll pow(ll x,ll y){ ll res=1; x%=mod; while(y>0){ if((y&1)) res*=x,res%=mod; x*=x,x%=mod; y=(y>>1); } return res; } ll sz=1; struct seg{ vii a; void init(ll x){ while(sz<x) sz*=2; a.resize(sz*2); } void update(ll i,ll v,ll x=0,ll lx=0,ll rx=sz){ if(rx-lx==1){ a[x]=v; return; } ll mid=((lx+rx)>>1); if(i<mid) update(i,v,x*2+1,lx,mid); else update(i,v,x*2+2,mid,rx); a[x]=max(a[x*2+1],a[x*2+2]); } ll query(ll l,ll r,ll x=0,ll lx=0,ll rx=sz){ if(r==l) return 0; if(lx>=l&&rx<=r) return a[x]; if(lx>=r||rx<=l) return 0; ll mid=((lx+rx)>>1); return max(query(l,r,x*2+1,lx,mid),query(l,r,x*2+2,mid,rx)); } }s,ss[2]; ll n,f[M],ind[M]; bool dis[M]; pii a[M]; set<ll>v[M]; int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int TC=1; //cin>>TC; while(TC--){ cin>>n; s.init(2*n); ss[0].init(n),ss[1].init(n); for(int i=0;i<n;i++){ cin>>a[i].F>>a[i].S,f[a[i].S]=a[i].F,ind[a[i].S]=ind[a[i].F]=i; } ll ans=n; sort(a,a+n); for(int i=0;i<n;i++){ s.update(a[i].F,a[i].S); } ss[0].update(1,a[0].S); for(int i=0;i<n;i++){ while(1){ ll x=s.query(a[i].F+1,a[i].S); if(x<a[i].S) break; else{ s.update(f[x],0); dis[ind[x]]=1-dis[i]; ss[dis[ind[x]]].update(f[x],x); ans--; v[i].insert(ind[x]); } } } for(int i=0;i<n;i++){ ll x=ss[dis[i]].query(a[i].F+1,a[i].S); if(x>a[i].S){ ans=0; } } if(ans==0) cout<<0<<'\n'; else cout<<pow(2,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...