#include <bits/stdc++.h>
#ifndef memset0
#define endl '\n'
#endif
using namespace std;
const int N = 3e3 + 9;
int n, k, q, a[N], ok[N], deg[N];
vector<int> G[N];
bool check(int l, int r) {
// cerr << "check " << l << " " << r << endl;
fill_n(deg + 1, n, 0);
for (int i = 1; i <= n; i++) { G[i].clear(); }
for (int i = l; i < r; i++) {
int x = a[i], y = a[i + 1];
if ((i - l) & 1) swap(x, y);
G[x].push_back(y);
deg[y]++;
// cerr << x << "->" << y << endl;
}
queue<int> q;
for (int i = 1; i <= n; i++)
if (!deg[i]) { q.push(i); }
while (q.size()) {
int u = q.front();
q.pop();
for (int v : G[u]) {
--deg[v];
if (!deg[v]) { q.push(v); }
}
}
for (int i = 1; i <= n; i++)
if (deg[i]) return false;
return true;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k >> q;
for (int i = 1; i <= n; i++) { cin >> a[i]; }
for (int l, r, mid, i = 1; i <= n; i++) {
ok[i] = i, l = i + 1, r = n;
while (l <= r) {
mid = (l + r) >> 1;
if (check(i, mid)) {
ok[i] = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
}
for (int l, r, i = 1; i <= q; i++) {
cin >> l >> r;
cout << (r <= ok[l] ? "YES" : "NO") << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
635 ms |
12936 KB |
Output is correct |
2 |
Correct |
643 ms |
12864 KB |
Output is correct |
3 |
Correct |
640 ms |
12880 KB |
Output is correct |
4 |
Correct |
111 ms |
7252 KB |
Output is correct |
5 |
Correct |
123 ms |
9300 KB |
Output is correct |
6 |
Correct |
633 ms |
12884 KB |
Output is correct |
7 |
Correct |
640 ms |
12868 KB |
Output is correct |
8 |
Correct |
645 ms |
13168 KB |
Output is correct |
9 |
Correct |
661 ms |
13124 KB |
Output is correct |
10 |
Correct |
744 ms |
13388 KB |
Output is correct |
11 |
Correct |
898 ms |
13908 KB |
Output is correct |
12 |
Correct |
832 ms |
13456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
11088 KB |
Output is correct |
2 |
Correct |
136 ms |
11088 KB |
Output is correct |
3 |
Correct |
135 ms |
11092 KB |
Output is correct |
4 |
Correct |
110 ms |
8328 KB |
Output is correct |
5 |
Correct |
117 ms |
9364 KB |
Output is correct |
6 |
Correct |
137 ms |
11092 KB |
Output is correct |
7 |
Correct |
137 ms |
11088 KB |
Output is correct |
8 |
Correct |
138 ms |
11088 KB |
Output is correct |
9 |
Correct |
143 ms |
11600 KB |
Output is correct |
10 |
Correct |
141 ms |
12116 KB |
Output is correct |
11 |
Correct |
141 ms |
11976 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
845 ms |
876 KB |
Output is correct |
3 |
Correct |
880 ms |
852 KB |
Output is correct |
4 |
Correct |
496 ms |
576 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
802 ms |
640 KB |
Output is correct |
8 |
Correct |
990 ms |
792 KB |
Output is correct |
9 |
Execution timed out |
1062 ms |
852 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
635 ms |
12936 KB |
Output is correct |
2 |
Correct |
643 ms |
12864 KB |
Output is correct |
3 |
Correct |
640 ms |
12880 KB |
Output is correct |
4 |
Correct |
111 ms |
7252 KB |
Output is correct |
5 |
Correct |
123 ms |
9300 KB |
Output is correct |
6 |
Correct |
633 ms |
12884 KB |
Output is correct |
7 |
Correct |
640 ms |
12868 KB |
Output is correct |
8 |
Correct |
645 ms |
13168 KB |
Output is correct |
9 |
Correct |
661 ms |
13124 KB |
Output is correct |
10 |
Correct |
744 ms |
13388 KB |
Output is correct |
11 |
Correct |
898 ms |
13908 KB |
Output is correct |
12 |
Correct |
832 ms |
13456 KB |
Output is correct |
13 |
Correct |
136 ms |
11088 KB |
Output is correct |
14 |
Correct |
136 ms |
11088 KB |
Output is correct |
15 |
Correct |
135 ms |
11092 KB |
Output is correct |
16 |
Correct |
110 ms |
8328 KB |
Output is correct |
17 |
Correct |
117 ms |
9364 KB |
Output is correct |
18 |
Correct |
137 ms |
11092 KB |
Output is correct |
19 |
Correct |
137 ms |
11088 KB |
Output is correct |
20 |
Correct |
138 ms |
11088 KB |
Output is correct |
21 |
Correct |
143 ms |
11600 KB |
Output is correct |
22 |
Correct |
141 ms |
12116 KB |
Output is correct |
23 |
Correct |
141 ms |
11976 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
845 ms |
876 KB |
Output is correct |
27 |
Correct |
880 ms |
852 KB |
Output is correct |
28 |
Correct |
496 ms |
576 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
802 ms |
640 KB |
Output is correct |
32 |
Correct |
990 ms |
792 KB |
Output is correct |
33 |
Execution timed out |
1062 ms |
852 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |