Bzoj 3343: The magic of the guru

Source: Internet
Author: User

Time Limit:10 Sec Memory limit:256 MB
submit:924 solved:402
[Submit] [Status] [Discuss] DescriptionThe leader 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 the N Heroes gathered together again, this time they were in a row numbered 1, 2 、......、 N. Each person's height begins with a positive integer that does not exceed 1000. The Master's magic each time can be closed interval [ L, R] (1≤ lrN) The height of all the heroes plus an integer W. (although L= R does not conform to the writing specification of the interval, we can think of it as a separate increase in the height of the hero of the L( R))CYZ, light elder brother and Zjq and other people do not worship the evil of the Lord, so they sometimes ask the WD closed interval [ L, R] How many heroes height is greater than or equal to C, to verify that the master's magic is really effective. WD was lazy, so he gave you the task of answering. Input1th Act Two integers N, Q. Q is the sum of the number of questions and the number of spells cast. the 2nd line has N positive integers, and the number of I represents the height of the hero of the first I . 3rd to Q+ 2 each line has an action:(1) If the first letter is "M", then there are three numbers L, R, W. Represents the height of all heroes in the closed interval [ L, R] plus W. (2) If the first letter is "A", then there are three numbers L, R, C. Ask how many heroes in the closed interval [ L, R] are taller than or equal to C. Outputfor each "A" query, the output line contains only one integer, representing the number of heroes in the closed interval [ L, R] that are greater than or equal to C . 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"The data for 30%, N≤1000, Q≤ 1000. for 100% of data, N≤1000000, Q≤3000,1≤ W≤1000,1≤ C≤ 1,000,000,000. The following:   want to use line tree and so on maintenance but every time the C is uncertain, bad processing, had to be divided into pieces to do. Divide the 1~n number per sqrt (n) by one piece, and at the end there may be a separate chunk of the remaining insufficient sqrt (n). A[] represents the initial sequence, b[] is stored in the block of a[] after the ordered result, Add[] is a block inside the accumulation tag. for M operations, L and R if in the same interval, the scope is very small, direct violence modified a[], and then refactor b[], if L and R are not in the same interval, then the whole block part of the interval is directly labeled, the ends may have not the whole block of partial violence modification a[], and then reconstruct b[].
for a operation, L and R if in the same interval, the direct violence judgment, if not, both ends of the violence, the middle part because b[] is orderly, can be solved by two points.
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <cmath>6#include <algorithm>7#include <queue>8#include <vector>9 using namespacestd;TentypedefLong LongLL; One Const intmaxn=1000001; A intN,q,m,block; - intA[MAXN],B[MAXN],POS[MAXN],ADD[MAXN]; - Chars[Ten]; theInlinevoidResetintx) { -     intL= (x1) *block+1, R=min (n,x*block); -      for(inti=l;i<=r;i++) b[i]=A[i]; -Sort (b+l,b+r+1); + } -InlinevoidUpdateintLintRintDelta) { +     if(pos[l]==Pos[r]) { A          for(inti=l;i<=r;i++) a[i]+=Delta; at     } -     Else{ -          for(inti=l;i<=pos[l]*block;i++) a[i]+=Delta; -          for(intI= (pos[r]-1) *block+1; i<=r;i++) a[i]+=Delta; -     } - Reset (pos[l]); reset (Pos[r]); in      for(inti=pos[l]+1; i<=pos[r]-1; i++) add[i]+=Delta; - }  toInlineintFindintLintRintv) { +     if(L +1>=R) { -         if(B[L]&GT;=V)returnl; the         Else returnR; *     } $     intMid= (l+r) >>1;Panax Notoginseng     if(B[MID]&GT;=V)returnfind (l,mid,v); -     Else returnFind (mid+1, r,v); the } +InlineintQueryintLintRintz) { A     intsum=0; the     if(pos[l]==Pos[r]) { +          for(inti=l;i<=r;i++) -             if(a[i]+add[pos[i]]>=z) sum++; $     } $     Else{ -          for(inti=l;i<=pos[l]*block;i++) -             if(a[i]+add[pos[i]]>=z) sum++; the          for(intI= (pos[r]-1) *block+1; i<=r;i++)  -             if(a[i]+add[pos[i]]>=z) sum++;Wuyi     } the      for(inti=pos[l]+1; i<=pos[r]-1; i++){ -sum+= (i*block+1)-find ((I-1) *block+1, i*block+1, Z-add[i]); Wu     } -     returnsum; About } $ intMain () { -scanf"%d%d",&n,&Q); -block=int(sqrt (N)); -      for(intI=1; i<=n;i++){ Ascanf"%d", &a[i]); b[i]=A[i]; +pos[i]= (I-1)/block+1; the     } -     if(n%block!=0) m=n/block+1; $     Elsem=n/Block; the      for(intI=1; i<=m;i++) reset (i); the      while(q--){ the         intx, y, z thescanf"%s%d%d%d",s,&x,&y,&z); -         if(s[0]=='M') update (x, y, z); in         Elseprintf"%d\n", query (x, Y, z)); the     } the     return 0; About}

Bzoj 3343: The magic of the guru

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.