Submission #698957

#TimeUsernameProblemLanguageResultExecution timeMemory
698957safaricolaAlternating Heights (CCO22_day1problem1)C++17
0 / 25
110 ms5012 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 1; i <= n; i++) #define pb push_back int n,a[3010],st=2,k,q,top[3010],cur,mini[3010],x,y; bool rmv[3010][3010],vis[3010]; vector<int> adjl[3010]; bool ord(int a){ if(vis[a] && top[a]==-1) return true; if(vis[a]) return false; vis[a] = true; for (int it: adjl[a]){ if(rmv[a][it])continue; if(ord(it)){ return true; } } cur++; top[a]=cur; return false; } void remov(){ bool flag=true; while(flag){ flag=false; cur=0; memset(top, -1, sizeof(top)); memset(vis, 0, sizeof(vis)); for(int i=1; i<=n; i++) if(!vis[i]) if(ord(i)){ flag=true; i=n+1; break; } if(flag){ //remove edge; assert(st<=n+1); if(st%2==1){ rmv[a[st]][a[st-1]]=1; }else{ rmv[a[st-1]][a[st]]=1; } st++; } } } int main(){ cin>>n>>k>>q; mini[1]=1; rep(i,n){ cin>>a[i]; if(i==1)continue; if(i%2==1){ adjl[a[i]].pb(a[i-1]); if(a[i]==a[i-1])st=i+1; remov(); //cout<<st<<' '<<i<<endl; mini[i]=st-1; }else{ adjl[a[i-1]].pb(a[i]); remov(); if(a[i]==a[i-1])st=i+1; //cout<<st<<' '<<i<<endl; mini[i]=st-1; } } while(q--){ cin>>x>>y; if(x<mini[y])cout<<"NO\n"; else cout<<"YES\n"; } } /* 6 3 3 1 1 2 3 1 2 1 2 2 5 2 6 * 6 3 3 1 1 1 1 1 1 1 2 2 5 2 6 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...