제출 #892799

#제출 시각아이디문제언어결과실행 시간메모리
892799ReLicePort Facility (JOI17_port_facility)C++17
100 / 100
3557 ms304148 KiB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define bc back()
#define ar array
#define vll vector<ll> 
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;*/
template <class _T>
bool chmin(_T &x, const _T &y){
    if(x>y){
        x=y;
        return true;
    }
    return false;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag=false;
    if (x<y){
        x=y;flag|=true;
    }
    return flag;
}
//#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=2e18+7;
const ll mod=1e9+7;
const ll N=2e6+7;
struct st{
	ll t[N*4];
	st(){
		for(ll i=0;i<N*4;i++)t[i]=-inf;
	}
	void upd(ll pos,ll val,ll v=1,ll tl=1,ll tr=N){
		if(tl>pos || tr<pos)return;
		if(tl==tr){
			t[v]=val;
			return;
		}
		ll tm=(tl+tr)/2;
		upd(pos,val,v*2,tl,tm);
		upd(pos,val,v*2+1,tm+1,tr);
		t[v]=max(t[v*2],t[v*2+1]);
	}
	ll get(ll l,ll r,ll v=1,ll tl=1,ll tr=N){
		if(tl>r || tr<l)return -inf;
		if(l<=tl && tr<=r)return t[v];
		ll tm=(tl+tr)/2;
		return max(get(l,r,v*2,tl,tm),get(l,r,v*2+1,tm+1,tr));
	}
}mx,mn;
ll vis[N];
ll id[N];
ll a[N],b[N];
ll type[N];
vll vt[2];
void dfs(ll v){
	vis[v]++;
	mx.upd(a[v],-inf);
	mn.upd(b[v],-inf);
	vt[type[v]].pb(v);
	while(true){
		ll i=mx.get(a[v],b[v]);
		if(b[v]<i){
			type[id[i]]=type[v]^1;
			dfs(id[i]);
			continue;
		}
		ll j=-mn.get(a[v],b[v]);
		if(a[v]>j){
			type[id[j]]=type[v]^1;
			dfs(id[j]);
			continue;
		}
		break;
	}
}
bool check(vll v){
	for(auto i : v){
		mn.upd(b[i],-a[i]);
		mx.upd(a[i],b[i]);
	}
	for(auto i : v){
		ll x=mx.get(a[i],b[i]);
		if(x>b[i])return true;
		x=-mn.get(a[i],b[i]);
		if(a[i]>x)return true;
	}
	for(auto i : v){
		mn.upd(b[i],-inf);
		mx.upd(a[i],-inf);
	}
	return false;
}
void solve(){
	ll i;
	ll n;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		mx.upd(a[i],b[i]);
		mn.upd(b[i],-a[i]);
		id[a[i]]=i;
		id[b[i]]=i;
	}
	ll ans=1;
	for(i=1;i<=n;i++){
		if(vis[i])continue;
		vt[0].clear();
		vt[1].clear();
		dfs(i);
		if(check(vt[1]) || check(vt[0])){
			cout<<0<<endl;
			return;
		}
		ans*=2;
		ans%=mod;
	}
	cout<<ans<<endl;
}
signed main(){
	//start();
    ll t=1;
	//cin>>t;
    while(t--) solve();
    return 0;
}
/*
35
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
31 32
33 34
35 36
37 38
39 40
41 42
43 44
45 46
47 48
49 50
51 52
53 54
55 56
57 58
59 60
61 62
63 64
65 66
67 68
69 70






*/

컴파일 시 표준 에러 (stderr) 메시지

port_facility.cpp: In function 'void fre(std::string)':
port_facility.cpp:42:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
port_facility.cpp:42:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...