HDU 1754 line segment tree

Source: Internet
Author: User

[Cpp] <span style = "font-size: 32px; "> # include <iostream> # include <string> # include <cstring> # include <algorithm> # include <cstdio> # include <cmath> # include <cctype> # include <iomanip> # define Lson left, t, rt <1 # define Rson t + 1, right, rt <1 | 1 using namespace std; const int maxn = 200005; int f [maxn <2]; void PushUP (int rt) {f [rt] = max (f [rt <1], f [rt <1 | 1]);} void build (int left, int right, int rt) {if (left = right) {cin> f [rt]; return;} int t = (left + right)> 1; build (Lson); build (Rson); PushUP (rt);} void update (int ii, int value, int left, int right, int rt) {if (left = right) {f [rt] = value; return;} int t = (left + right)> 1; if (ii <= t) update (ii, value, Lson); else update (ii, value, Rson); PushUP (rt);} int query (int l, int r, int left, int right, int rt) {if (l <= left & r> = right) return f [rt]; int t = (left + right)/2; int ret = 0; if (l <= t) ret = max (ret, query (l, r, Lson); if (r> t) ret = max (ret, query (l, r, Rson); return ret;} int main () {int n, m; while (cin >>n> m) {build (1, n, 1 ); while (m --) {char C; int a, B; // for (int I = 0; I <= n; ++ I) cout <f [I] <''; cout <endl; cin> C> a> B; if (C = 'q ') cout <query (a, B, 1, n, 1) <endl; else update (a, B, 1, n, 1) ;}} return 0 ;} </span>

Related Article

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.