#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;
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 |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
3408 KB |
Output is correct |
2 |
Correct |
114 ms |
11088 KB |
Output is correct |
3 |
Correct |
113 ms |
11040 KB |
Output is correct |
4 |
Correct |
97 ms |
8856 KB |
Output is correct |
5 |
Correct |
110 ms |
9520 KB |
Output is correct |
6 |
Correct |
113 ms |
11148 KB |
Output is correct |
7 |
Correct |
132 ms |
10980 KB |
Output is correct |
8 |
Correct |
115 ms |
11008 KB |
Output is correct |
9 |
Correct |
123 ms |
11532 KB |
Output is correct |
10 |
Correct |
119 ms |
12080 KB |
Output is correct |
11 |
Correct |
118 ms |
12080 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |