제출 #27860

#제출 시각아이디문제언어결과실행 시간메모리
27860suhgyuho_williamPort Facility (JOI17_port_facility)C++14
0 / 100
0 ms11788 KiB
#include <bits/stdc++.h>

#define lld long long
#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define left leftt
#define right rightt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007LL

using namespace std;

int N; lld ans,inv;
struct data{
	int x,y;
}a[1000002];
bool check[2000002];

int main(){
	scanf("%d",&N); ans = 1;
	for(int i=1; i<=N; i++){
		scanf("%d %d",&a[i].x,&a[i].y);
		a[i+N].x = a[i].y; a[i+N].y = -a[i].y;
		ans *= 2; ans %= Mod;
	}
	sort(a+1,a+N*2+1,[&](data &x,data &y){
		if(x.x != y.x) return x.x < y.x;
		return x.y < y.y;
	});
{
	vector<int> t1,t2;
	for(int i=1; i<=N*2; i++){
		if(a[i].y > 0){
			if(t1.size() == 0) t1.pb(a[i].y);
			else if(t2.size() == 0) t2.pb(a[i].y);
			else if(t1.back() < t2.back() && t1.back() > a[i].y) t1.pb(a[i].y);
			else if(t2.back() < t1.back() && t2.back() > a[i].y) t2.pb(a[i].y);
			else if(t1.back() > a[i].y) t1.pb(a[i].y);
			else if(t2.back() > a[i].y) t2.pb(a[i].y);
			else{
				puts("0");
				return 0;
			}
		}else{
			if(t1.size() != 0 && t1.back() == -a[i].y) t1.pop_back();
			else t2.pop_back();
		}
	}
}
	inv = (Mod+1)/2;
	vector<pii> t1,t2;
	t1.pb({Inf,0}); t2.pb({Inf,0});
	for(int i=1; i<=N*2; i++){
		if(t1.back() < t2.back()) swap(t1,t2);
		if(a[i].y > 0){
			if(t2.back().first < a[i].y){
				check[a[i].y] = true;
				ans *= inv; ans %= Mod;
			}
			if(t1.back().first > a[i].y){
				t1.pb({a[i].y,i});
				continue;
			}
			check[a[i].y] = true;
			ans *= inv; ans %= Mod;
			while(1){
				if(t1.back().second > t2.back().second) swap(t1,t2);
				t1.push_back(t2.back());
				t2.pop_back();
				if(!check[t1.back().second]){
					check[t1.back().second] = true;
					ans *= inv; ans %= Mod;
				}
				if(t1.back().first > a[i].y){
					t1.pb({a[i].y,i});
					break;
				}
			}
		}else{
			if(t1.size() != 0 && t1.back().first == -a[i].y) t1.pop_back();
			else t2.pop_back();
		}
	}
	printf("%lld\n",ans);

	return 0;
}

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

port_facility.cpp: In function 'int main()':
port_facility.cpp:23:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N); ans = 1;
                ^
port_facility.cpp:25:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a[i].x,&a[i].y);
                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...