Submission #1099658

# Submission time Handle Problem Language Result Execution time Memory
1099658 2024-10-12T00:53:42 Z Math4Life2020 Alternating Heights (CCO22_day1problem1) C++17
25 / 25
470 ms 4696 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include <bits/stdc++.h>
using namespace std;
using ll = int; using pii = pair<ll,ll>;
const ll Nm = 3005;
ll N;
ll a[Nm];
ll ans[Nm];

bool qry(ll x, ll y) {
	ll ncount = 0;
	ll tfound[N];
	ll fleft[N];
	for (ll i=0;i<N;i++) {
		tfound[i]=-1;
	}
	vector<ll> fadj[N];
	vector<ll> radj[N];
	for (ll i=x;i<y;i++) {
		if ((i-x)%2) {
			fadj[a[i]].push_back(a[i+1]);
			radj[a[i+1]].push_back(a[i]);
		} else {
			fadj[a[i+1]].push_back(a[i]);
			radj[a[i]].push_back(a[i+1]);
		}
	}
	stack<pii> s;
	for (ll i=0;i<N;i++) {
		fleft[i]=fadj[i].size();
		if (fadj[i].size()==0) {
			s.push({i,0});
		}
	}
	while (!s.empty()) {
		pii p0 = s.top(); s.pop();
		ncount++;
		ll x = p0.first; ll t = p0.second;
		if (tfound[x]!=-1) {
			return 0;
		}
		tfound[x]=t;
		for (ll y: radj[x]) {
			fleft[y]--;
			if (fleft[y]==0) {
				s.push({y,t+1});
			}
		}
	}
	if (ncount!=N) {
		return 0;
	}
	return 1;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll K,Q; cin >> N >> K >> Q;
	for (ll i=0;i<N;i++) {
		cin >> a[i]; a[i]--;
	}
	ll j=N-1;
	for (ll i=(N-1);i>=0;i--) {
		while (j>0) {
			if (qry(j-1,i)) {
				j--;
			} else {
				break;
			}
		}
		ans[i]=j;
	}
	for (ll q=0;q<Q;q++) {
		ll x,y; cin >> x >> y;
		x--; y--;
		if (x>=ans[y]) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 236 ms 3668 KB Output is correct
2 Correct 234 ms 3668 KB Output is correct
3 Correct 245 ms 3476 KB Output is correct
4 Correct 84 ms 3408 KB Output is correct
5 Correct 98 ms 3364 KB Output is correct
6 Correct 240 ms 3472 KB Output is correct
7 Correct 231 ms 3668 KB Output is correct
8 Correct 247 ms 3456 KB Output is correct
9 Correct 230 ms 3664 KB Output is correct
10 Correct 255 ms 3980 KB Output is correct
11 Correct 181 ms 4692 KB Output is correct
12 Correct 257 ms 4504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 3396 KB Output is correct
2 Correct 106 ms 3408 KB Output is correct
3 Correct 103 ms 3412 KB Output is correct
4 Correct 80 ms 4436 KB Output is correct
5 Correct 103 ms 3672 KB Output is correct
6 Correct 103 ms 3396 KB Output is correct
7 Correct 116 ms 3412 KB Output is correct
8 Correct 112 ms 3408 KB Output is correct
9 Correct 109 ms 3700 KB Output is correct
10 Correct 100 ms 4352 KB Output is correct
11 Correct 104 ms 4488 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 240 ms 664 KB Output is correct
3 Correct 227 ms 600 KB Output is correct
4 Correct 125 ms 600 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 234 ms 676 KB Output is correct
8 Correct 289 ms 604 KB Output is correct
9 Correct 293 ms 668 KB Output is correct
10 Correct 378 ms 604 KB Output is correct
11 Correct 294 ms 664 KB Output is correct
12 Correct 440 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 236 ms 3668 KB Output is correct
2 Correct 234 ms 3668 KB Output is correct
3 Correct 245 ms 3476 KB Output is correct
4 Correct 84 ms 3408 KB Output is correct
5 Correct 98 ms 3364 KB Output is correct
6 Correct 240 ms 3472 KB Output is correct
7 Correct 231 ms 3668 KB Output is correct
8 Correct 247 ms 3456 KB Output is correct
9 Correct 230 ms 3664 KB Output is correct
10 Correct 255 ms 3980 KB Output is correct
11 Correct 181 ms 4692 KB Output is correct
12 Correct 257 ms 4504 KB Output is correct
13 Correct 104 ms 3396 KB Output is correct
14 Correct 106 ms 3408 KB Output is correct
15 Correct 103 ms 3412 KB Output is correct
16 Correct 80 ms 4436 KB Output is correct
17 Correct 103 ms 3672 KB Output is correct
18 Correct 103 ms 3396 KB Output is correct
19 Correct 116 ms 3412 KB Output is correct
20 Correct 112 ms 3408 KB Output is correct
21 Correct 109 ms 3700 KB Output is correct
22 Correct 100 ms 4352 KB Output is correct
23 Correct 104 ms 4488 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 240 ms 664 KB Output is correct
27 Correct 227 ms 600 KB Output is correct
28 Correct 125 ms 600 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 234 ms 676 KB Output is correct
32 Correct 289 ms 604 KB Output is correct
33 Correct 293 ms 668 KB Output is correct
34 Correct 378 ms 604 KB Output is correct
35 Correct 294 ms 664 KB Output is correct
36 Correct 440 ms 600 KB Output is correct
37 Correct 404 ms 4176 KB Output is correct
38 Correct 349 ms 3984 KB Output is correct
39 Correct 230 ms 3468 KB Output is correct
40 Correct 80 ms 4308 KB Output is correct
41 Correct 97 ms 3920 KB Output is correct
42 Correct 357 ms 4180 KB Output is correct
43 Correct 470 ms 4508 KB Output is correct
44 Correct 366 ms 4176 KB Output is correct
45 Correct 398 ms 4588 KB Output is correct
46 Correct 452 ms 4500 KB Output is correct
47 Correct 389 ms 4696 KB Output is correct