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[3030], vis[3030], ans[3030], ck;
vector<int> vc[3030];
int check(int u){
vis[u] = 1;
for (int v : vc[u]) if(vis[v] == 1 || !vis[v] && check(v)) return 1;
vis[u] = 2;
return 0;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> k >> q;
for(int i = 1; i<=n; ++i) cin >> arr[i];
for(int i = 1; i<=n; ++i){
int l = i, r = n;
ans[i] = i;
while(l <= r){
int mid = (l + r) >> 1, ck = 1;
memset(vis, 0, sizeof(vis));
for(int j = 1; j<=k; ++j) vc[j].clear();
for(int j = i; j<mid; ++j){
if(j&1) vc[arr[j+1]].push_back(arr[j]);
else vc[arr[j]].push_back(arr[j+1]);
}
for(int j = i; j<=mid; ++j){
if(!vis[arr[j]] && check(arr[j])){
ck = 0;
break;
}
}
if(ck){
ans[i] = mid;
l = mid+1;
}
else r = mid - 1;
}
}
while(q--){
int l, r; cin >> l >> r;
ans[l] >= r ? cout << "YES\n": cout << "NO\n";
}
}
Compilation message (stderr)
Main.cpp: In function 'int check(int)':
Main.cpp:10:51: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
10 | for (int v : vc[u]) if(vis[v] == 1 || !vis[v] && check(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... |