bzoj3343: The magic of the guru

Source: Internet
Author: User

Block Posture Exercises

#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> #include <cmath >using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define    CLR (x,c) memset (x,c,sizeof (x)) int read () {int X=0,f=1;char c=getchar ();    while (!isdigit (c)) {if (c== '-') F=-1;c=getchar ();    } while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x*f;} const int Nmax=1e6+5;int a[nmax],b[nmax],bel[nmax],add[nmax],n,m,bck;char s[10];void Reset (int x) {int l= (x-1) *bck+1,r    =min (X*bck,n);    Rep (i,l,r) b[i]=a[i]; Sort (b+l,b+r+1);}    void update (int u,int V,int d) {if (Bel[u]==bel[v]) {Rep (i,u,v) A[i]+=d;reset (Bel[u]);        }else{Rep (i,u,bel[u]*bck) A[i]+=d;        Rep (I, (bel[v]-1) *bck+1,v) A[i]+=d;    Reset (Bel[u]); reset (Bel[v]); } Rep (i,bel[u]+1,bel[v]-1) Add[i]+=d;}    int find (int x,int d) {int l= (x-1) *bck+1,r=x*bck,mid,ans=r+1,res=r;        while (l<=r) {mid= (l+r) >>1; IF (b[mid]>=d) ans=mid,r=mid-1;    else l=mid+1; } return res-ans+1;}    int query (int u,int v,int d) {int ans=0;        if (Bel[u]==bel[v]) {int tmp=add[bel[u]];    Rep (i,u,v) if (A[i]+tmp>=d) ans++;        }else{int tmp=add[bel[u]],temp=add[bel[v]];        Rep (i,u,bel[u]*bck) if (A[i]+tmp>=d) ans++;    Rep (I, (bel[v]-1) *bck+1,v) if (A[i]+temp>=d) ans++;    } Rep (i,bel[u]+1,bel[v]-1) Ans+=find (I,d-add[i]); return ans;}    int main () {N=read (), M=read (), bck= (int) sqrt (n); int u,v,d;    Rep (I,1,n) B[i]=a[i]=read (), bel[i]= (i-1)/bck+1;    int sum= (n%bck==0)? n/bck:n/bck+1;    Rep (i,1,sum-1) sort (b + (i-1) *bck+1,b+i*bck+1);    Sort (b + (sum-1) *bck+1,b+n+1);        Rep (i,1,m) {scanf ("%s", s), U=read (), V=read (), D=read ();        if (s[0]== ' M ') update (U,V,D);    else printf ("%d\n", Query (U,v,d)); } return 0;}

  

3343: Archbishop's Magic time limit:10 Sec Memory limit:256 MB
submit:1063 solved:467
[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.

Source [Submit] [Status] [Discuss]

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.