#include <bits/stdc++.h>
using namespace std;
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 3e5+10, MOD = 1e9+7;
bool has_cycle(vector<vector<int>>& adj) {
int n = sz(adj);
vector<int> deg(n);
for (int a = 0; a < n; a++)
for (int b : adj[a])
deg[b]++;
vector<int> q; q.reserve(n);
for (int i = 0; i < n; i++) if (deg[i] == 0) q.push_back(i);
for (int rep = 0; rep < sz(q); rep++) {
int c = q[rep];
for (auto nxt : adj[c]) {
deg[nxt]--;
if (deg[nxt] == 0)
q.push_back(nxt);
}
}
return sz(q) < n;
}
void solve() {
int n, k, q; cin >> n >> k >> q;
vector<int> a(n); for (auto& x : a) cin >> x, --x;
vector<int> can(n);
for (int rep : {0, 1}) {
for (int l = rep, r = l; l < n; l += 2) {
while (r < n) {
vector<vector<int>> adj(k);
for (int i = l; i < r; i++) {
if (i % 2 == l % 2) adj[a[i]].push_back(a[i + 1]);
else adj[a[i + 1]].push_back(a[i]);
}
if (has_cycle(adj)) break;
r++;
}
can[l] = r;
}
}
while (q--) {
int l, r; cin >> l >> r, --l, --r;
if (can[l] <= r) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
12628 KB |
Output is correct |
2 |
Correct |
153 ms |
12620 KB |
Output is correct |
3 |
Correct |
149 ms |
12620 KB |
Output is correct |
4 |
Correct |
112 ms |
7192 KB |
Output is correct |
5 |
Correct |
127 ms |
9280 KB |
Output is correct |
6 |
Correct |
153 ms |
12660 KB |
Output is correct |
7 |
Correct |
154 ms |
12620 KB |
Output is correct |
8 |
Correct |
153 ms |
12616 KB |
Output is correct |
9 |
Correct |
166 ms |
12800 KB |
Output is correct |
10 |
Correct |
232 ms |
13108 KB |
Output is correct |
11 |
Correct |
290 ms |
13712 KB |
Output is correct |
12 |
Correct |
321 ms |
13068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
10956 KB |
Output is correct |
2 |
Correct |
137 ms |
10948 KB |
Output is correct |
3 |
Correct |
136 ms |
10880 KB |
Output is correct |
4 |
Correct |
118 ms |
8224 KB |
Output is correct |
5 |
Correct |
125 ms |
9276 KB |
Output is correct |
6 |
Correct |
134 ms |
10924 KB |
Output is correct |
7 |
Correct |
137 ms |
10952 KB |
Output is correct |
8 |
Correct |
142 ms |
10964 KB |
Output is correct |
9 |
Correct |
149 ms |
11356 KB |
Output is correct |
10 |
Correct |
143 ms |
11860 KB |
Output is correct |
11 |
Correct |
139 ms |
11896 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
415 ms |
460 KB |
Output is correct |
3 |
Correct |
483 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
329 ms |
332 KB |
Output is correct |
8 |
Correct |
542 ms |
588 KB |
Output is correct |
9 |
Correct |
720 ms |
592 KB |
Output is correct |
10 |
Correct |
562 ms |
556 KB |
Output is correct |
11 |
Correct |
630 ms |
488 KB |
Output is correct |
12 |
Correct |
471 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
12628 KB |
Output is correct |
2 |
Correct |
153 ms |
12620 KB |
Output is correct |
3 |
Correct |
149 ms |
12620 KB |
Output is correct |
4 |
Correct |
112 ms |
7192 KB |
Output is correct |
5 |
Correct |
127 ms |
9280 KB |
Output is correct |
6 |
Correct |
153 ms |
12660 KB |
Output is correct |
7 |
Correct |
154 ms |
12620 KB |
Output is correct |
8 |
Correct |
153 ms |
12616 KB |
Output is correct |
9 |
Correct |
166 ms |
12800 KB |
Output is correct |
10 |
Correct |
232 ms |
13108 KB |
Output is correct |
11 |
Correct |
290 ms |
13712 KB |
Output is correct |
12 |
Correct |
321 ms |
13068 KB |
Output is correct |
13 |
Correct |
141 ms |
10956 KB |
Output is correct |
14 |
Correct |
137 ms |
10948 KB |
Output is correct |
15 |
Correct |
136 ms |
10880 KB |
Output is correct |
16 |
Correct |
118 ms |
8224 KB |
Output is correct |
17 |
Correct |
125 ms |
9276 KB |
Output is correct |
18 |
Correct |
134 ms |
10924 KB |
Output is correct |
19 |
Correct |
137 ms |
10952 KB |
Output is correct |
20 |
Correct |
142 ms |
10964 KB |
Output is correct |
21 |
Correct |
149 ms |
11356 KB |
Output is correct |
22 |
Correct |
143 ms |
11860 KB |
Output is correct |
23 |
Correct |
139 ms |
11896 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
415 ms |
460 KB |
Output is correct |
27 |
Correct |
483 ms |
592 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
328 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
329 ms |
332 KB |
Output is correct |
32 |
Correct |
542 ms |
588 KB |
Output is correct |
33 |
Correct |
720 ms |
592 KB |
Output is correct |
34 |
Correct |
562 ms |
556 KB |
Output is correct |
35 |
Correct |
630 ms |
488 KB |
Output is correct |
36 |
Correct |
471 ms |
436 KB |
Output is correct |
37 |
Correct |
678 ms |
13552 KB |
Output is correct |
38 |
Correct |
602 ms |
13340 KB |
Output is correct |
39 |
Correct |
149 ms |
12584 KB |
Output is correct |
40 |
Correct |
117 ms |
8252 KB |
Output is correct |
41 |
Correct |
136 ms |
9672 KB |
Output is correct |
42 |
Correct |
524 ms |
13336 KB |
Output is correct |
43 |
Correct |
699 ms |
13556 KB |
Output is correct |
44 |
Correct |
481 ms |
13404 KB |
Output is correct |
45 |
Correct |
757 ms |
13740 KB |
Output is correct |
46 |
Correct |
710 ms |
13724 KB |
Output is correct |
47 |
Correct |
764 ms |
13864 KB |
Output is correct |