# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1225860 | _rain_ | Port Facility (JOI17_port_facility) | C++20 | 50 ms | 44616 KiB |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD=1e9+7;
const int N=(int)5e5;
int mul(int a,int b){
return (LL)a*b%MOD;
}
int n;
pair<int,int>p[N+2];
namespace subtask1{
bool check(){
return n<=2000;
}
bool intersec(pair<int,int>x,pair<int,int>y){
if (x.second<y.first || y.second<x.first) return false;
if (x.first<=y.first && y.second<=x.second) return false;
if (y.first<=x.first && x.second<=y.second) return false;
return true;
}
vector<int>ke[N+2];
vector<int>order;
bool vis[N+2]={};
void dfs(int u){
vis[u]=true;
order.push_back(u);
for(auto&v:ke[u]){
if (vis[v]==false) {
dfs(v);
}
}
return;
}
bool process(){
vector<pair<int,int>>a[2];
for(auto&x:order){
// case 1
if (a[1].size()==0) a[1].push_back(p[x]);
else {
bool can=false;
for(auto&e:a[1]) can|=intersec(p[x],e);
if (can){
for(auto&e:a[0]) if (intersec(p[x],e)) return false;
a[0].push_back(p[x]);
}
else a[1].push_back(p[x]);
}
}
return true;
}
void main_code(){
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
if (intersec(p[i],p[j])) {
ke[i].push_back(j);
ke[j].push_back(i);
}
}
}
int ans=1;
for(int i=1;i<=n;++i){
if (vis[i]==false){
order.clear();
dfs(i);
if (process()==false){
cout<<0;
return;
}
ans=mul(ans,2);
}
}
cout<<ans;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0) ; cout.tie(0);
#define task "main"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin>>n;
for(int i=1;i<=n;++i) cin>>p[i].first>>p[i].second;
if (subtask1::check()) {
return subtask1::main_code(),0;
}
return 0;
}
Compilation message (stderr)
# | 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... |