#include<bits/stdc++.h>
using namespace std;
const int N=3005;
int n,k,q;
int a[N],p[N],vis[N];
vector<int> adj[N];
bool dfs(int u){
if(vis[u])return vis[u]==1;
vis[u]=1;
for(auto v:adj[u])if(dfs(v))return true;
vis[u]=2;
return false;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> k >> q;
for(int i=1;i<=n;i++)cin >> a[i];
for(int i=1;i<=n;i++){
int l=i,r=n;
while(l<r){
int m=(l+r+1)/2;
bool b=false;
for(int j=i;j<m;j++){
if(b)adj[a[j]].emplace_back(a[j+1]);
else adj[a[j+1]].emplace_back(a[j]);
b^=true;
}
bool ok=true;
for(int j=i;j<=m;j++)if(dfs(a[j])){
ok=false;
break;
}
for(int j=i;j<=m;j++){
adj[a[j]].clear();
vis[a[j]]=0;
}
if(ok)l=m;
else r=m-1;
}
p[i]=l;
}
while(q--){
int l,r;
cin >> l >> r;
cout << (p[l]>=r?"YES":"NO") << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
12880 KB |
Output is correct |
2 |
Correct |
194 ms |
12672 KB |
Output is correct |
3 |
Correct |
169 ms |
12884 KB |
Output is correct |
4 |
Correct |
116 ms |
7428 KB |
Output is correct |
5 |
Correct |
136 ms |
9300 KB |
Output is correct |
6 |
Correct |
210 ms |
13100 KB |
Output is correct |
7 |
Correct |
169 ms |
12884 KB |
Output is correct |
8 |
Correct |
178 ms |
13032 KB |
Output is correct |
9 |
Correct |
184 ms |
12884 KB |
Output is correct |
10 |
Correct |
263 ms |
13304 KB |
Output is correct |
11 |
Correct |
457 ms |
13848 KB |
Output is correct |
12 |
Correct |
406 ms |
13140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
11084 KB |
Output is correct |
2 |
Correct |
141 ms |
11088 KB |
Output is correct |
3 |
Correct |
149 ms |
11108 KB |
Output is correct |
4 |
Correct |
115 ms |
8272 KB |
Output is correct |
5 |
Correct |
126 ms |
9552 KB |
Output is correct |
6 |
Correct |
150 ms |
10932 KB |
Output is correct |
7 |
Correct |
143 ms |
11180 KB |
Output is correct |
8 |
Correct |
142 ms |
11088 KB |
Output is correct |
9 |
Correct |
151 ms |
11388 KB |
Output is correct |
10 |
Correct |
148 ms |
11972 KB |
Output is correct |
11 |
Correct |
169 ms |
12172 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
89 ms |
636 KB |
Output is correct |
3 |
Correct |
122 ms |
600 KB |
Output is correct |
4 |
Correct |
20 ms |
576 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
93 ms |
632 KB |
Output is correct |
8 |
Correct |
195 ms |
628 KB |
Output is correct |
9 |
Correct |
304 ms |
632 KB |
Output is correct |
10 |
Correct |
451 ms |
856 KB |
Output is correct |
11 |
Correct |
469 ms |
600 KB |
Output is correct |
12 |
Correct |
445 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
12880 KB |
Output is correct |
2 |
Correct |
194 ms |
12672 KB |
Output is correct |
3 |
Correct |
169 ms |
12884 KB |
Output is correct |
4 |
Correct |
116 ms |
7428 KB |
Output is correct |
5 |
Correct |
136 ms |
9300 KB |
Output is correct |
6 |
Correct |
210 ms |
13100 KB |
Output is correct |
7 |
Correct |
169 ms |
12884 KB |
Output is correct |
8 |
Correct |
178 ms |
13032 KB |
Output is correct |
9 |
Correct |
184 ms |
12884 KB |
Output is correct |
10 |
Correct |
263 ms |
13304 KB |
Output is correct |
11 |
Correct |
457 ms |
13848 KB |
Output is correct |
12 |
Correct |
406 ms |
13140 KB |
Output is correct |
13 |
Correct |
144 ms |
11084 KB |
Output is correct |
14 |
Correct |
141 ms |
11088 KB |
Output is correct |
15 |
Correct |
149 ms |
11108 KB |
Output is correct |
16 |
Correct |
115 ms |
8272 KB |
Output is correct |
17 |
Correct |
126 ms |
9552 KB |
Output is correct |
18 |
Correct |
150 ms |
10932 KB |
Output is correct |
19 |
Correct |
143 ms |
11180 KB |
Output is correct |
20 |
Correct |
142 ms |
11088 KB |
Output is correct |
21 |
Correct |
151 ms |
11388 KB |
Output is correct |
22 |
Correct |
148 ms |
11972 KB |
Output is correct |
23 |
Correct |
169 ms |
12172 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
89 ms |
636 KB |
Output is correct |
27 |
Correct |
122 ms |
600 KB |
Output is correct |
28 |
Correct |
20 ms |
576 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
93 ms |
632 KB |
Output is correct |
32 |
Correct |
195 ms |
628 KB |
Output is correct |
33 |
Correct |
304 ms |
632 KB |
Output is correct |
34 |
Correct |
451 ms |
856 KB |
Output is correct |
35 |
Correct |
469 ms |
600 KB |
Output is correct |
36 |
Correct |
445 ms |
624 KB |
Output is correct |
37 |
Correct |
306 ms |
13392 KB |
Output is correct |
38 |
Correct |
256 ms |
13396 KB |
Output is correct |
39 |
Correct |
174 ms |
12880 KB |
Output is correct |
40 |
Correct |
116 ms |
8276 KB |
Output is correct |
41 |
Correct |
130 ms |
9808 KB |
Output is correct |
42 |
Correct |
269 ms |
13396 KB |
Output is correct |
43 |
Correct |
466 ms |
13620 KB |
Output is correct |
44 |
Correct |
298 ms |
13364 KB |
Output is correct |
45 |
Correct |
626 ms |
13948 KB |
Output is correct |
46 |
Correct |
629 ms |
13904 KB |
Output is correct |
47 |
Correct |
620 ms |
13952 KB |
Output is correct |