I Hate It

Source: Internet
Author: User

I Hate ItTime limit:3000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64 U SubmitStatusPracticeHDU 1754

Description

Many schools are popular for a comparative habit. Teachers like to ask, from XXX to XXX, the highest score is how much.
This makes many students very disgusted.

Whether you like it or not, now you need to do is to follow the teacher's request, write a program, mock teacher's inquiry. Of course, teachers sometimes need to update a student's grades.

Input

This topic contains multiple sets of tests, please handle to the end of the file.
On the first line of each test, there are two positive integers N and M (0<n<=200000,0<m<5000), which represent the number of students and the number of operations respectively.
Student ID numbers are numbered from 1 to N, respectively.
The second line contains n integers representing the initial scores of the N students, of which the number of I represents the student's score for ID i.
Then there's M-line. Each line has a character C (only ' Q ' or ' U '), and two positive integers, A/b.
When C is ' Q ', it indicates that this is a query operation, which asks for the highest number of students whose IDs are from a to B (including A, a).
When C is ' U ', it indicates that this is an update operation that requires the student with ID A to change the grade to B.

Output

For each query operation, output the highest score in one line.

Sample Input

5 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5

Sample Output

5659

Hint



Find the maximum value in a specified interval, and the value will be updated from time to time, because the data too much, so violent search must be tle, then the line tree came,
Each tree has the leftmost and rightmost subscripts of the number it covers, as well as the maximum value in this interval.
#include <iostream>#include<cstdio>using namespacestd;#defineN 200000#defineINF 0XFFFFFFFintMAX, a[n];structnode{intL, R, Max; intmid () {return(L+R)/2; }}tree[4*N];voidBuild (intRootintLintr)//achievement {TREE[ROOT].L= L, TREE[ROOT].R =R; if(TREE[ROOT].L = =TREE[ROOT].R) {Tree[root]. Max=A[l]; If it's the leaf node maximum, it's itself .return; } Build (Root*2, L, (l+r)/2); Build (Root*2+1, (L+R)/2+1, R); Tree[root]. Max= Max (tree[root*2]. Max, tree[root*2+1].   MAX); The maximum value of the tree is equal to the maximum value of its left son's tree and the maximum value of its right son}voidQueryintRootintLintr)//query, L~r interval max {if(TREE[ROOT].L = = L && TREE[ROOT].R = =r) {MAX=Max (Tree[root].  Max, Max); The maximum value of the total interval is equal to the maximum value of the original maximum and the maximum value of the partial interval.return ; }    if(R <=Tree[root].mid ())//Continue querying query (root*2, L, R); Else if(L >tree[root].mid ()) query (root*2+1, L, R); Else{query (root*2, L, Tree[root].mid ()); Query (Root*2+1, Tree[root].mid () +1, R); }}voidUpdateintRootintQintb)//update to leaf node {if(TREE[ROOT].L = = Q && TREE[ROOT].R = =q)//If to the leaf node, then its value is changed, the maximum value is also changed, is the changed value {a[q]=b; Tree[root]. Max=A[q]; return ; }    if(Q <=tree[root].mid ()) Update (2*Root, q, b); ElseUpdate (2*root+1, q, b); Tree[root]. Max= Max (tree[root*2]. Max, tree[root*2+1].  MAX); The maximum value on the tree is equal to the maximum value of the left son and right son}intMain () {intN, Q, L, R; Chars[3];  while(SCANF ("%d%d", &n, &q)! =EOF) {         for(inti =1; I <= N; i++) scanf ("%d", &A[i]); Build (1,1, N);  for(inti =0; i < Q; i++) {scanf ("%s%d%d", S, &l, &R); if(s[0] =='Q') {MAX= -INF; Start by initializing Max to query (1, L, R); printf ("%d\n", MAX); }            ElseUpdate (1, L, R); Update}}return 0;}

I Hate It

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.