Submission #535661

#TimeUsernameProblemLanguageResultExecution timeMemory
535661AntekbPort Facility (JOI17_port_facility)C++14
10 / 100
56 ms99208 KiB
#include<bits/stdc++.h> using namespace std; #define st first #define nd second typedef pair<int, int> pii; const int N=1<<21; pii seg[N]; vector<int> tab[N+N]; void insert(int id){ int l=seg[id].st+N, r=seg[id].nd+1+N; for(;l<r; l>>=1, r>>=1){ if(l&1)tab[l++].push_back(id); if(r&1)tab[--r].push_back(id); } } int vis[N]; void dfs(int s){ vector<int> V; V.push_back(s); vis[s]=1; for(int i=0; i<V.size(); i++){ int v=V[i]; int l=seg[v].st+N, r=seg[v].nd+N; while(l){ for(auto u:tab[l]){ if(!vis[u]){ vis[u]=1; V.push_back(u); } } tab[l].clear(); l/=2; } while(r){ for(auto u:tab[r]){ if(!vis[u]){ vis[u]=1; V.push_back(u); } } tab[r].clear(); r/=2; } } } int lew[N], pra[N]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n; cin>>n; for(int i=0; i<n; i++){ cin>>seg[i].st>>seg[i].nd; insert(i); } int ile=0, ans=1; int mod=1e9+7; vector<pii> V2; for(int i=0; i<n; i++){ V2.push_back({seg[i].st-seg[i].nd, i}); } sort(V2.begin(), V2.end()); for(int i=0; i<n; i++){ int j=V2[i].nd; if(!vis[j]){ ile++; ans*=2; if(ans>=mod)ans-=mod; dfs(j); } } bool czy=1; vector<pair<pii, int> > V; for(int i=0; i<n; i++){ V.push_back({seg[i], i}); } sort(V.begin(), V.end()); set<int> S; for(int i=0; i<n; i++){ int a=V[i].st.st, b=V[i].st.nd, c=V[i].nd; S.insert(b); auto it=S.find(b); if(it!=S.begin()){ it--; lew[c]=*it; } else lew[c]=a; } S.clear(); for(int i=0; i<n; i++)swap(V[i].st.st, V[i].st.nd); sort(V.begin(), V.end()); for(int i=n-1; i>=0; i--){ int a=V[i].st.st, b=V[i].st.nd, c=V[i].nd; //cerr<<a<<" "<<b<<" "<<c<<endl; S.insert(b); auto it=S.find(b); it++; if(it!=S.end()){ pra[c]=*it; } else pra[c]=a; } for(int i=0; i<n; i++){ //cerr<<pra[i]<<" "<<lew[i]<<endl; if(pra[i]<lew[i])ans=0; } cout<<ans; }

Compilation message (stderr)

port_facility.cpp: In function 'void dfs(int)':
port_facility.cpp:21:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int i=0; i<V.size(); i++){
      |               ~^~~~~~~~~
port_facility.cpp: In function 'int main()':
port_facility.cpp:72:7: warning: unused variable 'czy' [-Wunused-variable]
   72 |  bool czy=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...