Bzoj 3343: The magic of the bishop's block

Source: Internet
Author: User

3343: Archbishop's Magic time limit:10 Sec Memory limit:256 MB
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. Train of thought: sorting by blocks;
#include <bits/stdc++.h>using namespacestd;#definell Long Long#definePi (4*atan (1.0))Const intn=1e5+Ten, m=1e6+1010, inf=1e9+Ten, mod=1e9+7;Constll inf=1e18+Ten; ll A[m];intn,si,q;ll up[ .];intGetPosintl) {    return(L-1)/si+1;}voidUpdateintLintr,ll c) {    intR= (GetPos (R)-1+ (R%si?)0:1))*si; intL= (GetPos (L)-(l%si==1?1:0)) *si+1; intflag=0;  while(l<L) {A[l]+=C; L++; Flag=1; }    if(flag) sort (a+l-si+1, a+l+1); Flag=0;  while(l<=R) {Up[getpos (L)]+=B; L+=si; }     while(r+1<=r) {a[r+1]+=C; R++; Flag=1; }    if(flag) sort (a+r+1, A+min (n+1, r+si+1));}intQueryintLintr,ll k) {    intans=0; intR= (GetPos (R)-1+ (R%si?)0:1))*si; intL= (GetPos (L)-(l%si==1?1:0)) *si+1;  while(l<L) {if(A[l]+up[getpos (L)]>=k) Ans++; L++; }     while(l<=R) {intPos=lower_bound (A+l,a+l+si,k-up[getpos (L)])-A; Ans+=l+si-POS; L+=si; }     while(r+1<=r) {if(a[r+1]+up[getpos (r+1)]>=k) Ans++; R++; }    returnans;}Charch[Ten];intMain () {scanf ("%d%d",&n,&q); memset (UP,0,sizeof(UP)); Si=sqrt (n);  for(intI=1; i<=n; i++) scanf ("%lld",&A[i]);  for(intI=1; i<=n/si; i++) sort (a+ (I-1) *si+1, a+i*si+1); Sort (a+si* (N/SI) +1, a+n+1);  while(q--)    {        intL,r;        ll C; scanf ("%s%d%d%lld",ch,&l,&r,&c); if(ch[0]=='M') update (L,R,C); Elseprintf ("%d\n", Query (l,r,c)); }    return 0;}

Bzoj 3343: Magical chunking 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.