# Hdu1754 i hate it

Posted by yjjr's blog on February 6, 2018

HDU1754 I Hate It

http://www.sakurasake.icoc.me/nd.jsp?id=5#_np=2_327

Time Limit: 9000/3000 MS(Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description

Input

Output

Sample Input

5 6

1 2 3 4 5

Q 1 5

U 3 6

Q 3 4

Q 4 5

U 2 9

Q 1 5

Sample Output

5

6

5

9

Hint

Huge input,the C function scanf() will workbetter than cin

Source

#include<iostream>
#include<iomanip>
#include<cmath>
#include<ctime>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#define INF 200001
{
int f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct data
{
int l,r,max;
}t[3*INF];

int score[INF];

int Max(int a,int b)
{
return a>b?a:b;
}

void make(int i,int j,int num)
{
t[num].l=i;
t[num].r=j;
if(i==j)t[num].max=score[i];
else
{
make(i,(i+j)/2,2*num);
make(((i+j)/2)+1,j,2*num+1);
t[num].max=Max(t[num*2].max,t[num*2+1].max);
}
}

void change(int pos,int val,int num)
{
t[num].max=Max(val,t[num].max);
if(t[num].l==t[num].r)return;
if(pos<=t[num*2].r) change(pos,val,num*2);
else change(pos,val,num*2+1);
}

int query(int i,int j,int num)
{
if(i==t[num].l&&j==t[num].r) return t[num].max;
if(j<=t[num*2].r) return query(i,j,num*2);
if(i>=t[num*2+1].l) return query(i,j,num*2+1);
int mid=(t[num].l+t[num].r)/2;
return Max(query(i,mid,2*num),query(mid+1,j,2*num+1));
}

int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int i;
//for(i=1;i<=n;i++)scanf("%d",&score[i]);
//getchar();
char c;
int s,e;
make(1,n,1);
for(i=1;i<=m;i++)
{
scanf("%c",&c);