Submission #550297

# Submission time Handle Problem Language Result Execution time Memory
550297 2022-04-17T20:00:31 Z LucaDantas Long Mansion (JOI17_long_mansion) C++17
25 / 100
3000 ms 35828 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 5e5+10;

int l[maxn], r[maxn];

int edge_sweep_l[maxn], edge_sweep_r[maxn];

vector<int> keys[maxn];

bool tem(int x, int y, int cor) {
	// return 1 if there is some element with color 'cor' inside the open interval ]x, y[
	auto it = upper_bound(keys[cor].begin(), keys[cor].end(), x);
	return it != keys[cor].end() && *it < y;
}

int main() {
	int n; scanf("%d", &n);

	for(int i = 1; i < n; i++) {
		int c; scanf("%d", &c);
		edge_sweep_l[i] = edge_sweep_r[i+1] = c;
	}

	for(int i = 1; i <= n; i++) {
		int a, b; scanf("%d", &b);
		while(b--) {
			scanf("%d", &a);
			keys[a].push_back(i);
		}
	}

	// for(i = {0, n-1}) -> defino l[i]
	// for(i = {n-1, 0}) -> defino r[i] usando l[i], e também redefino l[i] overextending it
	
	l[1] = 0, r[n] = n+1; // the color of the edges are defined from [1, n] so we'll never be able to open c[0] and c[n+1] since they're 0
	for(int i = 1; i <= n; i++) {
		l[i] = i-1;
		while(tem(l[i], i+1, edge_sweep_l[l[i]]))
			l[i] = l[l[i]];
	}

	for(int i = n; i >= 1; i--) {
		r[i] = i+1;
		bool foi = 1;
		while(foi) {
			foi = 0;
			while(tem(l[i], r[i], edge_sweep_l[l[i]]))
				l[i] = l[l[i]];
			while(tem(l[i], r[i], edge_sweep_r[r[i]]))
				r[i] = r[r[i]], foi = 1;
		}
	}

	int q; scanf("%d", &q);
	while(q--) {
		int x, y; scanf("%d %d", &x, &y);
		puts(y > l[x] && y < r[x] ? "YES" : "NO");
	}
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
long_mansion.cpp:22:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   int c; scanf("%d", &c);
      |          ~~~~~^~~~~~~~~~
long_mansion.cpp:27:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   int a, b; scanf("%d", &b);
      |             ~~~~~^~~~~~~~~~
long_mansion.cpp:29:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |    scanf("%d", &a);
      |    ~~~~~^~~~~~~~~~
long_mansion.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |  int q; scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
long_mansion.cpp:58:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   int x, y; scanf("%d %d", &x, &y);
      |             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12116 KB Output is correct
2 Correct 14 ms 12244 KB Output is correct
3 Correct 10 ms 12196 KB Output is correct
4 Correct 9 ms 12116 KB Output is correct
5 Correct 8 ms 12152 KB Output is correct
6 Correct 10 ms 12236 KB Output is correct
7 Correct 9 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12116 KB Output is correct
2 Correct 14 ms 12244 KB Output is correct
3 Correct 10 ms 12196 KB Output is correct
4 Correct 9 ms 12116 KB Output is correct
5 Correct 8 ms 12152 KB Output is correct
6 Correct 10 ms 12236 KB Output is correct
7 Correct 9 ms 12244 KB Output is correct
8 Correct 122 ms 17996 KB Output is correct
9 Correct 128 ms 18012 KB Output is correct
10 Correct 120 ms 18292 KB Output is correct
11 Correct 152 ms 18628 KB Output is correct
12 Correct 121 ms 17592 KB Output is correct
13 Correct 118 ms 18188 KB Output is correct
14 Correct 120 ms 18140 KB Output is correct
15 Correct 123 ms 18148 KB Output is correct
16 Correct 106 ms 18008 KB Output is correct
17 Correct 122 ms 18188 KB Output is correct
18 Correct 120 ms 18272 KB Output is correct
19 Correct 132 ms 18228 KB Output is correct
20 Correct 113 ms 18124 KB Output is correct
21 Correct 105 ms 18024 KB Output is correct
22 Correct 113 ms 18132 KB Output is correct
23 Correct 122 ms 17928 KB Output is correct
24 Correct 134 ms 17992 KB Output is correct
25 Correct 120 ms 18000 KB Output is correct
26 Correct 127 ms 18036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 237 ms 24896 KB Output is correct
2 Correct 240 ms 24388 KB Output is correct
3 Correct 222 ms 24232 KB Output is correct
4 Correct 247 ms 24656 KB Output is correct
5 Correct 228 ms 24896 KB Output is correct
6 Correct 189 ms 23132 KB Output is correct
7 Correct 183 ms 22868 KB Output is correct
8 Correct 168 ms 22736 KB Output is correct
9 Correct 172 ms 22808 KB Output is correct
10 Correct 157 ms 22788 KB Output is correct
11 Correct 161 ms 22764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12116 KB Output is correct
2 Correct 14 ms 12244 KB Output is correct
3 Correct 10 ms 12196 KB Output is correct
4 Correct 9 ms 12116 KB Output is correct
5 Correct 8 ms 12152 KB Output is correct
6 Correct 10 ms 12236 KB Output is correct
7 Correct 9 ms 12244 KB Output is correct
8 Correct 122 ms 17996 KB Output is correct
9 Correct 128 ms 18012 KB Output is correct
10 Correct 120 ms 18292 KB Output is correct
11 Correct 152 ms 18628 KB Output is correct
12 Correct 121 ms 17592 KB Output is correct
13 Correct 118 ms 18188 KB Output is correct
14 Correct 120 ms 18140 KB Output is correct
15 Correct 123 ms 18148 KB Output is correct
16 Correct 106 ms 18008 KB Output is correct
17 Correct 122 ms 18188 KB Output is correct
18 Correct 120 ms 18272 KB Output is correct
19 Correct 132 ms 18228 KB Output is correct
20 Correct 113 ms 18124 KB Output is correct
21 Correct 105 ms 18024 KB Output is correct
22 Correct 113 ms 18132 KB Output is correct
23 Correct 122 ms 17928 KB Output is correct
24 Correct 134 ms 17992 KB Output is correct
25 Correct 120 ms 18000 KB Output is correct
26 Correct 127 ms 18036 KB Output is correct
27 Correct 237 ms 24896 KB Output is correct
28 Correct 240 ms 24388 KB Output is correct
29 Correct 222 ms 24232 KB Output is correct
30 Correct 247 ms 24656 KB Output is correct
31 Correct 228 ms 24896 KB Output is correct
32 Correct 189 ms 23132 KB Output is correct
33 Correct 183 ms 22868 KB Output is correct
34 Correct 168 ms 22736 KB Output is correct
35 Correct 172 ms 22808 KB Output is correct
36 Correct 157 ms 22788 KB Output is correct
37 Correct 161 ms 22764 KB Output is correct
38 Correct 318 ms 34512 KB Output is correct
39 Correct 354 ms 35828 KB Output is correct
40 Correct 291 ms 31992 KB Output is correct
41 Correct 403 ms 33304 KB Output is correct
42 Correct 196 ms 24524 KB Output is correct
43 Correct 193 ms 24280 KB Output is correct
44 Correct 283 ms 30444 KB Output is correct
45 Correct 268 ms 30692 KB Output is correct
46 Correct 275 ms 31052 KB Output is correct
47 Correct 217 ms 24708 KB Output is correct
48 Correct 180 ms 24064 KB Output is correct
49 Correct 265 ms 29916 KB Output is correct
50 Correct 285 ms 30512 KB Output is correct
51 Correct 305 ms 31548 KB Output is correct
52 Execution timed out 3042 ms 24036 KB Time limit exceeded
53 Halted 0 ms 0 KB -