把所有括号相匹配的段直接预处理出来就行了
#include <bits/stdc++.h> using namespace std; #define ll long long #define re register #define P pair<int,int> #define mp make_pair #define pb push_back #define fi first #define se second const int N=1e6+10; const int mod=19260817; void read(int &a) { a=0; int d=1; char ch; while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1; a=ch-'0'; while(ch=getchar(),ch>='0'&&ch<='9') a=a*10+ch-'0'; a*=d; } void write(int x) { if(x<0) putchar(45),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } int a[N],rmq[N],sta[N]; int main() { int n,m,T,cnt=0; read(n); read(m); read(T); for(re int i=1;i<=n;i++) read(a[i]); for(re int i=1;i<=n;i++) { if(cnt==0) sta[++cnt]=i; else if(a[sta[cnt]]/2==a[i]/2&&a[sta[cnt]]+1==a[i]) cnt--; else sta[++cnt]=i; rmq[i]=sta[cnt]; } while(T--) { int l,r; read(l); read(r); if(rmq[l-1]==rmq[r]) puts("Yes"); else puts("No"); } return 0; }