HDU 4027 (segment tree)

Source: Internet
Author: User

HDU4027

Test Instructions : The operation instruction is 0 o'clock, the number between the interval [x, y] is opened square, the instruction is 1, the interval [x, y] between the number of the sum and output;

idea : Line tree processing is OK, but the number of 64 bits in the maximum open 8 times the square is 1 (start not to believe, after trying to orz ... ), so at the time of the square, add a limit to allow the square operation to end prematurely without the necessary operation, otherwise it will time out.

This sentence in the code: EN-ST + 1 = = Evil[rt] Indicates that all the numbers in the range St to EN are 1, so it can be ended prematurely.

Code:

/*time:2018/8/20 author:sykai1 funtion:solve HDU 4027*/#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<queue>#include<vector>#include<algorithm>#defineINF 0x3f3f3f3fusing namespaceStd;typedefLong LongLl;typedef pair<Double,int>P;Const intMAXN = 2e5 +Ten; ll Evil[maxn*4];intN;voidBuild (intRtintStinten) {    if(St = =en) {scanf ("%i64d", &Evil[rt]); return; }    intMid = (st + en)/2; Build (Rt<<1, St, mid); Build (Rt<<1|1, Mid +1, en); EVIL[RT]= Evil[rt <<1] + evil[rt <<1|1];}voidADD (intRtintXintYintStinten) {    if(St = =en) {Evil[rt]=(LL) sqrt (Evil[rt]); return; }    if(En-st +1==Evil[rt]) {printf ("GG%d\n", Evil[rt]); return; }    intMid = (st + en)/2; if(Y <=mid) Add (RT<<1, X, Y, St, mid); Else if(X >mid) Add (RT<<1|1, X, Y, Mid +1, en); Else{Add (rt<<1, X, Mid, St, mid); ADD (Rt<<1|1, Mid +1, Y, Mid +1, en); } Evil[rt]= Evil[rt <<1] + evil[rt <<1|1];} ll query (intRtintXintYintStinten) {LL res=0; if(x = = St && y = =en)returnEvil[rt]; intMid = (st + en)/2; if(Y <=mid) Res= Query (RT <<1, X, Y, St, mid); Else if(X >mid) Res= Query (RT <<1|1, X, Y, Mid +1, en); Else{res= Query (RT <<1, X, Mid, St, mid); Res+ = query (RT <<1|1, Mid +1, Y, Mid +1, en); }    returnRes;}intMain () {intCNT =0;  while(SCANF ("%d", &n)! =EOF) {printf ("Case #%d:\n", ++CNT); Build (1,1, N); intq, OP, x, y; scanf ("%d", &q);  for(inti =0; i < Q; i++) {scanf ("%d%d%d", &op, &x, &y); if(X >y) Swap (x, y); if(OP = =0) Add (1, X, Y,1, N); Else{printf ("%lld\n", Query (1, X, Y,1, N)); }} printf ("\ n"); }    return 0;}
View Code

HDU 4027 (segment tree)

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.