hdu 1754

#include <iostream>
#include <stdio.h>
#define MAX_N 200005
using namespace std;

int a[MAX_N];

struct node {
    int left, right, maxx;
} tt[MAX_N * 3];

int build(int left, int right, int index) {
    tt[index].left = left;
    tt[index].right = right;
    if (left == right) return tt[index].maxx = a[left];
    int mid = (left + right) / 2;
    return tt[index].maxx = max(build(left, mid, index * 2), build(mid + 1, right, index * 2 + 1));
}

int solve(int index, int x, int y) {
    int left, right, mid;
    left = tt[index].left;
    right = tt[index].right;
    if (left == x && right == y) return tt[index].maxx;
    mid = (left + right) / 2;
    if (mid >= y) return solve(index * 2, x, y);
    else if (mid < x) return solve(index * 2 + 1, x, y);
    else {
        int t1, t2;
        t1 = solve(index * 2, x, mid);
        t2 = solve(index * 2 + 1, mid + 1, y);
        return max(t1, t2);
    }
}

void update(int index, int x, int y) {
    if (tt[index].maxx < y) tt[index].maxx = y;
    if (tt[index].left == x && tt[index].right == x) return;
    int mid = (tt[index].left + tt[index].right) / 2;
    if (x <= mid) update(index * 2, x, y);
    else update(index * 2 + 1, x, y);
}

int main() {
    int n, m, i, x, y;
    char str[5];
    while (scanf("%d%d", &n, &m) != EOF) {
        for (i = 1; i <= n; i++) scanf("%d", &a[i]);
        build(1, n, 1);
        for (i = 0; i < m; i++) {
            scanf("%s%d%d", str, &x, &y);
            if (str[0] == 'Q') printf("%d\n", solve(1, x, y));
            else update(1, x, y);
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值