#include <bits/stdc++.h>
using namespace std;
int n, k, q, arr[3010], dp[3010], x, y, vs[3010], idx, l, r, mid;
bool cnt;
pair<int, int> temp;
vector<int> g[3010];
int cyclic(int u)
{
vs[u] = 1;
for (int v : g[u])
if (vs[v] == 1 || !vs[v] && cyclic(v)) return 1;
vs[u] = 2;
return 0;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k >> q;
for(int i=1; i<=n; i++) {
cin >> arr[i];
}
for(int i=1; i<=n; i++) {
l=i; r=n;
while(l<r) {
mid = (l+r)>>1;
for(int j=1; j<=n; j++) {
g[j].clear();
}
for(int j=i+1; j<=n; j++) {
if(j%2 == 0) {
g[arr[j-1]].push_back(arr[j]);
} else {
g[arr[j]].push_back(arr[j-1]);
}
}
for (int j = i; cnt && j > mid; --j) if (!vs[arr[j]] && cyclic(arr[j])) cnt = 0;
if(cnt) {
r = mid;
} else {
l = mid+1;
}
}
dp[i] = l;
}
while(q--) {
cin >> x >> y;
if(x == y || dp[x] <= y) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
Compilation message
Main.cpp: In function 'int cyclic(int)':
Main.cpp:14:34: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
14 | if (vs[v] == 1 || !vs[v] && cyclic(v)) return 1;
| ~~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
307 ms |
12608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
126 ms |
10716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
307 ms |
12608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |