第一眼看错题以为只是要求区间值域连续,那莫队一发维护形成的值域段数量就行了。
原题这个条件相当于区间内相邻数差的绝对值不超过1。所以只要对这个做个前缀和就……完了?
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 100010 char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } int n,m,a[N],s[N]; int main() { #ifndef ONLINE_JUDGE freopen("bzoj5127.in","r",stdin); freopen("bzoj5127.out","w",stdout); const char LL[]="%I64d "; #else const char LL[]="%lld "; #endif n=read(),m=read(); for (int i=1;i<=n;i++) a[i]=read(),s[i]=s[i-1]+(abs(a[i]-a[i-1])>1); while (m--) { int l=read(),r=read(); if (s[r]-s[l]) puts("NO");else puts("YES"); } return 0; }