There is always a problem in the posture of the block, to find the Hzwer board;
Bzoj 3343 1 //bzoj 3343
2
3
4#include <stdio.h>
5#include <algorithm>
6#include <string.h>
7#include <math.h>
8#include <string>
9#include <iostream>
TenusingnamespaceStd
OnetypedefLongLongll
A
-#defineN 1000002
-
the
-intA[n],b[n],pos[n],add[n];
- intN,q,block,m;
-
+
-voidResetintX//sort within a block
+{
AintL= (x1) *block+1;
atintR=min (Block*x,n);
- for(inti=l;i<=r;i++) B[i]=a[i];
-Sort (b+l,b+r+1);
-}
-
-voidUpdateintXintYintV
in{
-if(Pos[x]==pos[y])
to for(inti=x;i<=y;i++) A[i]=a[i]+v;
+Else
-{
the for(inti=x;i<=pos[x]*block;i++) A[i]=a[i]+v;
* for(intI= (pos[y]-1) *block+1; i<=y;i++) A[i]+=v;
$}
Panax NotoginsengReset (pos[x]);
-Reset (Pos[y]);
the for(inti=pos[x]+1; i<pos[y];i++) Add[i]+=v;
+}
AintFindintXintV//within each block two points
the{
+intL= (x1) *block+1, R=min (X*block,n);
-intLast=r;
$ while(L<=R)
${
-intMid= (l+r) >>1;
-if(B[MID]<V) l=mid+1;
theElser=mid-1;
-}
Wuyireturnlast-l+1;
the}
-
WuintQueryintXintYintV
-{
Aboutintsum=0;
$if(Pos[x]==pos[y])//within a block
-{
- for(inti=x;i<=y;i++)
-if(a[i]+add[pos[i]]>=v) sum++;
A}
+ Else//violent treatment on both ends
the{
- for(inti=x;i<=pos[x]*block;i++)
$if(a[i]+add[pos[i]]>=v) sum++;
the for(intI= (pos[y]-1) *block+1; i<=y;i++)
theif(a[i]+add[pos[i]]>=v) sum++;
the}
the for(inti=pos[x]+1; i<pos[y];i++)//two points for each block
-Sum+=find (I,v-add[i]);
inreturnSum
the}
the
About intMain ()
the{
thescanf"%d%d", &n,&q);
theBLOCK=SQRT (n);//How many are there per block?
+ for(intI=1; i<=n;i++)
-{
thescanf"%d", &a[i]);
Bayipos[i]= (I-1)/block+1;//in which block
the}
theif(N%block) m=n/block+1;
-ElseM=n/block;
- for(intI=1; i<=m;i++) reset (i);
the while(q--)
the{
theChars[4];
theintX,y,v;
-scanf"%s%d%d%d", s,&x,&y,&v);
theif(s[0]=='M') update (X,Y,V);
theElseprintf"%d\n", query (X,Y,V));
the}
94return0;
the}
Block Dafa Good