답안 #990873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990873 2024-05-31T16:54:34 Z Trisanu_Das Alternating Heights (CCO22_day1problem1) C++17
25 / 25
617 ms 20052 KB
#include <bits/stdc++.h>
using namespace std;

int A[201010];
int last[201010];
vector<int> adj[201010];
int vis[201010];
bool dfs(int x) {
	if (vis[x]) return !~vis[x];
	vis[x] = -1;
	for (auto v : adj[x]) if (dfs(v)) return true;
	vis[x] = 1;
	return false;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N, K;
	int Q;
	cin >> N >> K;
	cin >> Q;
	int i, j;
	for (i = 1; i <= N; i++) cin >> A[i];
	for (i = 1; i <= N; i++) {
		int l, r;
		l = i;
		r = N + 1;
		while (r - l > 1) {
			int m = l + r >> 1;
			for (j = 1; j <= K; j++) adj[j].clear(), vis[j] = 0;
			int c = 0;
			for (j = i + 1; j <= m; j++) {
				if (c) adj[A[j]].push_back(A[j - 1]);
				else adj[A[j - 1]].push_back(A[j]);
				c ^= 1;
			}
			c = 0;
			for (j = 1; j <= K; j++) if (!vis[j]) {
				if (dfs(j)) {
					c = 1;
					break;
				}
			}
			if (c) r = m;
			else l = m;
		}
		last[i] = l;
	}
	while (Q--) {
		int a, b;
		cin >> a >> b;
		if (last[a] < b) cout << "NO\n";
		else cout << "YES\n";
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:28:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |    int m = l + r >> 1;
      |            ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 18904 KB Output is correct
2 Correct 118 ms 18768 KB Output is correct
3 Correct 128 ms 18836 KB Output is correct
4 Correct 81 ms 13408 KB Output is correct
5 Correct 96 ms 15444 KB Output is correct
6 Correct 157 ms 18772 KB Output is correct
7 Correct 118 ms 18768 KB Output is correct
8 Correct 118 ms 18812 KB Output is correct
9 Correct 123 ms 19000 KB Output is correct
10 Correct 186 ms 19280 KB Output is correct
11 Correct 268 ms 19968 KB Output is correct
12 Correct 237 ms 19284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 17232 KB Output is correct
2 Correct 100 ms 17276 KB Output is correct
3 Correct 141 ms 17232 KB Output is correct
4 Correct 79 ms 14416 KB Output is correct
5 Correct 99 ms 15444 KB Output is correct
6 Correct 110 ms 17224 KB Output is correct
7 Correct 101 ms 17232 KB Output is correct
8 Correct 104 ms 17232 KB Output is correct
9 Correct 112 ms 17496 KB Output is correct
10 Correct 103 ms 18076 KB Output is correct
11 Correct 106 ms 18000 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 254 ms 6940 KB Output is correct
3 Correct 271 ms 6684 KB Output is correct
4 Correct 10 ms 6492 KB Output is correct
5 Correct 2 ms 6488 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 168 ms 6684 KB Output is correct
8 Correct 322 ms 6712 KB Output is correct
9 Correct 395 ms 6488 KB Output is correct
10 Correct 436 ms 6696 KB Output is correct
11 Correct 563 ms 6488 KB Output is correct
12 Correct 346 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 18904 KB Output is correct
2 Correct 118 ms 18768 KB Output is correct
3 Correct 128 ms 18836 KB Output is correct
4 Correct 81 ms 13408 KB Output is correct
5 Correct 96 ms 15444 KB Output is correct
6 Correct 157 ms 18772 KB Output is correct
7 Correct 118 ms 18768 KB Output is correct
8 Correct 118 ms 18812 KB Output is correct
9 Correct 123 ms 19000 KB Output is correct
10 Correct 186 ms 19280 KB Output is correct
11 Correct 268 ms 19968 KB Output is correct
12 Correct 237 ms 19284 KB Output is correct
13 Correct 103 ms 17232 KB Output is correct
14 Correct 100 ms 17276 KB Output is correct
15 Correct 141 ms 17232 KB Output is correct
16 Correct 79 ms 14416 KB Output is correct
17 Correct 99 ms 15444 KB Output is correct
18 Correct 110 ms 17224 KB Output is correct
19 Correct 101 ms 17232 KB Output is correct
20 Correct 104 ms 17232 KB Output is correct
21 Correct 112 ms 17496 KB Output is correct
22 Correct 103 ms 18076 KB Output is correct
23 Correct 106 ms 18000 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 254 ms 6940 KB Output is correct
27 Correct 271 ms 6684 KB Output is correct
28 Correct 10 ms 6492 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 168 ms 6684 KB Output is correct
32 Correct 322 ms 6712 KB Output is correct
33 Correct 395 ms 6488 KB Output is correct
34 Correct 436 ms 6696 KB Output is correct
35 Correct 563 ms 6488 KB Output is correct
36 Correct 346 ms 6488 KB Output is correct
37 Correct 409 ms 19536 KB Output is correct
38 Correct 356 ms 19504 KB Output is correct
39 Correct 127 ms 18768 KB Output is correct
40 Correct 81 ms 14412 KB Output is correct
41 Correct 100 ms 15956 KB Output is correct
42 Correct 336 ms 19504 KB Output is correct
43 Correct 446 ms 19752 KB Output is correct
44 Correct 227 ms 19540 KB Output is correct
45 Correct 617 ms 20052 KB Output is correct
46 Correct 561 ms 20020 KB Output is correct
47 Correct 602 ms 20020 KB Output is correct