Block Dafa Good

Source: Internet
Author: User

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&LT;=R)
${
-intMid= (l+r) >>1;
-if(B[MID]&LT;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

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.