Submission #966251

#TimeUsernameProblemLanguageResultExecution timeMemory
966251vjudge1Alternating Heights (CCO22_day1problem1)C++17
0 / 25
122 ms3416 KiB
#include<bits/stdc++.h> using namespace std; vector<int> vc[2020]; int n,k,q, arr[2020], dp[2020], vis[2020]; bool cycle(int u){ vis[u] = 1; for(auto x:vc[u]) if(vis[x] || (!vis[x] && cycle(x))) 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 >> 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[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"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...