제출 #891040

#제출 시각아이디문제언어결과실행 시간메모리
891040pccAlternating Heights (CCO22_day1problem1)C++14
10 / 25
1033 ms14160 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int mxn = 3030; vector<int> paths[mxn]; int deg[mxn],arr[mxn]; int n,m; int range[mxn]; queue<int> q; bool check(int s,int e){ bool flag = false; fill(deg+1,deg+m+1,0); for(int i = s+1;i<=e;i++){ int a = arr[i-1],b = arr[i]; if(flag)swap(a,b); flag ^= 1; deg[b]++; paths[a].push_back(b); } for(int i = 1;i<=m;i++)if(!deg[i])q.push(i); while(!q.empty()){ auto now = q.front(); q.pop(); for(auto nxt:paths[now]){ deg[nxt]--; if(!deg[nxt])q.push(nxt); } } for(int i = 1;i<=m;i++)paths[i].clear(); if(*max_element(deg+1,deg+m+1) != 0)return false; else return true; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int q; cin>>n>>m>>q; for(int i = 1;i<=n;i++)cin>>arr[i]; for(int i = 1;i<=n;i++){ int l = i,r = n; while(l != r){ int mid = (l+r+1)>>1; if(check(i,mid))l = mid; else r = mid-1; } range[i] = l; } while(q--){ int l,r; cin>>l>>r; if(range[l]>=r)cout<<"YES\n"; else cout<<"NO\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...