답안 #550300

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
550300 2022-04-17T20:06:21 Z LucaDantas Long Mansion (JOI17_long_mansion) C++17
25 / 100
391 ms 45484 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
	int cnt = 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]], assert(++cnt <= maxn);
	}

	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]], assert(++cnt <= 2*maxn);
			while(tem(l[i], r[i], edge_sweep_r[r[i]]))
				r[i] = r[r[i]], foi = 1, assert(++cnt <= 2*maxn);
		}
	}

	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:57:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |  int q; scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
long_mansion.cpp:59:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   int x, y; scanf("%d %d", &x, &y);
      |             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12116 KB Output is correct
2 Correct 10 ms 12244 KB Output is correct
3 Correct 10 ms 12252 KB Output is correct
4 Correct 9 ms 12192 KB Output is correct
5 Correct 8 ms 12132 KB Output is correct
6 Correct 9 ms 12116 KB Output is correct
7 Correct 11 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12116 KB Output is correct
2 Correct 10 ms 12244 KB Output is correct
3 Correct 10 ms 12252 KB Output is correct
4 Correct 9 ms 12192 KB Output is correct
5 Correct 8 ms 12132 KB Output is correct
6 Correct 9 ms 12116 KB Output is correct
7 Correct 11 ms 12116 KB Output is correct
8 Correct 132 ms 17744 KB Output is correct
9 Correct 141 ms 17628 KB Output is correct
10 Correct 125 ms 17820 KB Output is correct
11 Correct 139 ms 17936 KB Output is correct
12 Correct 115 ms 17608 KB Output is correct
13 Correct 112 ms 17864 KB Output is correct
14 Correct 112 ms 17876 KB Output is correct
15 Correct 128 ms 18068 KB Output is correct
16 Correct 106 ms 17996 KB Output is correct
17 Correct 112 ms 17848 KB Output is correct
18 Correct 122 ms 17900 KB Output is correct
19 Correct 110 ms 17928 KB Output is correct
20 Correct 108 ms 18084 KB Output is correct
21 Correct 119 ms 17968 KB Output is correct
22 Correct 112 ms 17948 KB Output is correct
23 Correct 127 ms 17740 KB Output is correct
24 Correct 118 ms 17844 KB Output is correct
25 Correct 113 ms 17728 KB Output is correct
26 Correct 129 ms 17720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 233 ms 19852 KB Output is correct
2 Correct 243 ms 21268 KB Output is correct
3 Correct 201 ms 21256 KB Output is correct
4 Correct 225 ms 21476 KB Output is correct
5 Correct 225 ms 21696 KB Output is correct
6 Correct 191 ms 20680 KB Output is correct
7 Correct 166 ms 20876 KB Output is correct
8 Correct 152 ms 20832 KB Output is correct
9 Correct 198 ms 20776 KB Output is correct
10 Correct 153 ms 20944 KB Output is correct
11 Correct 155 ms 20896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12116 KB Output is correct
2 Correct 10 ms 12244 KB Output is correct
3 Correct 10 ms 12252 KB Output is correct
4 Correct 9 ms 12192 KB Output is correct
5 Correct 8 ms 12132 KB Output is correct
6 Correct 9 ms 12116 KB Output is correct
7 Correct 11 ms 12116 KB Output is correct
8 Correct 132 ms 17744 KB Output is correct
9 Correct 141 ms 17628 KB Output is correct
10 Correct 125 ms 17820 KB Output is correct
11 Correct 139 ms 17936 KB Output is correct
12 Correct 115 ms 17608 KB Output is correct
13 Correct 112 ms 17864 KB Output is correct
14 Correct 112 ms 17876 KB Output is correct
15 Correct 128 ms 18068 KB Output is correct
16 Correct 106 ms 17996 KB Output is correct
17 Correct 112 ms 17848 KB Output is correct
18 Correct 122 ms 17900 KB Output is correct
19 Correct 110 ms 17928 KB Output is correct
20 Correct 108 ms 18084 KB Output is correct
21 Correct 119 ms 17968 KB Output is correct
22 Correct 112 ms 17948 KB Output is correct
23 Correct 127 ms 17740 KB Output is correct
24 Correct 118 ms 17844 KB Output is correct
25 Correct 113 ms 17728 KB Output is correct
26 Correct 129 ms 17720 KB Output is correct
27 Correct 233 ms 19852 KB Output is correct
28 Correct 243 ms 21268 KB Output is correct
29 Correct 201 ms 21256 KB Output is correct
30 Correct 225 ms 21476 KB Output is correct
31 Correct 225 ms 21696 KB Output is correct
32 Correct 191 ms 20680 KB Output is correct
33 Correct 166 ms 20876 KB Output is correct
34 Correct 152 ms 20832 KB Output is correct
35 Correct 198 ms 20776 KB Output is correct
36 Correct 153 ms 20944 KB Output is correct
37 Correct 155 ms 20896 KB Output is correct
38 Correct 331 ms 26760 KB Output is correct
39 Correct 391 ms 28576 KB Output is correct
40 Correct 287 ms 25644 KB Output is correct
41 Runtime error 247 ms 45484 KB Execution killed with signal 6
42 Halted 0 ms 0 KB -