BZOJ4373: Arithmetic genius ⑨ and arithmetic progression

Source: Internet
Author: User

Description

Arithmetic genius ⑨ like to play with arithmetic progression very much.
One day, he gave you a sequence of length n, where the number of I is a[i].
He wants to test you, every time he will give an inquiry l,r,k, ask the interval [l,r] in the number from small to large, can form a tolerance of k arithmetic progression.
Of course, he will constantly revise one of these items.
In order not to be despised by him, you have to answer all the questions quickly and correctly.
Note: Only one number of the series is also arithmetic progression.

Input

The first line contains two positive integer n,m (1<=n,m<=300000), each representing the length of the sequence and the number of operations.
The second line contains n integers, which in turn represent each number in the sequence A[i] (0<=a[i]<=10^9).
Next m line, each line starts with a number OP,
If Op=1, then the next two integers, X, y (1<=x<=n,0<=y<=10^9), indicate A[X] is modified to Y.
If op=2, then the next three integers, l,r,k (1<=l<=r<=n,0<=k<=10^9), represent a query.
In the subject, the x,y,l,r,k are encrypted and need to be decrypted by different or the number of yes you have previously output.

Output

Output a number of lines, for each query, if you can form arithmetic progression, then output yes, otherwise output No.

Sample Input5 3
1 3 2) 5 6
2 1 5 1
1 5 4
2 1 5 1Sample OutputNo
YesWOC original line segment tree to open 4 times times space, then I noi when is how to come over?????? OrzQiancl Big Uncle Hash violence Dafa Good ... The http://qiancl.is-programmer.com/posts/192245.html is very detailed.
#include <cstdio>#include<cctype>#include<queue>#include<cmath>#include<cstring>#include<algorithm>#defineRep (i,s,t) for (int i=s;i<=t;i++)#defineDwn (i,s,t) for (int i=s;i>=t;i--)#defineren for (int i=first[x];i;i=next[i])using namespacestd;Const intBuffersize=1<< -;Charbuffer[buffersize],*head,*Tail;inlineCharGetchar () {if(head==tail) {        intL=fread (Buffer,1, Buffersize,stdin); Tail= (Head=buffer) +l; }    return*head++;} InlineintRead () {intx=0, f=1;CharC=Getchar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;} typedef unsignedLong Longull;Const intmaxn=300010; ull SUMV[MAXN*4],sum,mn;intminv[maxn*4],lastans;voidBuildintOintLintr) {if(l==r) Minv[o]=read (), sumv[o]= (ull) minv[o]*Minv[o]; Else {        intMid=l+r>>1,lc=o<<1, rc=lc|1; Build (Lc,l,mid); Build (Rc,mid+1, R); Minv[o]=min (MINV[LC],MINV[RC]); Sumv[o]=sumv[lc]+SUMV[RC]; }}voidUpdateintOintLintRintPOS) {    if(l==r) Minv[o]=read () ^lastans,sumv[o]= (ull) minv[o]*Minv[o]; Else {        intMid=l+r>>1,lc=o<<1, rc=lc|1; if(pos<=mid) Update (LC,L,MID,POS); ElseUpdate (rc,mid+1, R,pos); Minv[o]=min (MINV[LC],MINV[RC]); Sumv[o]=sumv[lc]+SUMV[RC]; }}voidQueryintOintLintRintQlintqr) {    if(QL&LT;=L&AMP;&AMP;R&LT;=QR) sum+=sumv[o],mn=min (Mn, (ull) minv[o]); Else {        intMid=l+r>>1,lc=o<<1, rc=lc|1; if(ql<=mid) query (LC,L,MID,QL,QR); if(qr>mid) query (rc,mid+1, R,QL,QR); }}intMain () {intN=read (), m=read (); Build (1,1, N);  while(m--) {        if(read () = =1) Update (1,1, N,read () ^Lastans); Else {            intL=read () ^lastans,r=read () ^lastans,v=read () ^Lastans; Ull Len=r-l+1; mn=2e9;sum=0; Query (1,1, N,l,r); ull Res=len*mn* (mn+ (len-1) *v) +len* (len-1)*(2*len-1)/6*v*v; if(Res==sum) puts ("Yes"), lastans++; ElsePuts"No"); }    }    return 0;}
View Code

BZOJ4373: Arithmetic genius ⑨ and arithmetic progression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.