"bzoj3343", "the magic of the Guru."

Source: Internet
Author: User

3343: Guru's Magic Time limit: Sec Memory limit: + MB
Submit: 441 Solved: 198
[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 problem is a moderately difficult chunk, and two points.

We can divide the number of inputs into sqrt (n) blocks, and we can easily think of changes that can be added to the whole block directly plus the modified number for non-whole block violence.

Query, for the whole block is also a violent query. But the trouble is the whole piece of how we go to query.

At first I thought of going to two points, but the process of two points each need to be relative to a block order, so that will time out, how to do?

We can think of an array that can be opened outside to record the number of sequential orders for each block. Then we just need to sort the two incomplete two blocks two times at the time of the modification, so we can sort them up by 4m.

It is important to note that in the case of brute force search, we cannot simply judge the original sequence of changes, because we will miss out on the entire fast-changing mark, and use these tags for violence.

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace STD; #include <cmath>int n,m,a[1000010]={0},len,n=1,block[1500]={0};struct s{int va,no;} B[1000010];char ch;bool cmpva (S x,s y) {return x.va<y.va;} BOOL Cmpno (S x,s y) {return x.no<y.no;} #define MID (L+r)/2int the_dichotomy (int l,int r,int high) {int ans=0;if (L==R) return l; if (High<=b[mid].va) Ans=the_di  Chotomy (L,mid,high); else ans=the_dichotomy (Mid+1,r,high); return ans;} int main () {int i,j,x,y,z;scanf ("%d%d", &n,&m), for (I=1;i<=n;++i) {scanf ("%d", &a[i]); b[i].va=a[i];b[i ]. No=i;} LEN=SQRT (n); while (1) {n+=1;if (n*len>=n) break;} for (i=1;i<=n;++i) sort (b + (i-1) *len+1,b+min (i*len+1,n+1), CMPVA), while (m--) {cin>>ch;scanf ("%d%d%d",& X,&AMP;Y,&AMP;Z); int l,r,ll,rr;l= (x%len==0)? (X/len):(x/len+1); r= (y%len==0)? (Y/len):(y/len+1) ll=len* (L-1) +1==x?l:l+1;rr=y%len==0?r:r-1;if (ch== ' M ') {if (LL&LT;=RR) {for (i=ll;i<=rr;++i) Block[i]+=z;if (l<ll) {sort (b + (L-1) *len+1,b+l*len+1,cmpno); for (i=x;i<=l*len;++i) B[i].va+=z,a[i]+=z;sort (b + (L-1) *LEN+1,B+L*LEN+1,CMPVA);} if (rr<r) {sort (b+rr*len+1,b+min (r*len+1,n+1), cmpno); for (I=rr*len+1;i<=y;++i) B[i].va+=z,a[i]+=z;sort (b+rr* Len+1,b+min (r*len+1,n+1), CMPVA);}} Else{if (l==r) {sort (b + (L-1) *len+1,b+min (l*len+1,n+1), Cmpno), for (I=x;i<=y;++i) B[i].va+=z,a[i]+=z;sort (b + (L-1) *len+1,b+min (l*len+1,n+1), CMPVA);} Else{sort (b + (L-1) *len+1,b+l*len+1,cmpno); sort (b + (r-1) *len+1,b+min (r*len+1,n+1), cmpno); for (I=x;i<=y;++i) B[i] . Va+=z,a[i]+=z;sort (b + (L-1) *len+1,b+l*len+1,cmpva); sort (b + (r-1) *len+1,b+min (r*len+1,n+1), CMPVA);} }}else{int ans=0;if (LL&LT;=RR) {for (i=ll;i<=rr;++i) {int left= (i-1) *len+1,right=min (i*len,n), High=z-block[i], Number;if (B[left].va>=high) {ans+=right-left+1;continue;} if (B[right].va

"bzoj3343", "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.