#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
vector<int> adj[3005];
bool cyc=false,v[3005],isdoing[3005];
void dfs(int x){
v[x]=1;
isdoing[x]=1;
for(int i:adj[x]){
if(isdoing[i]) cyc=true;
else if(!v[i]) dfs(i);
}
isdoing[x]=0;
}
void fastscan(int &number)
{
//variable to indicate sign of input number
bool negative = false;
register int c;
number = 0;
// extract current character from buffer
c = getchar();
if (c=='-')
{
// number is negative
negative = true;
// extract the next character from the buffer
c = getchar();
}
// Keep on extracting characters if they are integers
// i.e ASCII Value lies from '0'(48) to '9' (57)
for (; (c>47 && c<58); c=getchar())
number = number *10 + c - 48;
// if scanned input has a negative sign, negate the
// value of the input number
if (negative)
number *= -1;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,k,q;
fastscan(n); fastscan(k); fastscan(q);
int arr[n];
for(int i=0; i<n; i++) fastscan(arr[i]);
int prec[n];
for(int i=0; i<n; i++){
int lo=i,hi=n-1,mid;
while(lo<hi){
mid=(lo+hi+1)/2;
int ev=0;
for(int j=0; j<=k; j++){
adj[j].clear();
v[j]=0;
isdoing[j]=0;
}
for(int j=i+1; j<=mid; j++){
if(ev){
adj[arr[j]].push_back(arr[j-1]);
}
else{
adj[arr[j-1]].push_back(arr[j]);
}
ev^=1;
}
cyc=false;
for(int j=i; j<=mid; j++){
if(!v[arr[j]]) dfs(arr[j]);
}
//cout << i << ' ' << mid << ' ' << cyc << ' ' << found << '\n';
if(cyc){
hi=mid-1;
}
else lo=mid;
}
prec[i]=lo;
//cout << lo << ' ';
}
for(int i=0; i<q; i++){
int a,b;
fastscan(a); fastscan(b);
a--; b--;
if(b<=prec[a]) cout << "YES\n";
else cout << "NO\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
3364 KB |
Output is correct |
2 |
Correct |
98 ms |
3408 KB |
Output is correct |
3 |
Correct |
98 ms |
3364 KB |
Output is correct |
4 |
Correct |
42 ms |
3380 KB |
Output is correct |
5 |
Correct |
46 ms |
3452 KB |
Output is correct |
6 |
Correct |
98 ms |
3316 KB |
Output is correct |
7 |
Correct |
99 ms |
3356 KB |
Output is correct |
8 |
Correct |
97 ms |
3376 KB |
Output is correct |
9 |
Correct |
114 ms |
3496 KB |
Output is correct |
10 |
Correct |
232 ms |
3876 KB |
Output is correct |
11 |
Correct |
422 ms |
4408 KB |
Output is correct |
12 |
Correct |
395 ms |
4304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
3380 KB |
Output is correct |
2 |
Correct |
53 ms |
3464 KB |
Output is correct |
3 |
Correct |
51 ms |
3392 KB |
Output is correct |
4 |
Correct |
36 ms |
4276 KB |
Output is correct |
5 |
Correct |
50 ms |
3596 KB |
Output is correct |
6 |
Correct |
52 ms |
3372 KB |
Output is correct |
7 |
Correct |
53 ms |
3412 KB |
Output is correct |
8 |
Correct |
54 ms |
3520 KB |
Output is correct |
9 |
Correct |
62 ms |
3788 KB |
Output is correct |
10 |
Correct |
59 ms |
4372 KB |
Output is correct |
11 |
Correct |
58 ms |
4300 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
348 ms |
448 KB |
Output is correct |
3 |
Correct |
411 ms |
560 KB |
Output is correct |
4 |
Correct |
40 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
291 ms |
436 KB |
Output is correct |
8 |
Correct |
529 ms |
468 KB |
Output is correct |
9 |
Correct |
732 ms |
468 KB |
Output is correct |
10 |
Correct |
752 ms |
460 KB |
Output is correct |
11 |
Correct |
867 ms |
468 KB |
Output is correct |
12 |
Correct |
668 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
3364 KB |
Output is correct |
2 |
Correct |
98 ms |
3408 KB |
Output is correct |
3 |
Correct |
98 ms |
3364 KB |
Output is correct |
4 |
Correct |
42 ms |
3380 KB |
Output is correct |
5 |
Correct |
46 ms |
3452 KB |
Output is correct |
6 |
Correct |
98 ms |
3316 KB |
Output is correct |
7 |
Correct |
99 ms |
3356 KB |
Output is correct |
8 |
Correct |
97 ms |
3376 KB |
Output is correct |
9 |
Correct |
114 ms |
3496 KB |
Output is correct |
10 |
Correct |
232 ms |
3876 KB |
Output is correct |
11 |
Correct |
422 ms |
4408 KB |
Output is correct |
12 |
Correct |
395 ms |
4304 KB |
Output is correct |
13 |
Correct |
54 ms |
3380 KB |
Output is correct |
14 |
Correct |
53 ms |
3464 KB |
Output is correct |
15 |
Correct |
51 ms |
3392 KB |
Output is correct |
16 |
Correct |
36 ms |
4276 KB |
Output is correct |
17 |
Correct |
50 ms |
3596 KB |
Output is correct |
18 |
Correct |
52 ms |
3372 KB |
Output is correct |
19 |
Correct |
53 ms |
3412 KB |
Output is correct |
20 |
Correct |
54 ms |
3520 KB |
Output is correct |
21 |
Correct |
62 ms |
3788 KB |
Output is correct |
22 |
Correct |
59 ms |
4372 KB |
Output is correct |
23 |
Correct |
58 ms |
4300 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
348 ms |
448 KB |
Output is correct |
27 |
Correct |
411 ms |
560 KB |
Output is correct |
28 |
Correct |
40 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
291 ms |
436 KB |
Output is correct |
32 |
Correct |
529 ms |
468 KB |
Output is correct |
33 |
Correct |
732 ms |
468 KB |
Output is correct |
34 |
Correct |
752 ms |
460 KB |
Output is correct |
35 |
Correct |
867 ms |
468 KB |
Output is correct |
36 |
Correct |
668 ms |
340 KB |
Output is correct |
37 |
Correct |
542 ms |
4044 KB |
Output is correct |
38 |
Correct |
421 ms |
3900 KB |
Output is correct |
39 |
Correct |
97 ms |
3316 KB |
Output is correct |
40 |
Correct |
35 ms |
4376 KB |
Output is correct |
41 |
Correct |
50 ms |
3948 KB |
Output is correct |
42 |
Correct |
409 ms |
3888 KB |
Output is correct |
43 |
Correct |
681 ms |
4284 KB |
Output is correct |
44 |
Correct |
367 ms |
4044 KB |
Output is correct |
45 |
Correct |
916 ms |
4420 KB |
Output is correct |
46 |
Correct |
858 ms |
4508 KB |
Output is correct |
47 |
Correct |
905 ms |
4552 KB |
Output is correct |