#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
const int MAXN = 200000 + 10;
int a[MAXN], c[MAXN], n, m;
int lowbit (int x);
int getmax (int l, int r);
void add (int x, int d);
int main ()
{
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while (cin >> n >> m)
{
int x;
memset (a, 0, sizeof(a));
memset (c, 0, sizeof(c));
for (int j=1; j<=n; j++)
cin >> x, add (j, x);
char que;
int x1, y1;
while (m--)
{
cin >> que >> x1 >> y1;
if (que == 'Q')
cout << getmax (x1, y1) << endl;
else
add (x1, y1);
}
}
return 0;
}
int lowbit (int x)
{
return x & (-x);
}
int getmax (int l, int r)
{
int ans = a[r];
while (l != r)
{
r--;
while (r - lowbit(r) > l)
{
ans = max (c[r], ans);
r -= lowbit (r);
}
ans = max (ans, a[r]);
}
return ans;
}
void add (int x, int d)
{
a[x] = d;
while (x <= n)
{
if (c[x] < d)
c[x] = d;
else
break;
x += lowbit(x);
}
}
hdu 1754 I Hate It
最新推荐文章于 2020-07-21 19:15:51 发布