Back Gear | Loyal 2|zkw line tree

Source: Internet
Author: User

Line tree, we see a look at it, this problem is a template problem, I learn zkw line segment tree used. Single point of Maintenance, Interval max.
The topic is the loyalty of TYVJ 2.

#include"iostream"#include"Cstdio"using namespacestd;intM;intt[10000000];intRead () {CharC=GetChar (); intA=0;  while(c<'0'|| C>'9') c=GetChar ();  while(c>='0'&&c<='9') {a=a*Ten+c-'0'; C=GetChar (); }    returnA;}voidBuild (intN) {         for(m=1; m<=n+1; m*=2);//m indicates the total number of nodes (branch + root), of course, here is the default he is full of two fork tree     for(intI=1+m; i<=n+m; i++) t[i]=read ();  for(intj=n-1; I i--) T[i]=min (t[i*2],t[i*2+1]);}intAskintAintb) {    intans=111111117; //cout << 1 << endl;     for(a=a+m-1, b=b+m+1; a^b^1; A/=2, b/=2)    {    //change the query interval from [s,t] to (s-1,t+1) for easy handling//s^t^1 If =0 then s and T only the last one is different, that is, s and t have a father        if(a%2==0) Ans=min (ans,t[a^1]);//If S is the left subtree, the maximum value is the original maximum and the big one in the right subtree.        if(b%2==1) Ans=min (ans,t[b^1]);//vice versa    }    returnans;}voidChangeintXinty) {     for(t[x+=m]=y,x/=2; X X/=2) T[x]=min (t[2*x],t[2*x+1]); }intMain () {intn,m; M=read (); n=read ();    Build (m);  for(intI=1; i<=n; i++)    {        intA=read (), X=read (), y=read (); if(a==1) {cout << ask (x, y) <<' '; }            Else{change (x, y); }    }    return 0;}

Back Gear | Loyal 2|zkw line 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.