# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973915 | 2024-05-02T12:52:34 Z | SeenSiravit | Alternating Heights (CCO22_day1problem1) | C++14 | 708 ms | 14164 KB |
#include<bits/stdc++.h> using namespace std; const int mxN = 3e3 + 5; int n,k,q; int a[mxN]; int ans[mxN]; vector<int> g[mxN]; int vis[mxN]; bool valid; void dfs(int u){ vis[u] = 1; for(auto v : g[u]){ if(vis[v] == 2) continue; else if(vis[v] == 1){ valid = false; return ; }else{ dfs(v); if(!valid) return ; } } vis[u] = 2; } int main(){ scanf("%d %d %d",&n,&k,&q); for(int i=1;i<=n;i++) scanf("%d",a+i); for(int i=1;i<=n;i++) ans[i] = n + 1; for(int l=1;l<=n;l++){ int lb=l+1 , ub=n; while(lb<=ub){ // clear edge and reset vis value for(int i=1;i<=k;i++) g[i].clear() , vis[i] = 0; int mid = (lb + ub) / 2; // add edge int t = 1; for(int i=l;i<mid;i++){ if(t == 1) g[a[i]].push_back(a[i+1]); else g[a[i+1]].push_back(a[i]); t ^= 1; } valid = true; for(int i=l;i<=mid;i++){ if(vis[a[i]] == 0){ dfs(a[i]); if(!valid) break; } } if(!valid){ ans[l] = min(ans[l] , mid); // printf("l=%d , mid=%d\n" , l , mid); ub = mid - 1; }else lb = mid + 1; } } // for(int i=1;i<=n;i++) printf("%d " , ans[i]); // printf("\n"); while(q--){ int l,r; scanf("%d %d" , &l , &r); cout<< (ans[l]<=r ? "NO" : "YES") << "\n"; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 209 ms | 3408 KB | Output is correct |
2 | Correct | 187 ms | 3416 KB | Output is correct |
3 | Correct | 187 ms | 3412 KB | Output is correct |
4 | Correct | 162 ms | 3284 KB | Output is correct |
5 | Correct | 161 ms | 3504 KB | Output is correct |
6 | Correct | 185 ms | 3492 KB | Output is correct |
7 | Correct | 195 ms | 3664 KB | Output is correct |
8 | Correct | 188 ms | 3388 KB | Output is correct |
9 | Correct | 202 ms | 3784 KB | Output is correct |
10 | Correct | 245 ms | 13136 KB | Output is correct |
11 | Correct | 371 ms | 13908 KB | Output is correct |
12 | Correct | 370 ms | 13140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 167 ms | 3412 KB | Output is correct |
2 | Correct | 175 ms | 3408 KB | Output is correct |
3 | Correct | 175 ms | 3412 KB | Output is correct |
4 | Correct | 164 ms | 4424 KB | Output is correct |
5 | Correct | 176 ms | 3632 KB | Output is correct |
6 | Correct | 167 ms | 3408 KB | Output is correct |
7 | Correct | 187 ms | 3636 KB | Output is correct |
8 | Correct | 168 ms | 3516 KB | Output is correct |
9 | Correct | 176 ms | 3920 KB | Output is correct |
10 | Correct | 221 ms | 4448 KB | Output is correct |
11 | Correct | 172 ms | 4428 KB | Output is correct |
12 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 196 ms | 572 KB | Output is correct |
3 | Correct | 195 ms | 604 KB | Output is correct |
4 | Correct | 13 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 600 KB | Output is correct |
7 | Correct | 127 ms | 604 KB | Output is correct |
8 | Correct | 255 ms | 600 KB | Output is correct |
9 | Correct | 353 ms | 604 KB | Output is correct |
10 | Correct | 451 ms | 604 KB | Output is correct |
11 | Correct | 539 ms | 612 KB | Output is correct |
12 | Correct | 387 ms | 604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 209 ms | 3408 KB | Output is correct |
2 | Correct | 187 ms | 3416 KB | Output is correct |
3 | Correct | 187 ms | 3412 KB | Output is correct |
4 | Correct | 162 ms | 3284 KB | Output is correct |
5 | Correct | 161 ms | 3504 KB | Output is correct |
6 | Correct | 185 ms | 3492 KB | Output is correct |
7 | Correct | 195 ms | 3664 KB | Output is correct |
8 | Correct | 188 ms | 3388 KB | Output is correct |
9 | Correct | 202 ms | 3784 KB | Output is correct |
10 | Correct | 245 ms | 13136 KB | Output is correct |
11 | Correct | 371 ms | 13908 KB | Output is correct |
12 | Correct | 370 ms | 13140 KB | Output is correct |
13 | Correct | 167 ms | 3412 KB | Output is correct |
14 | Correct | 175 ms | 3408 KB | Output is correct |
15 | Correct | 175 ms | 3412 KB | Output is correct |
16 | Correct | 164 ms | 4424 KB | Output is correct |
17 | Correct | 176 ms | 3632 KB | Output is correct |
18 | Correct | 167 ms | 3408 KB | Output is correct |
19 | Correct | 187 ms | 3636 KB | Output is correct |
20 | Correct | 168 ms | 3516 KB | Output is correct |
21 | Correct | 176 ms | 3920 KB | Output is correct |
22 | Correct | 221 ms | 4448 KB | Output is correct |
23 | Correct | 172 ms | 4428 KB | Output is correct |
24 | Correct | 1 ms | 344 KB | Output is correct |
25 | Correct | 1 ms | 348 KB | Output is correct |
26 | Correct | 196 ms | 572 KB | Output is correct |
27 | Correct | 195 ms | 604 KB | Output is correct |
28 | Correct | 13 ms | 348 KB | Output is correct |
29 | Correct | 1 ms | 348 KB | Output is correct |
30 | Correct | 1 ms | 600 KB | Output is correct |
31 | Correct | 127 ms | 604 KB | Output is correct |
32 | Correct | 255 ms | 600 KB | Output is correct |
33 | Correct | 353 ms | 604 KB | Output is correct |
34 | Correct | 451 ms | 604 KB | Output is correct |
35 | Correct | 539 ms | 612 KB | Output is correct |
36 | Correct | 387 ms | 604 KB | Output is correct |
37 | Correct | 395 ms | 13396 KB | Output is correct |
38 | Correct | 355 ms | 13220 KB | Output is correct |
39 | Correct | 195 ms | 12892 KB | Output is correct |
40 | Correct | 161 ms | 8236 KB | Output is correct |
41 | Correct | 162 ms | 9768 KB | Output is correct |
42 | Correct | 342 ms | 13404 KB | Output is correct |
43 | Correct | 504 ms | 13652 KB | Output is correct |
44 | Correct | 328 ms | 13392 KB | Output is correct |
45 | Correct | 708 ms | 14160 KB | Output is correct |
46 | Correct | 673 ms | 13820 KB | Output is correct |
47 | Correct | 685 ms | 14164 KB | Output is correct |