Submission #166933

#TimeUsernameProblemLanguageResultExecution timeMemory
166933theStaticMindPort Facility (JOI17_port_facility)C++14
22 / 100
6056 ms42600 KiB
#include<bits/stdc++.h> #define mp make_pair #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; vector<int>no(1000004); vector<int>vis(1000004,0); vector<int>lazy(1000004,0); vector<int>sz(1000004,1); vector<pair<int,ii>> arr; int F(int x){ while(x!=no[x]){ x=no[x]; } return x; } int get_lazy(int x){ int l=lazy[x]; while(x!=no[x]){ x=no[x]; l^=lazy[x]; } return l; } bool merge(int x,int y){ int X=F(x); int Y=F(y); if(X==Y){ if(vis[x]^get_lazy(x)==vis[y]^get_lazy(y))return false; } else{ if(sz[X]<sz[Y]){ swap(X,Y); swap(x,y); } if(vis[x]^get_lazy(x)==vis[y]^get_lazy(y)){ lazy[Y]^=1; } no[Y]=X; sz[X]+=sz[Y]; } return true; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // freopen("q.cik","w",stdout); int n,ans=1; for(int i=0;i<no.size();i++)no[i]=i; cin>>n; for(int i=1;i<=n;i++){ int a,b; cin>>a>>b; arr.pb({a,{b,i}}); arr.pb({b,{b,-i}}); } sort(all(arr)); set<ii>data; for(int i=0;i<arr.size();i++){ int x=arr[i].first,y=arr[i].second.first,id=arr[i].second.second; if(id<0){ data.erase({x,-id}); } else{ for(set<ii>::iterator itr=data.lower_bound({x,0});itr!=data.end()&&itr->first<y;itr++){ if(!merge(itr->second,id)){ cout<<0; return 0; } } data.insert({y,id}); } } for(int i=1;i<=n;i++){ if(F(i)==i)ans=ans*2%modulo; } cout<<ans; }

Compilation message (stderr)

port_facility.cpp: In function 'bool merge(long long int, long long int)':
port_facility.cpp:34:34: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
             if(vis[x]^get_lazy(x)==vis[y]^get_lazy(y))return false;
port_facility.cpp:41:34: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
             if(vis[x]^get_lazy(x)==vis[y]^get_lazy(y)){
port_facility.cpp: In function 'int32_t main()':
port_facility.cpp:55:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=0;i<no.size();i++)no[i]=i;
                   ~^~~~~~~~~~
port_facility.cpp:65:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=0;i<arr.size();i++){
                   ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...