Submission #1099656

# Submission time Handle Problem Language Result Execution time Memory
1099656 2024-10-12T00:52:04 Z Math4Life2020 Alternating Heights (CCO22_day1problem1) C++17
25 / 25
581 ms 14116 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 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 334 ms 12880 KB Output is correct
2 Correct 346 ms 13016 KB Output is correct
3 Correct 338 ms 12880 KB Output is correct
4 Correct 82 ms 7252 KB Output is correct
5 Correct 94 ms 9300 KB Output is correct
6 Correct 341 ms 12880 KB Output is correct
7 Correct 336 ms 12880 KB Output is correct
8 Correct 339 ms 13140 KB Output is correct
9 Correct 343 ms 13392 KB Output is correct
10 Correct 361 ms 13540 KB Output is correct
11 Correct 243 ms 14056 KB Output is correct
12 Correct 374 ms 13396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 11344 KB Output is correct
2 Correct 106 ms 11092 KB Output is correct
3 Correct 109 ms 11092 KB Output is correct
4 Correct 83 ms 8276 KB Output is correct
5 Correct 96 ms 9296 KB Output is correct
6 Correct 120 ms 11052 KB Output is correct
7 Correct 109 ms 11096 KB Output is correct
8 Correct 110 ms 11088 KB Output is correct
9 Correct 115 ms 11344 KB Output is correct
10 Correct 99 ms 11932 KB Output is correct
11 Correct 100 ms 12024 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 348 ms 748 KB Output is correct
3 Correct 317 ms 600 KB Output is correct
4 Correct 233 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 322 ms 760 KB Output is correct
8 Correct 372 ms 600 KB Output is correct
9 Correct 390 ms 600 KB Output is correct
10 Correct 436 ms 600 KB Output is correct
11 Correct 343 ms 604 KB Output is correct
12 Correct 549 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 334 ms 12880 KB Output is correct
2 Correct 346 ms 13016 KB Output is correct
3 Correct 338 ms 12880 KB Output is correct
4 Correct 82 ms 7252 KB Output is correct
5 Correct 94 ms 9300 KB Output is correct
6 Correct 341 ms 12880 KB Output is correct
7 Correct 336 ms 12880 KB Output is correct
8 Correct 339 ms 13140 KB Output is correct
9 Correct 343 ms 13392 KB Output is correct
10 Correct 361 ms 13540 KB Output is correct
11 Correct 243 ms 14056 KB Output is correct
12 Correct 374 ms 13396 KB Output is correct
13 Correct 110 ms 11344 KB Output is correct
14 Correct 106 ms 11092 KB Output is correct
15 Correct 109 ms 11092 KB Output is correct
16 Correct 83 ms 8276 KB Output is correct
17 Correct 96 ms 9296 KB Output is correct
18 Correct 120 ms 11052 KB Output is correct
19 Correct 109 ms 11096 KB Output is correct
20 Correct 110 ms 11088 KB Output is correct
21 Correct 115 ms 11344 KB Output is correct
22 Correct 99 ms 11932 KB Output is correct
23 Correct 100 ms 12024 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 348 ms 748 KB Output is correct
27 Correct 317 ms 600 KB Output is correct
28 Correct 233 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 322 ms 760 KB Output is correct
32 Correct 372 ms 600 KB Output is correct
33 Correct 390 ms 600 KB Output is correct
34 Correct 436 ms 600 KB Output is correct
35 Correct 343 ms 604 KB Output is correct
36 Correct 549 ms 852 KB Output is correct
37 Correct 485 ms 13568 KB Output is correct
38 Correct 457 ms 13396 KB Output is correct
39 Correct 333 ms 12884 KB Output is correct
40 Correct 79 ms 8272 KB Output is correct
41 Correct 98 ms 9756 KB Output is correct
42 Correct 463 ms 13592 KB Output is correct
43 Correct 581 ms 13836 KB Output is correct
44 Correct 479 ms 13652 KB Output is correct
45 Correct 453 ms 14116 KB Output is correct
46 Correct 525 ms 14116 KB Output is correct
47 Correct 471 ms 14080 KB Output is correct