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;
vector<int> vc[2020];
int n,k,q, arr[2020], dp[2020], vis[2020];
int cycle(int u)
{
vis[u] = 1;
for (int v : vc[u])
if (vis[v] == 1 || !vis[v] && cycle(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];
int l = 1, r = i;
dp[i] = i;
while(l <= r){
int mid = (l + r) >> 1;
bool check = true;
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]].emplace_back(arr[j - 1]);
else vc[arr[j - 1]].emplace_back(arr[j]);
}
for(int j = i; j>mid && check; --j) if(!vis[arr[j]] && cycle(arr[j])) check = false;
if(check){
dp[i] = mid;
r = mid - 1;
}
else l = mid+1;
}
}
while(q--){
int x, y; cin >> x >> y;
dp[y] <= x ? cout << "YES\n" : cout << "NO\n";
}
}
Compilation message (stderr)
Main.cpp: In function 'int cycle(int)':
Main.cpp:12:36: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
12 | if (vis[v] == 1 || !vis[v] && cycle(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... |