Submission #698397

# Submission time Handle Problem Language Result Execution time Memory
698397 2023-02-13T10:59:03 Z penguin133 Alternating Heights (CCO22_day1problem1) C++17
25 / 25
416 ms 13900 KB
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, k, q;
int A[3005], lft[3005];
int vis[3005], vis2[3005], cyc = 0, lp = 0;
vector <pi> v[3005];
void dfs(int x){
	if(vis2[x]){
		cyc = 1;
		return;
	}
	else if(vis[x])return;
	vis[x] = vis2[x] = 1;
	for(auto [i, j] : v[x])if(j > lp)dfs(i);
	vis2[x] = 0;
}

bool hello(){
	for(int i=1;i<=k;i++)vis[i] = 0;
	cyc=  0;
	for(int i=1;i<=k;i++)if(!vis[i])dfs(i);
	return cyc;
}
void solve(){
	cin >> n >> k >> q;
	for(int i=1;i<=n;i++)cin >> A[i];
	lft[1] = 1;
	lp = 1;
	for(int i=2;i<=n;i++){
		lft[i] = i;
		if(i%2 == 0)v[A[i-1]].push_back({A[i], i});
		else v[A[i]].push_back({A[i-1], i});
		while(hello())lp++;
		lft[i] = min(lft[i], lp);
	}
	lp = 1;
	for(int i=1;i<=k;i++)v[i].clear();
	for(int i=2;i<=n;i++){
		if(i%2)v[A[i-1]].push_back({A[i], i});
		else v[A[i]].push_back({A[i-1], i});
		while(hello())lp++;
		lft[i] = min(lft[i], lp);
	}
	while(q--){
		int l, r; cin >> l >> r;
		cout << (lft[r] <= l ? "YES\n" : "NO\n");
	}
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

Main.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 160 ms 3932 KB Output is correct
2 Correct 174 ms 3988 KB Output is correct
3 Correct 161 ms 3920 KB Output is correct
4 Correct 113 ms 3892 KB Output is correct
5 Correct 124 ms 4004 KB Output is correct
6 Correct 182 ms 3992 KB Output is correct
7 Correct 167 ms 3980 KB Output is correct
8 Correct 180 ms 3916 KB Output is correct
9 Correct 163 ms 4044 KB Output is correct
10 Correct 178 ms 4456 KB Output is correct
11 Correct 164 ms 5032 KB Output is correct
12 Correct 193 ms 4928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 3944 KB Output is correct
2 Correct 136 ms 3668 KB Output is correct
3 Correct 134 ms 3640 KB Output is correct
4 Correct 113 ms 4664 KB Output is correct
5 Correct 125 ms 3812 KB Output is correct
6 Correct 138 ms 3624 KB Output is correct
7 Correct 136 ms 3720 KB Output is correct
8 Correct 141 ms 3748 KB Output is correct
9 Correct 146 ms 4088 KB Output is correct
10 Correct 137 ms 4664 KB Output is correct
11 Correct 135 ms 4668 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 392 KB Output is correct
2 Correct 258 ms 520 KB Output is correct
3 Correct 244 ms 476 KB Output is correct
4 Correct 14 ms 468 KB Output is correct
5 Correct 1 ms 396 KB Output is correct
6 Correct 1 ms 408 KB Output is correct
7 Correct 159 ms 476 KB Output is correct
8 Correct 206 ms 604 KB Output is correct
9 Correct 222 ms 608 KB Output is correct
10 Correct 110 ms 492 KB Output is correct
11 Correct 148 ms 468 KB Output is correct
12 Correct 97 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 3932 KB Output is correct
2 Correct 174 ms 3988 KB Output is correct
3 Correct 161 ms 3920 KB Output is correct
4 Correct 113 ms 3892 KB Output is correct
5 Correct 124 ms 4004 KB Output is correct
6 Correct 182 ms 3992 KB Output is correct
7 Correct 167 ms 3980 KB Output is correct
8 Correct 180 ms 3916 KB Output is correct
9 Correct 163 ms 4044 KB Output is correct
10 Correct 178 ms 4456 KB Output is correct
11 Correct 164 ms 5032 KB Output is correct
12 Correct 193 ms 4928 KB Output is correct
13 Correct 157 ms 3944 KB Output is correct
14 Correct 136 ms 3668 KB Output is correct
15 Correct 134 ms 3640 KB Output is correct
16 Correct 113 ms 4664 KB Output is correct
17 Correct 125 ms 3812 KB Output is correct
18 Correct 138 ms 3624 KB Output is correct
19 Correct 136 ms 3720 KB Output is correct
20 Correct 141 ms 3748 KB Output is correct
21 Correct 146 ms 4088 KB Output is correct
22 Correct 137 ms 4664 KB Output is correct
23 Correct 135 ms 4668 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 392 KB Output is correct
26 Correct 258 ms 520 KB Output is correct
27 Correct 244 ms 476 KB Output is correct
28 Correct 14 ms 468 KB Output is correct
29 Correct 1 ms 396 KB Output is correct
30 Correct 1 ms 408 KB Output is correct
31 Correct 159 ms 476 KB Output is correct
32 Correct 206 ms 604 KB Output is correct
33 Correct 222 ms 608 KB Output is correct
34 Correct 110 ms 492 KB Output is correct
35 Correct 148 ms 468 KB Output is correct
36 Correct 97 ms 488 KB Output is correct
37 Correct 378 ms 4280 KB Output is correct
38 Correct 416 ms 4256 KB Output is correct
39 Correct 157 ms 3664 KB Output is correct
40 Correct 110 ms 4648 KB Output is correct
41 Correct 130 ms 4216 KB Output is correct
42 Correct 342 ms 4212 KB Output is correct
43 Correct 298 ms 4532 KB Output is correct
44 Correct 237 ms 4392 KB Output is correct
45 Correct 281 ms 7500 KB Output is correct
46 Correct 266 ms 13900 KB Output is correct
47 Correct 287 ms 13872 KB Output is correct