HDU 1754
tagged-zkw.
稍后做一个教程。
namespace DEL
{
const int INF = 1e9, maxn = 1 << 25;
struct info
{
int Max;
info(int x = -INF) : Max(x){}
} A[maxn];
}
#include <cstdio>
#include <algorithm>
using namespace std;
using namespace DEL;
int main()
{
int n, m;
while(~scanf("%d%d", &n, &m))
{
int t;
for(t = 1; t <= n + 3; t <<= 1);
for(int i = t + 1; i < t + 1 + n; i++)
{
int a;
scanf("%d", &a);
A[i] = info(a);
}
for(int i = t - 1; i > 0; i--)
A[i].Max = max(A[i * 2].Max, A[i * 2 + 1].Max);
while(m--)
{
static char c[maxn];int x, y;
scanf("%s%d%d", &c, &x, &y);
if(c[0] == 'Q')
{
int ans = 0;
for(x += t - 1, y += t + 1; x ^ y ^ 1; x >>= 1, y >>= 1)
{
if(~x & 1)
ans = max(ans, A[x ^ 1].Max);
if(y & 1)
ans = max(ans, A[y ^ 1].Max);
}
printf("%d\n", ans);
}
else
{
for(A[x += t] = info(y), x >>= 1; x > 0; x >>= 1)
A[x].Max = max(A[x * 2].Max, A[x * 2 + 1].Max);
}
}
}
return 0;
}