This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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], tab2[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){
while(tab[l].size()){
int u=tab[l].back();
//cout<<v<<" "<<u<<"\n";
if(seg[u].nd>seg[v].nd)break;
if(!vis[u]){
vis[u]=1;
V.push_back(u);
}
tab[l].pop_back();
}
l/=2;
}
while(r){
while(tab2[r].size()){
int u=tab2[r].back();
//cout<<v<<" + "<<u<<"\n";
if(seg[u].st<seg[v].st)break;
if(!vis[u]){
vis[u]=1;
V.push_back(u);
}
tab2[r].pop_back();
}
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);
}
for(int i=1; i<N+N; i++){
sort(tab[i].begin(), tab[i].end(), [](int a, int b){return seg[a].nd>seg[b].nd;});
tab2[i]=tab[i];
sort(tab2[i].begin(), tab2[i].end(), [](int a, int b){return seg[a].st<seg[b].st;});
//cout<<i<<"a\n";
//for(int j:tab[i])cout<<j<<" ";
//cout<<"\n";
}
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=i;
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:86:7: warning: unused variable 'czy' [-Wunused-variable]
86 | bool czy=1;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |