#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int maxn = 201000;
int value[maxn*3];//value[maxn*2] -> WA
int maxv[maxn*3];//total of the segment.
//Accepted 1754 2078MS 6556K 2308 B G++ Achiberx
//Accepted 1754 1015MS 6504K 1955 B C++ Achiberx
int n, m;
int ql, qr;//全局变量。
//ql, qr /给出的查询区间。
int update(int o, int L, int R, int v) {
if(L == R && L ==ql ) {
maxv[o] = v;
return v;
}
int M = L + (R-L)/2;
if(ql <= M) {//单点修改,在左右选择一个。
update(o*2, L, M, v);
}
else {
update(o*2+1, M+1, R, v);
}
maxv[o] = max(maxv[o*2], maxv[o*2+1]);
return maxv[o];
}
int query(int o, int L, int R) {
if(ql <= L && R <= qr) return maxv[o];
int ans = 0;
int M = L + (R-L)/2;
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;
}
void init() {
for(int i = 1; i <= n; i++) {
ql = i;
update(1, 1, n, value[i]);
}
}
int main()
{
int a, b;
while(scanf("%d%d", &n, &m) != EOF) {
for(int i = 1; i <= n*2; i++) {
value[i] = 0;
maxv[i] = 0;
}
for(int i = 1; i <=n; i++) {
scanf("%d", value+i);
}
init();
for(int i = 0; i < m; i++) {
char c[5];
scanf("%s", c);
scanf("%d%d",&a, &b);
if(c[0]=='U') {
ql = a;
update(1, 1, n, b);
}
else if(c[0]=='Q') {
ql = a; qr = b;
int res = query(1, 1, n);
printf("%d\n", res);
}
}
}
return 0;
}
hdu1754I Hate It
最新推荐文章于 2020-09-30 13:33:24 发布