POJ 3225 (segment tree interval update) help with intervals

Source: Internet
Author: User

This problem has been engaged for a long time, in fact there are many pits point.

On the internet to find a lot of solutions, found that the idea is actually similar, so it is not repeated.

Recommend a better one, please poke this.

In addition, if it is possible to update multiple times, but the final query only needs one time, there is no write pushup function, only one pushdown.

1#include <cstdio>2 3 Const intMAXN =131072;4 //const int MAXN = ten;5 intQL, QR, op;6 intSETV[MAXN <<2], XORV[MAXN <<2];7 BOOL inch[Maxn +Ten];8 9 voidPushdown (into)Ten { One     intLC = o*2, rc = o*2+1; A     if(Setv[o] >=0) -     { -SETV[LC] = SETV[RC] =Setv[o]; theSetv[o] =-1; -XORV[LC] = XORV[RC] =0; -     } -     if(Xorv[o]) +     { -         if(SETV[LC] >=0) SETV[LC] ^=1;ElseXORV[LC] ^=1; +         if(SETV[RC] >=0) SETV[RC] ^=1;ElseXORV[RC] ^=1; AXorv[o] =0; at     } - } -  - voidUpdateintOintLintRintQlintQR) - { -     if(QL <= L && QR >=R) in     { -         if(OP = =1) {Setv[o] = xorv[o] =0; } to         Else if(OP = =2) {Setv[o] =1; Xorv[o] =0; } +         Else if(OP = =3) {if(Setv[o] >=0) Setv[o] ^=1;ElseXorv[o] ^=1; } -         return; the     } *     intM = (L + R)/2; $ pushdown (o);Panax Notoginseng     if(QL <= M) Update (o*2, L, M, QL, QR); -     if(QR > M) Update (o*2+1, m+1, R, QL, QR); the } +  A voidQueryintOintLintR) the { +     if(Setv[o] >=0) -     { $         if(Setv[o] = =1) for(inti = L; I <= R; i++)inch[I] =true; $         return; -     } - pushdown (o); the     if(L = = R)return; -     intM = (L + R)/2;WuyiQuery (o*2, L, M); theQuery (o*2+1, m+1, R); - } Wu  - Charcmd, _left, _right; About  $ intMain () - { -     //freopen ("In.txt", "R", stdin); -  A      while(SCANF ("%c%c%d,%d%c\n", &cmd, &_left, &AMP;QL, &AMP;QR, &_right) >=0) +     { theQL <<=1; QR <<=1; -         if(_left = ='(') ql++;if(_right = =')') qr--; $         if(QL > QR && (cmd = ='I'|| cmd = ='C')) {setv[1] =0; xorv[1] =0;Continue; } the         if(cmd = ='U') {op =2; Update1,0, MAXN, QL, QR); } the         Else if(cmd = ='I') the         { theOP =1; -             if(QL-1>=0) Update (1,0, MAXN,0, ql-1); in             if(QR +1<= maxn) Update (1,0, MAXN, qr+1, MAXN); the         } the         Else if(cmd = ='D') {op =1; Update1,0, MAXN, QL, QR); } About         Else if(cmd = ='C') the         { theOP =1; the             if(QL-1>=0) Update (1,0, MAXN,0, ql-1); +             if(QR +1<= maxn) Update (1,0, MAXN, qr+1, MAXN); -OP =3; theUpdate1,0, MAXN, QL, QR);Bayi         } the         Else if(cmd = ='S') {op =3; Update1,0, MAXN, QL, QR); } the     } -Query1,0, MAXN); -     BOOLPrint =false; the     ints =-1, E; the      for(inti =0; I <= MAXN; i++) the     { the         if(inch[i]) -         { the             if(s = =-1) s =i; theE =i; the         }94         Else if(s! =-1) the         { the             if(print) printf (" "); thePrint =true;98printf"%c%d,%d%c", s&1?'(':'[', s>>1, (e+1) >>1, e&1?')':']'); Abouts =-1; -         }101     }102 103     if(!print) puts ("Empty Set");104  the     return 0;106}
code June

POJ 3225 (segment tree interval update) help with intervals

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.