Submission #490874

# Submission time Handle Problem Language Result Execution time Memory
490874 2021-11-29T14:59:34 Z ntabc05101 Long Mansion (JOI17_long_mansion) C++14
0 / 100
3000 ms 8236 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 >= 0; 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 >= 0 && (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]; x = l[i] - 1;
			}
			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:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   57 |    if (x >= 0 && (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);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3078 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3078 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3088 ms 8236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3078 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -