제출 #1124838

#제출 시각아이디문제언어결과실행 시간메모리
1124838VinhLuuAlternating Heights (CCO22_day1problem1)C++20
10 / 25
1096 ms27968 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]; void dfs(int u) { in[u] = ++demin; for(auto j : p[u]) { if(!in[j]) { dfs(j); } } en[u] = demin; } 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]); } } for(int j = 1; j <= k; j ++) if(!in[j]) { dfs(j); } bool ff = true; for(int j = 1; j <= k; j ++) { for(auto h : p[j]) { if(kt(h, j)) { ff = false; break; } } 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"; } }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen(task ".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     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...