Topic links
The main topic: give you n number, give two operations, a kind to you L, R, K, ask you [L, r] interval in the number of the order can constitute a tolerance of k arithmetic progression. The other is to change the number of positions X to Y. Force online.
You can use a hash to save the minimum value in a range, and the sum of the squares with a segment tree. Then each time asked, assuming that this interval constitutes arithmetic progression, then the first term is the minimum value of this interval, and then by the formula to calculate the Minn, K for the tolerance of the sum of the series, for a1*len+len* (len-1)/2*d, and then calculate the sum of squares, the equivalent of Sigma (i:0 to len-1) (a1+i*d) ^2, and then take it apart, it becomes a1*a1*len+a1*d*len* (len-1) +d*d*len* (len-1) * (2*len-1)/6, remember the time to take the mold to prevent explosion Longlong,/6 where the multiplication inverse of the calculation. And see if it's equal.
The positive solution is certainly not the case.
#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<Set>#include<string>#include<queue>#include<stack>#include<bitset>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<1|1#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (i, N, a) for (int i = A; i<n; i++)#defineFi first#defineSe Secondtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Constll mod = 1e9+7;Constll inf =1e18;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };Const intMAXN = 3e5+5; ll Sum1[maxn<<2], sum2[maxn<<2], minn[maxn<<2], ans1, Ans2, ANS3;voidPushup (intRT) {Sum1[rt]= sum1[rt<<1]+sum1[rt<<1|1]; SUM2[RT]= (sum2[rt<<1] + sum2[rt<<1|1])%MoD; MINN[RT]= Min (minn[rt<<1], minn[rt<<1|1]);}voidBuildintLintRintRT) { if(L = =r) {scanf ("%i64d", &Sum1[rt]); MINN[RT]=Sum1[rt]; SUM2[RT]= sum1[rt]*sum1[rt]%MoD; return ; } intm = l+r>>1; Build (Lson); Build (Rson); Pushup (RT);}voidUpdateintP, LL Val,intLintRintRT) { if(L = =R) {Sum1[rt]= Minn[rt] =Val; SUM2[RT]= val*val%MoD; return ; } intm = l+r>>1; if(p<=m) Update (p, Val, Lson); ElseUpdate (P, Val, Rson); Pushup (RT);}voidQueryintLintRintLintRintRT) { if(l<=l&&r>=r) {ans1+=Sum1[rt]; Ans2= (Ans2+sum2[rt])%MoD; ANS3=min (ans3, minn[rt]); return ; } intm = l+r>>1; if(l<=m) query (L, R, Lson); if(r>m) query (L, R, Rson);} ll Pow (ll A, ll b) {LL ret=1; while(b) {if(b&1) {ret= ret*a%MoD; } A= a*a%MoD; b>>=1; } returnret;} ll Get1 (ll A1, LL L, ll D) {LL ret= a1*l+l* (l1)/2*D; returnret;} ll Get2 (ll A1, LL L, ll D) {LL ret= a1*a1%mod*l%MoD; ll Rev= Pow (6LL, mod-2)%MoD; RET= (ret + d*d%mod*l%mod* (L-1)%mod* (2*l-1)%mod*rev%mod)%MoD; RET= (ret + a1*d%mod*l%mod* (L-1)%mod)%MoD; returnret%MoD;}intMain () {intN, m, cnt =0, sign, x, Y, Z; CIN>>n>>m; Build (1N1); while(m--) {scanf ("%d%d%d", &sign, &x, &y); X^= cnt, y ^=CNT; if(Sign = =1) {update (x, 1LL*y,1N1); } Else{scanf ("%d", &z); Z^=CNT; ANS3= inf, ans1 = ANS2 =0; Query (x, Y,1N1); ll TMP1= Get1 (ANS3, y-x+1, z); ll TMP2= Get2 (ANS3, y-x+1, z); if(TMP1 = = ans1 && TMP2 = =ans2) {CNT++; Puts ("Yes"); } Else{puts ("No"); } } } return 0;}
Bzoj 4373: Arithmetic genius ⑨ and arithmetic progression hash