Submission #166924

#TimeUsernameProblemLanguageResultExecution timeMemory
166924theStaticMindPort Facility (JOI17_port_facility)C++14
22 / 100
5919 ms1048580 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>adj[1000004]; vector<int>vis(1000004,-1); vector<pair<int,ii>> arr; int F(int x){ if(x==no[x])return x; return no[x]=F(no[x]); } bool merge(int x,int y){ x=F(x); y=F(y); if(x==y)return false; no[x]=y; return true; } bool dfs(int x){ for(int i=0;i<adj[x].size();i++){ int y=adj[x][i]; if(vis[y]==-1){ vis[y]=vis[x]^1; if(dfs(y)==false)return false; } else if(vis[y]==vis[x])return false; } 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++){ merge(itr->second,id); adj[id].pb(itr->second); adj[itr->second].pb(id); } data.insert({y,id}); } } for(int i=1;i<=n;i++){ if(F(i)==i)ans=ans*2%modulo; } for(int i=1;i<=n;i++){ if(vis[i]>=0)continue; vis[i]=1; if(dfs(i)==false){ cout<<0; return 0; } } cout<<ans; }

Compilation message (stderr)

port_facility.cpp: In function 'bool dfs(long long int)':
port_facility.cpp:27:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i=0;i<adj[x].size();i++){
                   ~^~~~~~~~~~~~~~
port_facility.cpp: In function 'int32_t main()':
port_facility.cpp:43: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:53: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...