Submission #1108907

#TimeUsernameProblemLanguageResultExecution timeMemory
1108907vjudge1Port Facility (JOI17_port_facility)C++17
100 / 100
1194 ms400012 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 all(x) x.begin(),x.end() //#define int long long typedef long long ll; typedef pair<int,int> pii; const ll maxn=1e6+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*8]; int pt[maxn*8]; 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; // cerr<< u<<' '<<v<<''<<'\n'; if (u==v) return same^(cu!=cv); if (par[u]>par[v]) swap(u,v); par[u]+=par[v]; par[v]=u; col[v]=same^(cu==cv); 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) { // cerr<< st[id].size()<<" zzz\n"; while (pt[id]<st[id].size()) { if (pt[id]!=0) if (!Union(st[id][pt[id]-1],st[id][pt[id]],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(int, int, int, int, int)':
port_facility.cpp:57:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |     int mid=l+r>>1;
      |             ~^~
port_facility.cpp: In function 'void Edge(int, int, int, int, int, int)':
port_facility.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         while (pt[id]<st[id].size())
      |                ~~~~~~^~~~~~~~~~~~~~
port_facility.cpp:83:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |     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...