Submission #620628

#TimeUsernameProblemLanguageResultExecution timeMemory
620628Theo830Alternating Heights (CCO22_day1problem1)C++17
0 / 25
480 ms9264 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ii,ll> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training ll n; vector<vll>in; ll out[3005] = {0}; bool check(vll arr){ f(i,0,n){ out[i] = 0; } in.assign(n,vll()); ll posoi = 0; queue<ll>q; f(i,0,(ll)arr.size()-1){ if(i % 2 == 0){ out[arr[i]]++; in[arr[i+1]].pb(arr[i]); } else{ out[arr[i+1]]++; in[arr[i]].pb(arr[i+1]); } } f(i,0,n){ if(out[i] == 0){ q.push(i); } } while(!q.empty()){ ll f = q.front(); q.pop(); posoi++; for(auto x:in[f]){ out[x]--; if(out[x] == 0){ q.push(x); } } } return posoi == n; } int main(void){ ios_base::sync_with_stdio(0); cin.tie(0); ll k,q; cin>>n>>k>>q; ll arr[n]; f(i,0,n){ cin>>arr[i]; } ll ans[n]; ll pos[2] = {0,1}; f(i,0,n){ ans[i] = max(i,pos[i % 2] - 1); while(pos[i % 2] < n){ vll ex; f(j,i,pos[i % 2] + 1){ ex.pb(arr[j]-1); } if(check(ex)){ pos[i % 2]++; } else{ ans[i] = pos[i % 2] - 1; break; } } } while(q--){ ll x,y; cin>>x>>y; if(ans[x-1] >= y-1){ 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...