#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
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 |
1 |
Incorrect |
8 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
7644 KB |
Output is correct |
2 |
Correct |
125 ms |
7672 KB |
Output is correct |
3 |
Correct |
131 ms |
7644 KB |
Output is correct |
4 |
Correct |
97 ms |
6720 KB |
Output is correct |
5 |
Correct |
111 ms |
6596 KB |
Output is correct |
6 |
Correct |
124 ms |
7416 KB |
Output is correct |
7 |
Correct |
126 ms |
7652 KB |
Output is correct |
8 |
Correct |
123 ms |
7500 KB |
Output is correct |
9 |
Correct |
143 ms |
7892 KB |
Output is correct |
10 |
Correct |
126 ms |
8552 KB |
Output is correct |
11 |
Correct |
125 ms |
8540 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |