This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |