제출 #785112

#제출 시각아이디문제언어결과실행 시간메모리
785112winter0101Port Facility (JOI17_port_facility)C++14
10 / 100
2 ms468 KiB
#include<bits/stdc++.h> using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) const int maxn=1e6+9; const long long du=1e9+7; pii a[maxn]; long long pw[maxn]; int mx[maxn*8]; int pos[maxn*2]; int st[maxn*8]; int f[maxn*2]; int findset(int u){ if (f[u]<0)return u; return f[u]=findset(f[u]); } void unite(int u,int v){ if (u==0||v==0)return; u=findset(u),v=findset(v); if (u==v)return ; if (f[u]>f[v])swap(u,v); f[u]+=f[v]; f[v]=u; } int n; void up(int id,int l,int r,int u,int v,int val){ if (l>v||r<u||u>v)return; if (u<=l&&r<=v){ //if (val==3)cout<<l<<" "<<r<<" "<<st[id]<<'\n'; if (val>abs(st[id])&&st[id]!=0){ unite(val+n,abs(st[id])); //cout<<val<<" "<<l<<" "<<r<<'\n'; } mx[id]=max(mx[id],val); return; } int mid=(l+r)/2; up(id*2,l,mid,u,v,val); up(id*2+1,mid+1,r,u,v,val); } void solve(int id,int l,int r){ int mid=(l+r)/2; if (l==r)return; solve(id*2,l,mid); solve(id*2+1,mid+1,r); int lst=0; for1(i,l,r){ if (pos[i]<mx[id]){ unite(lst,pos[i]); lst=max(lst,pos[i]); } } } void update(int id,int l,int r,int u,int val){ if (l>u||r<u)return; if (l==r){ st[id]=val; return; } int mid=(l+r)/2; update(id*2,l,mid,u,val); update(id*2+1,mid+1,r,u,val); st[id]=max(st[id*2],st[id*2+1]); } int get(int id,int l,int r,int u,int v){ if (l>v||r<u||u>v)return 0; if (u<=l&&r<=v)return st[id]; int mid=(l+r)/2; return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v)); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen(".INP","r",stdin); //freopen(".OUT","w",stdout); cin>>n; for1(i,1,n)cin>>a[i].fi>>a[i].se; sort(a+1,a+1+n); pw[0]=1; for1(i,1,n)pw[i]=(pw[i-1]*2)%du; for1(i,1,n){ pos[a[i].se]=i; } set<int>num; set<int>::iterator it; for1(i,1,n*2)f[i]=-1; for1(i,1,2*n)update(1,1,2*n,i,-2*n-1); for1(i,1,n){ update(1,1,2*n,a[i].se,-i); up(1,1,2*n,a[i].fi+1,a[i].se-1,i); } solve(1,1,2*n); for1(i,1,n){ if (findset(i)==findset(i+n)){ //cout<<findset(i); cout<<0; return 0; } } for1(i,1,n)unite(i,i+n); int cnt=0; for1(i,1,n){ //cout<<findset(i)<<'\n'; if (f[i]<0||f[i+n]<0){ cnt++; //cout<<i<<'\n'; } } cout<<pw[cnt]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...