제출 #698403

#제출 시각아이디문제언어결과실행 시간메모리
698403emptypringlescanAlternating Heights (CCO22_day1problem1)C++17
0 / 25
1010 ms596 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") vector<short> adj[3005]; bool cyc=false,v[3005],isdoing[3005]; void dfs(short x){ v[x]=1; isdoing[x]=1; for(short i:adj[x]){ if(isdoing[i]) cyc=true; else if(!v[i]) dfs(i); } isdoing[x]=0; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); short n,k,q; cin >> n >> k >> q; short arr[n]; for(short i=0; i<n; i++) cin >> arr[i]; short prec[n]; for(short i=0; i<n; i++){ short lo=i,hi=n-1,mid; while(lo<hi){ mid=(lo+hi+1)/2; short ev=0; for(short j=0; j<=k; j++){ adj[j].clear(); v[j]=0; isdoing[j]=0; } for(short j=i+1; j<=mid; j++){ if(ev){ adj[arr[j]].push_back(arr[j-1]); } else{ adj[arr[j-1]].push_back(arr[j]); } ev^=1; } cyc=false; for(short j=i; j<=mid; j++){ if(!v[arr[j]]) dfs(arr[j]); } //cout << i << ' ' << mid << ' ' << cyc << ' ' << found << '\n'; if(cyc){ hi=mid-1; } else lo=mid; } prec[i]=lo; //cout << lo << ' '; } for(short i=0; i<q; i++){ short a,b; cin >> a >> b; a--; b--; if(b<=prec[a]) cout << "YES\n"; else 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...