"Hdoj" 4902 nice boat

Source: Internet
Author: User

Interval segment tree. The title is good.

1 /*  */2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <vector>8#include <algorithm>9#include <cstdio>Ten#include <cmath> One#include <cstring> A#include <climits> -#include <cctype> - using namespacestd; the  - #defineLson L, Mid, rt<<1 - #defineRson mid+1, R, rt<<1|1 - #defineMAXN 100005 +  -typedefstruct { +     intmx, Val; A } node_t; at  -node_t t[maxn<<2]; - intN, m, X; - intl; -  - intgcdintNintm) { in     if(M = =0) -         returnN; to     if(M >N) +         returngcd (M, n); -     returnGCD (M, n%m); the } *  $ voidPushup (intRT) {Panax NotoginsengT[rt].val = t[rt<<1].val==t[rt<<1|1].val? t[rt<<1].val:-1; -t[rt].mx = Max (t[rt<<1].mx, t[rt<<1|1].mx); the } +  A voidPushdown (intRT) { the     if(T[rt].val >=0) { +t[rt<<1].val = t[rt<<1|1].val =T[rt].val; -t[rt<<1].mx = t[rt<<1|1].mx =t[rt].mx; $     } $ } -  - voidBuildintLintRintRT) { the     if(L = =r) { -scanf"%d", &t[rt].val);Wuyit[rt].mx =T[rt].val; the         return ; -     } Wu     intMid = (l+r) >>1; - build (Lson); About build (Rson); $ pushup (RT); - } -  - voidUpdate1 (intllintRrintLintRintRT) { A     if(Ll<=l && rr>=r) { +T[rt].val =x; thet[rt].mx =x; -         return ; $     } the     intMid = (l+r) >>1; the pushdown (RT); the     if(RR <=mid) { the update1 (LL, RR, Lson); -}Else if(LL >mid) { in update1 (LL, RR, Rson); the}Else { the Update1 (ll, Mid, Lson); AboutUpdate1 (mid+1, RR, Rson); the     } the pushup (RT); the } +  - voidUpdate2 (intllintRrintLintRintRT) { the     if(T[rt].mx <=x)Bayi         return ; the     intMid = (l+r) >>1; the     if(Ll<=l && rr>=r) { -         if(T[rt].val >=0) { -T[rt].val =gcd (T[rt].val, x); thet[rt].mx =T[rt].val; the}Else { the Update2 (LL, RR, Lson); the Update2 (LL, RR, Rson); - pushup (RT); the         } the         return ; the     }94 pushdown (RT); the     if(RR <=mid) { the Update2 (LL, RR, Lson); the}Else if(LL >mid) {98 Update2 (LL, RR, Rson); About}Else { - Update2 (ll, Mid, Lson);101Update2 (mid+1, RR, Rson);102     }103 pushup (RT);104 } the 106 voidPrintall (intLintRintRT) {107     if(T[rt].val >=0) {108          for(intI=l; i<=r; ++i)109printf"%d", t[rt].val); the         return ;111     } the     intMid = (l+r) >>1;113 printall (Lson); the printall (Rson); the } the 117 intMain () {118     intI, J, K;119     intL, R; -     intT;121 122 #ifndef Online_judge123Freopen ("data.in","R", stdin);124Freopen ("Data.out","W", stdout); the     #endif126 127scanf"%d", &t); -      while(t--) {129scanf"%d", &n); theBuild1N1);131scanf"%d", &m); the          while(m--) {133scanf"%d %d%d%d", &k, &l, &r, &x);134             if(k = =1) {135Update1 (L, R,1N1);136}Else {137Update2 (L, R,1N1);138             }139         } $Printall (1N1);141Putchar ('\ n');142     }143 144     return 0;145}

"Hdoj" 4902 nice boat

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.