Bzoj 3343: The magic of the Guru [chunking] "Learning notes"

Source: Internet
Author: User

3343: Archbishop's Magic time limit:10 Sec Memory limit:256 MB
submit:1172 solved:526
[Submit] [Status] [Discuss] Description has recently learned a magical magic that can make a person grow taller. So he was ready to demonstrate to each hero of the Xmyz Information Group. So NHeroes gathered together again, this time they lined up in a row numbered 1, 2 、......、 N。 Each person's height begins with a positive integer that does not exceed 1000. The magic of the bishop can turn the closed interval [ L, R] (1≤ LRNThe height of the hero in all plus an integer W。 (Although L= RNot conform to the written specification of the interval, but we may consider it a separate addition to the LRThe height of a hero) CYZ, Brother Guang and ZJQ are not religious, so they sometimes ask the WD closed zone [ L, R] Inside how many heroes are taller than equals CTo verify that the magic of the Guru is really effective. WD was lazy, so he gave you the task of answering. Input 1th Behavior two integers NQQSum of the number of questions and the number of spells cast by the Guru. Line 2nd has NA positive integer, section INumber represents the first IThe height of a hero. 3rd to No. Q+2 rows have one operation per line: (1) If the first letter is "M", then there are three digits LRW。 Indicates the closed interval [ L, R] All the hero's height plus W。 (2) If the first letter is "A", then there are three digits LRC。 Ask the closed interval [ L, R] How many heroes are taller than equals in height C。 Output for each "a" query outputs a line with only one integer, indicating the closed interval [ L, R] inside height is greater than or equal to CNumber of Heroes. Sample Input5 3
1 2 3) 4 5
A 1 5 4
M 3 5 1
A 1 5 4
Sample Output2
3
HINT

"Input and Output sample description"
The original 5 heroes were 1, 2, 3, 4, 5, and at this time [1, 5] There were 2 heroes taller than or equal to 4. The master cast to 1, 2, 4, 5, 6, at this time [1, 5] There are 3 heroes taller than or equal to 4.

"Data Range"
For 30% of the data, N≤1000, Q≤1000.
For 100% of the data, N≤1000000, Q≤3000,1≤ W≤1000,1≤ C≤1,000,000,000. Simple thought, the chairman of the tree is not good to do, MO team is not good to do (inquiry between the bad transfer)then the violence is divided.BL is the size of the block, M is the number of blocks, pos[i] is the number of the block I reside inthe B-array maintains each block in a well-orderedAdd Operation:1. The same piece of violence modified and then reconstructed2. Both ends of the incomplete violence modification refactoring, the middle complete block plus MarkQuery operation:1. The same piece of violence2. Two ends of violence, middle in B binary searchQuestions:1. Pay attention to two points to find the wording, find greater than or equal to 2.l= (x-1) *bl+1,r=min (x*bl,n) 3. Do not omit/ add more pos
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespaceStd;typedefLong Longll;Const intn=1e6+5, m=1e3+5; inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intn,q,bl,m,a[n],pos[n],b[n],add[m],x,y,z;Chars[Ten];voidResetintx) {    intL= (x1) *bl+1, R=min (x*bl,n);  for(inti=l;i<=r;i++) b[i]=A[i]; Sort (b+l,b+r+1);}voidChangeintLintRintv) {    if(pos[l]==Pos[r]) {         for(inti=l;i<=r;i++) a[i]+=v;    Reset (Pos[l]); }Else{        intt=pos[l]*BL;  for(inti=l;i<=t;i++) a[i]+=v;  for(intI= (pos[r]-1) *bl+1; i<=r;i++) a[i]+=v;        Reset (pos[l]); reset (Pos[r]);  for(inti=pos[l]+1; i<pos[r];i++) add[i]+=v; }}inlineintFindintXintv) {    intL= (x1) *bl+1, R=min (x*bl,n), t=R;  while(l<=R) {        intMid= (l+r) >>1; if(B[MID]&LT;V) l=mid+1; Elser=mid-1; }    returnt-l+1;}intQueryintLintRintv) {    intans=0; if(pos[l]==Pos[r]) {          for(inti=l;i<=r;i++)if(A[I]+ADD[POS[I]]&GT;=V) ans++; returnans; }Else{        intt=pos[l]*BL;  for(inti=l;i<=t;i++)if(A[I]+ADD[POS[I]]&GT;=V) ans++;  for(intI= (pos[r]-1) *bl+1; i<=r;i++)if(A[I]+ADD[POS[I]]&GT;=V) ans++;  for(inti=pos[l]+1; i<pos[r];i++) Ans+=find (i,v-Add[i]); returnans; }}intMain () {n=read (); q=read (); BL=sqrt (n); M=N/BL;if(N%BL) m++;  for(intI=1; i<=n;i++) A[i]=read (), pos[i]= (i-1)/bl+1;  for(intI=1; i<=m;i++) reset (i);  while(q--) {scanf ("%s", s); X=read (); Y=read (); z=read (); if(s[0]=='M') Change (x, y, z); Elseprintf"%d\n", query (x, Y, z)); }}

Bzoj 3343: The magic of the Guru [chunking] "Learning notes"

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.