답안 #490869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490869 2021-11-29T14:49:58 Z ntabc05101 Long Mansion (JOI17_long_mansion) C++14
0 / 100
3000 ms 10060 KB
#include<bits/stdc++.h>
using namespace std;

#define taskname ""

int main() {
	if (fopen(taskname".inp", "r")) {
		freopen(taskname".inp", "r", stdin);
		freopen(taskname".out", "w", stdout);
	}
	else {
		if (fopen(taskname".in", "r")) {
			freopen(taskname".in", "r", stdin);
			freopen(taskname".out", "w", stdout);
		}
	}

	cin.tie(0)->sync_with_stdio(0);

	int n; cin >> n;
	int c[n - 1];
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i]; c[i]--;
	}

	vector<int> a[n];
	for (int i = 0, b; i < n; i++) {
		cin >> b; a[i].resize(b);
		for (auto &x: a[i]) {
			cin >> x; x--;
		}
	}

	int pos[n];
	memset(pos, -1, sizeof(pos));
	int lo[n - 1], hi[n - 1];
	for (int i = 0; i < n - 1; i++) {
		for (auto &x: a[i]) {
			pos[x] = i;
		}
		lo[i] = pos[c[i]];
	}
	memset(pos, -1, sizeof(pos));
	for (int i = n - 2; ~i; i--) {
		for (auto &x: a[i + 1]) {
			pos[x] = i + 1;
		}
		hi[i] = pos[c[i]];
	}

	int l[n], r[n];

	for (int i = 0, x, y; i < n; i++) {
		l[i] = r[i] = i;
		while (1) {
			x = l[i] - 1;
			if ((~x) && (hi[x] >= l[i] && hi[x] <= r[i]) || (hi[x] >= l[i] && hi[x] <= r[i])) {
				r[i] = max(r[i], r[x]);
				l[i] = l[x];
			}
			else {
				if (r[i] < n - 1 && (hi[r[i]] >= l[i] && hi[r[i]] <= r[i]) || (lo[r[i]] >= l[i] && lo[r[i]] <= r[i])) {
					r[i]++;
				}
				else {
					break;
				}
			}
		}
	}

	int q; cin >> q;
	while (q--) {
		int x, y; cin >> x >> y;
		x--; y--;
		 cout << (y >= l[x] && y <= r[x] ? "YES": "NO") << "\n";
	 }

	return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:57:13: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   57 |    if ((~x) && (hi[x] >= l[i] && hi[x] <= r[i]) || (hi[x] >= l[i] && hi[x] <= r[i])) {
      |        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:62:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   62 |     if (r[i] < n - 1 && (hi[r[i]] >= l[i] && hi[r[i]] <= r[i]) || (lo[r[i]] >= l[i] && lo[r[i]] <= r[i])) {
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:53:21: warning: unused variable 'y' [-Wunused-variable]
   53 |  for (int i = 0, x, y; i < n; i++) {
      |                     ^
long_mansion.cpp:8:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:9:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   freopen(taskname".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:13:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |    freopen(taskname".in", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:14:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |    freopen(taskname".out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3071 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3071 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3061 ms 10060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3071 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -