HDU 1754 I Hate It segment Tree single point update interval max

Source: Internet
Author: User

1#include <iostream>2#include <string>3#include <algorithm>4#include <cstdlib>5#include <cstdio>6#include <Set>7#include <map>8#include <vector>9#include <cstring>Ten#include <stack> One#include <cmath> A#include <queue> -#include <bits/stdc++.h> - using namespacestd; the  - intmax[4000001]; - //int max (int a,int b) - //{ + //return a>b?a:b; - //} + voidPushup (intRT) A { atMax[rt]=max (max[rt<<1],max[(rt<<1)+1]); - } - voidBuildintLintRintRT) - { -     if(l==R) -     { inscanf"%d",&Max[rt]); -         return; to     } +     intM= (l+r) >>1; -Build (l,m,rt<<1); theBuild (m+1, R, (rt<<1)+1); * pushup (RT); $ }Panax Notoginseng voidUpdateintPintQintLintRintRT) - { the     if(l==R) +     { Amax[rt]=Q; the         return; +     } -     intM= (l+r) >>1; $     if(p<=m) $Update (p,q,l,m,rt<<1); -     Else -Update (p,q,m+1, R, (rt<<1)+1); the pushup (RT); - }Wuyi intGetmax (intLintRintLintRintRT) the { -     if(l<=l&&r<=R) Wu         returnMax[rt]; -     intM= (r+l) >>1; About     intret=0; $     if(l<=m) -Ret=max (Ret,getmax (l,r,l,m,rt<<1)); -     if(r>m) -Ret=max (Ret,getmax (l,r,m+1, R, (rt<<1)+1)); A     returnret; + } the intMain () - { $     intn,m,a,b,i; the     CharC; the      while(~SCANF ("%d%d",&n,&m)) the     { theBuild1N1); -          for(i=0; i<m; i++) in         { thescanf"%*c%c%d%d", &c,&a,&b);//*c is the same as GetChar . the             if(c=='Q') Aboutprintf"%d\n", Getmax (A, B,1N1)); the             Else theUpdate (A, B,1N1); the         } +     } -     return 0; the}
View Code

HDU 1754 I Hate It segment Tree single point update interval maximum

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.