답안 #27774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27774 2017-07-14T05:12:14 Z 큐브러버(#1177) Cultivation (JOI17_cultivation) C++14
0 / 100
0 ms 33188 KB
#include <cstdio>
#include <cassert>
#include <unordered_set>

using namespace std;

unordered_set<long long> S;

int L[1000001], R[1000001];
int a[2000002];
unsigned long long d[1000001];

int s1[1000001], s2[1000001], s1n, s2n;

unsigned int rnd() {
	static unsigned int x = 1983526071;
	return x = x * 1664525 + 1013904223;
}

int main() {
	unsigned long long t;
	int i, j, k, n, r = 1;
	assert(scanf("%d", &n) == 1);
	assert(1 <= n && n <= 1000000);
	for (i = 1; i <= n; i++) {
		assert(scanf("%d%d", &L[i], &R[i]) == 2);
		assert(1 <= L[i] && L[i] < R[i] && R[i] <= n + n);
		a[L[i]] = i;
		a[R[i]] = -i;
		d[i] = (unsigned long long)rnd() << 32 | rnd();
	}
	s1[s1n] = s2[s2n] = 1e9;
	t = 0;
	S.insert(0);
	for (i = 1; i <= n + n; i++) {
		if (a[i] > 0) {
			t ^= d[a[i]];
			if (s1[s1n] > R[a[i]] && (s1[s1n] < s2[s2n] || s2[s2n] < R[a[i]])) s1[++s1n] = R[a[i]];
			else if (s2[s2n] > R[a[i]]) s2[++s2n] = R[a[i]];
			else {
				puts("0");
				return 0;
			}
		}
		else {
			t ^= d[-a[i]];
			if (s1[s1n] == i) s1n--;
			else s2n--;
		}
		if (S.find(t) != S.end()) r = r * 2 % 1000000007;
		else S.insert(t);
	}
	printf("%d\n", r);
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:22:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, k, n, r = 1;
         ^
cultivation.cpp:22:12: warning: unused variable 'k' [-Wunused-variable]
  int i, j, k, n, r = 1;
            ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 33188 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 33188 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 33188 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 33188 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 33188 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 33188 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -