Submission #1108900

#TimeUsernameProblemLanguageResultExecution timeMemory
1108900vjudge1Port Facility (JOI17_port_facility)C++17
0 / 100
33 ms193104 KiB
#include<bits/stdc++.h> using namespace std; #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 int long long #define all(x) x.begin(),x.end() typedef long long ll; typedef pair<int,int> pii; const ll maxn=2e6+5; const ll offset=2e5; const ll inf=1e18; const int base=550; const ll mod=1e9+7; int n,m; pii a[maxn]; int par[maxn]; bool col[maxn]; vector<int> st[maxn*4]; int pt[maxn*4]; pii Find(int u) { int c=0; while (par[u]>0) { c^=col[u]; u=par[u]; } c^=col[u]; return {u,c}; } bool Union(int u,int v,bool same) { // cerr<< "Merge "<<u<<' '<<v<<' '<<same<<'\n'; pii x=Find(u),y=Find(v); u=x.fi; v=y.fi; int cu=x.se,cv=y.se; if (u==v) return same^(cu!=cv); par[u]+=par[v]; par[v]=u; col[v]=same^1; return 1; } void Update(int u,int val,int id=1,int l=1,int r=2*n) { st[id].pb(val); if (l==r) return; int mid=l+r>>1; if (u<=mid) Update(u,val,id*2,l,mid); else Update(u,val,id*2+1,mid+1,r); } void Edge(int u,int v,int val,int id=1,int l=1,int r=2*n) { if (st[id].empty()||u>r || v<l) return; if (u<=l && r<=v) { while (pt[id]<st[id].size()) { if (pt[id]!=0) if (!Union(st[id][pt[id]],st[id][pt[id]-1],1)) { cout << "0"; exit(0); } pt[id]++; } if (!Union(val,st[id].back(),0)) { cout << "0"; exit(0); } return; } int mid=l+r>>1; Edge(u,v,val,id*2,l,mid); Edge(u,v,val,id*2+1,mid+1,r); } void sol() { cin >> n; for1(i,1,n) { par[i]=-1; cin >> a[i].fi>> a[i].se; } sort(a+1,a+1+n,[](pii x,pii y) { return x.se>y.se; }); for1(i,1,n) { // cerr<<i<<' '<<a[i].fi<<' '<<a[i].se<<'\n'; Edge(a[i].fi,a[i].se,i); Update(a[i].fi,i); } int res=1; for1(i,1,n) { if (par[i]<0) res=res*2%mod; } cout << res; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #define task "acll" // freopen(task".inp","r",stdin); // freopen(task".out","w",stdout); int t=1;//cin >> t; while (t--) { sol(); } } /* 10 2 0 2 1 4 3 5 6 8 7 10 9 1 2 5 8 6 1 12 2 1 3 4 5 6 6 1 1 4 1 2 6 2 1 2 2 1 3 2 1 5 2 1 6 */

Compilation message (stderr)

port_facility.cpp: In function 'void Update(long long int, long long int, long long int, long long int, long long int)':
port_facility.cpp:55:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |     int mid=l+r>>1;
      |             ~^~
port_facility.cpp: In function 'void Edge(long long int, long long int, long long int, long long int, long long int, long long int)':
port_facility.cpp:64:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         while (pt[id]<st[id].size())
      |                ~~~~~~^~~~~~~~~~~~~~
port_facility.cpp:80:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |     int mid=l+r>>1;
      |             ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...