HDU 1754 I Hate It

Source: Internet
Author: User

The line tree solves, similarly, the array of numbers is OK.

Point modification, the interval query is the complexity of LOGN.

There is no use of the bottom-up zkw line segment tree notation, the normal recursive line segment tree.


#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># include<bitset> #include <vector> #include <cmath> #define INF 0x7fffffff#define EPS 1e-8#define LL Long Long#define PI 3.141592654#define CLR (A, B) memset (A,b,sizeof (a)) #define for (I,A,B) for (int i=a;i<b;i++) #define For_ (I,A,B) for (int i=a;i>=b;i--) #define PUB push_back#define PUF push_front#define pob pop_back#define pof pop_front #define MP make_pair#define ft first#define SD second#define SF scanf#define PF printf#define sz (v) ((int) (v). Size ()) #defi NE All (v) (v). Begin (), (v). End () #define ACFUN Std::ios::sync_with_stdio (false) #define SIZE 400000 +1#define MOD 1000000007using namespace Std;int a[size];int _max[size];int n,m;int Build (int o,int l,int R) {if (l==r) return _max[o]=a    [L];    int m= (L+R) >>1; Return _max[o]=max (Build (O*2,l,m), Build (o*2+1,m+1,r));}    int ql,qr;int query (int o,int l,int R) {if (ql<=l&&qr>=r) return _max[o];    int m= (L+R) >>1;    int ans=-inf;    if (ql<=m) Ans=max (Ans,query (o*2,l,m));    if (qr>m) Ans=max (Ans,query (o*2+1,m+1,r)); return ans;}    int site,up;void update (int o,int l,int R) {if (l==r) _max[o]=up;        else {int m= (L+R) >>1;        if (site<=m) update (O*2,L,M);    else update (O*2+1,M+1,R);    _max[o]=max (_max[o*2],_max[o*2+1]);        }}int Main () {while (~SF ("%d%d", &n,&m)) {CLR (_max,0);        for (i,1,n+1) SF ("%d", &a[i]);        Build (1,1,n);        char c;            while (m--) {GetChar ();            SF ("%c", &c);                if (c== ' Q ') {SF ("%d%d", &AMP;QL,&AMP;QR);            PF ("%d\n", Query (1,1,n));                } else if (c== ' U ') {SF ("%d%d", &site,&up);            Update (1,1,N);   }        } }} 


HDU 1754 I Hate It

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.