Submission #1124840

#TimeUsernameProblemLanguageResultExecution timeMemory
1124840VinhLuuAlternating Heights (CCO22_day1problem1)C++20
17 / 25
1039 ms28024 KiB
#include <bits/stdc++.h> //#define int long long #define ll long long #define all(lpv) lpv.begin(), lpv.end() #define fi first #define se second #define pot(x, y) lower_bound(x.begin(), x.end(), y) - x.begin() using namespace std; typedef pair<int,int> pii; const int N = 1e6 + 5; const int oo = 1e9; int n, f[N], k, q, a[N], flag[N], deg[N], id[N]; vector<int> p[N]; int demin, in[N], en[N]; bool ff = true; void dfs(int u) { in[u] = 1; for(auto j : p[u]) { if(in[j] == 2) continue; if(!in[j]) { dfs(j); } else { ff = false; return; } if(!ff) return; } in[u] = 2; } bool kt(int u,int v) { return in[u] <= in[v] && in[v] <= en[u]; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")) { freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n >> k >> q; for(int i = 1; i <= n; i ++) cin >> a[i]; for(int i = 1; i <= n; i ++) { f[i] = i; int l = i + 1, r = n, mid; while(l <= r) { mid = (l + r) / 2; for(int j = 1; j <= k; j ++) { flag[j] = 0, p[j].clear(); in[j] = en[j] = 0; } demin = 0; for(int j = i; j < mid; j ++) { if(j % 2 == i % 2) { // > p[a[j]].push_back(a[j + 1]); } else { p[a[j + 1]].push_back(a[j]); } } ff = true; for(int j = 1; j <= k; j ++) if(!in[j]) { dfs(j); if(!ff) break; } if(ff) f[i] = mid, l = mid + 1; else r = mid - 1; } } while(q--) { int l, r; cin >> l >> r; if(f[l] < r) cout << "NO\n"; else cout << "YES\n"; } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     freopen(task ".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen(task ".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...