| 比赛 |
NOIP2025模拟赛3 |
评测结果 |
AAAAAAAAAAAAAAAAAAAAAAAAA |
| 题目名称 |
Alternating Heights |
最终得分 |
100 |
| 用户昵称 |
李奇文 |
运行时间 |
20.727 s |
| 代码语言 |
C++ |
内存使用 |
3.83 MiB |
| 提交时间 |
2025-11-26 12:07:21 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define in inline
#define pii pair<int,int>
using namespace std;
template<typename T>T read(){
T res=0,f=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
for(;isdigit(ch);ch=getchar()) res=(res<<3)+(res<<1)+(ch^48);
return res*f;
}
template<typename T>void write(T x){
if(x<0) x=-x,putchar('-');
int sta[20],top=0;
do{
sta[++top]=x%10+'0';
x/=10;
}while(x);
while(top){
putchar(sta[top--]);
}
}
const int N=3005,Q=1e6+5;
int n,k,q,a[N],d[N],ans[N],tot;
vector<int>e[N];
bool solve(int l,int r){
memset(d,0,sizeof(d));
queue<int> q;tot=0;
for(int i(1);i<=k;++i) e[i].clear();
for(int i(l+1);i<=r;i+=2){
e[a[i-1]].push_back(a[i]);
d[a[i]]++;
if(i+1<=r){
e[a[i+1]].push_back(a[i]);
d[a[i]]++;
}
}
for(int i(1);i<=k;++i) if(!d[i]) q.push(i);
while(!q.empty()){
int f=q.front();
q.pop();++tot;
for(int to:e[f]){
d[to]--;
if(!d[to]) q.push(to);
}
}
if(tot==k) return 1;
else return 0;
}
int l,r,x,y,mid;
signed main(){
freopen("Heights.in","r",stdin);
freopen("Heights.out","w",stdout);
n=read<int>(),k=read<int>(),q=read<int>();
for(int i(1);i<=n;++i){
a[i]=read<int>();
}
for(int i(1);i<=n;++i){
l=i,r=n;
ans[i]=i;
while(l<=r){
mid=((l+r)>>1);
if(solve(i,mid)){
l=mid+1;
ans[i]=mid;
}else{
r=mid-1;
}
}
}
for(int i(1);i<=q;++i){
x=read<int>(),y=read<int>();
if(y<=ans[x]) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}