Submission #166922

#TimeUsernameProblemLanguageResultExecution timeMemory
166922theStaticMindPort Facility (JOI17_port_facility)C++14
0 / 100
10 ms8184 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<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; } 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); } 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 'int32_t main()':
port_facility.cpp:30: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:40: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...