同之前那道由乃题,可以认为由乃题是这题的特殊情况……
维护方法是同样的,维护区间和,区间平方和即可。
注意特判一个数(其实没有必要)
#include<bits/stdc++.h> const int N=300005; using namespace std; typedef long long ll; const int yql=1e9+7; int n,m;ll a[N],s[N]; ll sum,sumx;ll mn,mx,LastOrder=0; struct Segment_Tree{ #define lson (o<<1) #define rson (o<<1|1) ll sumv[N<<2],sum2[N<<2];ll maxv[N<<2],minv[N<<2]; inline void pushup(int o){ sumv[o]=sumv[lson]+sumv[rson]; sum2[o]=(sum2[lson]+sum2[rson])%yql; minv[o]=min(minv[lson],minv[rson]); maxv[o]=max(maxv[lson],maxv[rson]); } inline void build(int o,int l,int r){ if(l==r){ sumv[o]=a[l];sum2[o]=1LL*a[l]*a[l]%yql;maxv[o]=a[l];minv[o]=a[l]; return; } int mid=(l+r)>>1; build(lson,l,mid);build(rson,mid+1,r); pushup(o); } inline void change(int o,int l,int r,int q){ if(l==r){sumv[o]=a[l];sum2[o]=1LL*a[l]*a[l]%yql;maxv[o]=a[l];minv[o]=a[l];return;} int mid=(l+r)>>1; if(q<=mid)change(lson,l,mid,q); if(q>mid)change(rson,mid+1,r,q); pushup(o); } inline void query(int o,int l,int r,int ql,int qr){ if(ql<=l&&r<=qr){mx=max(mx,maxv[o]);mn=min(mn,minv[o]);sum+=sumv[o];sumx=(sumx+sum2[o])%yql;return;} int mid=(l+r)>>1; if(ql<=mid)query(lson,l,mid,ql,qr); if(qr>mid)query(rson,mid+1,r,ql,qr); } }T; inline ll read(){ ll f=1,x=0;char ch; do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9'); do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9'); return f*x; } int main(){ n=read();m=read();for(int i=1;i<=n;i++)a[i]=read(); s[0]=0;for(int i=1;i<n;i++)s[i]=(s[i-1]+i*i)%yql; T.build(1,1,n); while(m--){ int opt=read(); if(opt==1){ int x=read(),y=read();x^=LastOrder;y^=LastOrder; a[x]=y;T.change(1,1,n,x); } if(opt==2){ mx=-1,mn=yql+1;sum=0;sumx=0; ll l=read(),r=read(),k=read(); l^=LastOrder;r^=LastOrder;k^=LastOrder; if(l==r){puts("Yes");LastOrder++;continue;} T.query(1,1,n,l,r);ll size=r-l+1;//printf("%lld %lld\n",mx,mn); if(mx-mn!=k*(size-1)){puts("No");continue;} ll tmp1=(mx+mn)*size/2,tmp2=(mn*mn%yql*size+mn*k%yql*size%yql*(size-1)%yql+k*k%yql*s[size-1])%yql; // printf("%lld %lld %lld %lld\n",tmp1,sum,tmp2,sumx); if(tmp1==sum&&tmp2==sumx){LastOrder++;puts("Yes");}else puts("No"); } } }