Submission #698301

#TimeUsernameProblemLanguageResultExecution timeMemory
698301blackscreen1Alternating Heights (CCO22_day1problem1)C++17
11 / 25
246 ms13724 KiB
#include <bits//stdc++.h> using namespace std; #define ll long long #define st short #define iloop(m, h) for (auto i = m; i != h; i+=(m<h?1:-1)) #define jloop(m, h) for (auto j = m; j != h; j+=(m<h?1:-1)) #define kloop(m, h) for (auto k = m; k != h; k+=(m<h?1:-1)) #define lloop(m, h) for (auto l = m; l != h; l+=(m<h?1:-1)) #define iloop_(m, h, g) for (auto i = m; i != h; i+=g) #define jloop_(m, h, g) for (auto j = m; j != h; j+=g) #define kloop_(m, h, g) for (auto k = m; k != h; k+=g) #define lloop_(m, h, g) for (auto l = m; l != h; l+=g) #define getchar_unlocked _getchar_nolock // comment before submission #define pll pair<ll,ll> #define plll pair<ll, pll> #define pllll pair<pll, pll> #define vll vector<ll> #define qll queue<ll> #define dll deque<ll> #define pqll priority_queue<ll> #define gll greater<ll> #define INF 1000000000000000 #define MOD1 1000000007 #define MOD2 998244353 #define MOD3 1000000009 mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); ll n, m, t; bool adjmat[3005][3005]; ll vis[3005]; bool dfs(ll nd) { vis[nd] = 1; iloop(0, m) { if (adjmat[nd][i] && vis[i] == 1) return 0; if (adjmat[nd][i] && vis[i] == 0) if (dfs(i) == 0) return 0; } vis[nd] = 2; return 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> t; ll a[n]; iloop(0, n) {cin >> a[i]; a[i]--;} ll lptr = 0; ll ans[n]; iloop(0, n) { if (i != 0) { if (i%2 == 1) { adjmat[a[i]][a[i-1]] = 1; } else { adjmat[a[i-1]][a[i]] = 1; } } while (1) { memset(vis, 0, sizeof(vis)); if (dfs(a[i]) == 1) break; lptr++; if (lptr%2 == 1) { adjmat[a[lptr]][a[lptr-1]] = 0; } else { adjmat[a[lptr-1]][a[lptr]] = 0; } } ans[i] = lptr; } ll a1, b1; iloop(0, t) { cin >> a1 >> b1; a1--, b1--; if (ans[b1] > a1) cout << "NO\n"; else cout << "YES\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...