답안 #694863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
694863 2023-02-04T10:56:20 Z US3RN4M3 Alternating Heights (CCO22_day1problem1) C++17
25 / 25
526 ms 13840 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mx = 3005;
vector<pair<int, int>> graph[mx];
int nums[mx];
int bes[mx];
char vis[mx];
int l, r, n, k, q;
bool cond;
void dfs(int cur) {
	vis[cur] = 1;
	for(auto [nxt, pos] : graph[cur]) if(l <= pos && pos < r) {
		if(vis[nxt] == 1) {
			cond = true;
			return;
		}
		if(!vis[nxt]) dfs(nxt);
		if(cond) return;
	}
	vis[cur] = 2;
}
void test() {
	r = l;
	for(int delta = 2048; delta >= 1; delta >>= 1) {
		r += delta;
		if(r >= n) {
			r -= delta;
			continue;
		}
		cond = false;
		memset(vis, 0, sizeof(vis));
		for(int i = l; i <= r; i++) {
			if(vis[nums[i]] == 0) dfs(nums[i]);
		}
		if(cond) r -= delta;
	}
	bes[l] = r;
}
main() {
	cin >> n >> k >> q;
	for(int i = 0; i < n; i++) cin >> nums[i];
	for(int i = 1; i < n; i++) {
		if(i & 1) {
			graph[nums[i]].push_back({nums[i - 1], i - 1});
		} else {
			graph[nums[i - 1]].push_back({nums[i], i - 1});
		}
	}
	for(l = 0; l < n; l++) {
		test();
	}
	for(int i = 0; i < q; i++) {
		int x, y;
		scanf("%d %d\n", &x, &y);
		if(bes[x - 1] >= y - 1) printf("YES\n");
		else printf("NO\n");
	}
}

Compilation message

Main.cpp:40:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   40 | main() {
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d %d\n", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 6348 KB Output is correct
2 Correct 242 ms 12852 KB Output is correct
3 Correct 290 ms 12816 KB Output is correct
4 Correct 183 ms 7244 KB Output is correct
5 Correct 205 ms 9224 KB Output is correct
6 Correct 249 ms 12768 KB Output is correct
7 Correct 262 ms 12704 KB Output is correct
8 Correct 256 ms 12704 KB Output is correct
9 Correct 296 ms 12868 KB Output is correct
10 Correct 289 ms 13280 KB Output is correct
11 Correct 314 ms 13804 KB Output is correct
12 Correct 295 ms 13020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 5668 KB Output is correct
2 Correct 192 ms 10960 KB Output is correct
3 Correct 223 ms 10996 KB Output is correct
4 Correct 185 ms 8244 KB Output is correct
5 Correct 236 ms 9356 KB Output is correct
6 Correct 219 ms 10912 KB Output is correct
7 Correct 230 ms 11012 KB Output is correct
8 Correct 196 ms 10984 KB Output is correct
9 Correct 217 ms 11316 KB Output is correct
10 Correct 211 ms 12040 KB Output is correct
11 Correct 212 ms 11932 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 167 ms 448 KB Output is correct
3 Correct 200 ms 564 KB Output is correct
4 Correct 38 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 149 ms 444 KB Output is correct
8 Correct 232 ms 452 KB Output is correct
9 Correct 341 ms 452 KB Output is correct
10 Correct 253 ms 452 KB Output is correct
11 Correct 257 ms 452 KB Output is correct
12 Correct 219 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 6348 KB Output is correct
2 Correct 242 ms 12852 KB Output is correct
3 Correct 290 ms 12816 KB Output is correct
4 Correct 183 ms 7244 KB Output is correct
5 Correct 205 ms 9224 KB Output is correct
6 Correct 249 ms 12768 KB Output is correct
7 Correct 262 ms 12704 KB Output is correct
8 Correct 256 ms 12704 KB Output is correct
9 Correct 296 ms 12868 KB Output is correct
10 Correct 289 ms 13280 KB Output is correct
11 Correct 314 ms 13804 KB Output is correct
12 Correct 295 ms 13020 KB Output is correct
13 Correct 214 ms 5668 KB Output is correct
14 Correct 192 ms 10960 KB Output is correct
15 Correct 223 ms 10996 KB Output is correct
16 Correct 185 ms 8244 KB Output is correct
17 Correct 236 ms 9356 KB Output is correct
18 Correct 219 ms 10912 KB Output is correct
19 Correct 230 ms 11012 KB Output is correct
20 Correct 196 ms 10984 KB Output is correct
21 Correct 217 ms 11316 KB Output is correct
22 Correct 211 ms 12040 KB Output is correct
23 Correct 212 ms 11932 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 372 KB Output is correct
26 Correct 167 ms 448 KB Output is correct
27 Correct 200 ms 564 KB Output is correct
28 Correct 38 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 149 ms 444 KB Output is correct
32 Correct 232 ms 452 KB Output is correct
33 Correct 341 ms 452 KB Output is correct
34 Correct 253 ms 452 KB Output is correct
35 Correct 257 ms 452 KB Output is correct
36 Correct 219 ms 460 KB Output is correct
37 Correct 526 ms 13404 KB Output is correct
38 Correct 402 ms 13200 KB Output is correct
39 Correct 286 ms 12884 KB Output is correct
40 Correct 183 ms 8268 KB Output is correct
41 Correct 196 ms 9748 KB Output is correct
42 Correct 367 ms 13260 KB Output is correct
43 Correct 482 ms 13700 KB Output is correct
44 Correct 460 ms 13288 KB Output is correct
45 Correct 461 ms 13840 KB Output is correct
46 Correct 469 ms 13820 KB Output is correct
47 Correct 491 ms 13700 KB Output is correct