Click Open link I hate it
Time Limit: 9000/3000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 37367 accepted submission (s): 14775
Problem description many schools have a popular habit. Teachers like to ask, from xx to xx, what is the highest score.
This made many students very disgusted.
Whether you like it or not, what you need to do now is to write a program to simulate the instructor's inquiry according to the instructor's requirements. Of course, teachers sometimes need to update their scores.
Input this question contains multiple groups of tests, please process until the end of the file.
In the first row of each test, there are two positive integers n and M (0 <n <= 200000,0 <m <5000), representing the number of students and the number of operations respectively.
Student ID numbers are separated from 1 to n.
The second row contains N integers, indicating the initial score of the N students. The number of I represents the score of the students whose ID is I.
Next there are m rows. Each line has a character C (only 'q' or 'U'), and two positive integers A and B.
When C is 'Q', it indicates that this is a query operation. It asks the students whose ID ranges from A to B (including a and B) about the highest score.
When C is 'U', it indicates that this is an update operation. You must change the score of students whose ID is A to B.
Output outputs the highest score in one row for each query operation.
Sample Input
5 61 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5
Sample output
5659HintHuge input,the C function scanf() will work better than cin
Authorlinle
Source2007 provincial training team exercise session (6) _ linle
//500MS9228K#include<stdio.h>#include<algorithm>using namespace std;struct Tree{ int l,r,mid,count;}tree[200007*3];int g[200007];void build(int left,int right,int i){ tree[i].l=left;tree[i].r=right;tree[i].mid=(left+right)>>1; if(left==right){tree[i].count=g[left];return;} build(left,tree[i].mid,i*2); build(tree[i].mid+1,right,i*2+1); tree[i].count=max(tree[2*i].count,tree[2*i+1].count);}void update(int id,int num,int i){ if(tree[i].l==tree[i].r&&tree[i].l==id){tree[i].count=num;return;} tree[i].count=max(tree[i].count,num); if(tree[i*2].r>=id)update(id,num,i*2); else update(id,num,i*2+1);}int query(int left,int right,int i){ if(tree[i].l==left&&tree[i].r==right)return tree[i].count; if(tree[i*2].r>=right)return query(left,right,2*i); else if(tree[i*2+1].l<=left)return query(left,right,2*i+1); return max(query(left,tree[i].mid,i*2),query(tree[i].mid+1,right,i*2+1));}int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { for(int i=1;i<=n;i++) scanf("%d",&g[i]); build(1,n,1); while(m--) { char s[2]; int a,b; scanf("%s%d%d",s,&a,&b); if(s[0]=='Q')printf("%d\n",query(a,b,1)); else update(a,b,1); } } return 0;}