이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |