#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;
}
hdu 1754
最新推荐文章于 2019-10-25 00:39:07 发布