#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 200005
struct Stu{
int l, r, s;
}str[maxn*3];
int num[maxn];
void Build(int n, int l, int r)
{
str[n].l =l;
str[n].r = r;
if(l == r){
str[n].s = num[l];
return ;
}
int mid = (l + r) / 2;
Build(n<<1, l, mid);
Build(n<<1|1, mid+1, r);
str[n].s = max(str[n<<1].s, str[n<<1|1].s);
}
void Top(int n, int l, int r, int &s)
{
if(str[n].l == l && str[n].r == r)
{
s = max(s, str[n].s);
return ;
}
int mid = (str[n].l + str[n].r) / 2;
if(r <= mid){
Top(n<<1, l, r, s);
}
else if(l > mid){
Top(n<<1|1, l, r, s);
}
else{
Top(n<<1, l, mid, s);
Top(n<<1|1, mid+1, r, s);
}
}
void Update(int n, int a, int b)
{
if(str[n].l == str[n].r){
str[n].s = b;
return ;
}
int mid = (str[n].l + str[n].r) / 2;
if(a <= mid)
Update(n<<1, a, b);
else
Update(n<<1|1, a, b);
str[n].s = max(str[n<<1].s, str[n<<1|1].s);
}
int main()
{
//freopen("in.txt", "r", stdin);
int n, m;
while(cin >> n >> m)
{
for(int i = 1; i <= n; i++)
scanf("%d ", num+i);
Build(1, 1, n);
char ch;
int a, b;
for(int i = 1; i <= m; i++)
{
scanf("%c %d %d ", &ch, &a, &b);
if(ch == 'Q')
{
int s = 0;
Top(1, a, b, s);
cout << s << endl;
}
else if(ch == 'U'){
Update(1, a, b);
}
}
}
return 0;
}
HDOJ-1754 I Hate It
最新推荐文章于 2018-07-30 13:28:53 发布