I Hate it

Source: Internet
Author: User

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), representing 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 6
1 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5

Sample Output

5659
Test instructions
Given n values arranged in a certain order, the N values are operated in two ways:
1. Query the maximum value of an interval [a, b];
2. Change the value of the ordinal to A; Segment tree, update node, interval to find the most value idea: This question is exactly a basic application of line tree, is to build a static tree, and then do not maintain the maximum value of each interval according to the input area. Three basic operations were used,achievements, updates, inquiries。

The code is as follows:

#include "stdio.h" #include <cstdio> #include <climits>using namespace std; #define M ((l+r) >>1) # Define Lson rt<<1,l,m#define Rson rt<<1|1,m+1,r#define root 1,1,n#define max (A, B) ((a>b)? a:b) Const INT MAXN = 200001;int maxv[maxn << 2],ql,qr,tar,v,val[maxn];inline void pushup (int rt) {Maxv[rt] = max (MAXV[RT&LT;&L T;1],maxv[rt<<1|1]);}    void build (int rt,int l,int R) {if (L = = r) Maxv[rt] = Val[l];        else {build (Lson); build (Rson);    Pushup (RT);    }}void Update (int rt,int l,int R) {if (L = = r) Maxv[rt] = v;        else {if (tar <= M) update (Lson);        if (Tar > M) update (Rson);    Pushup (RT);    }}int query (int rt,int l,int R) {if (QL <= L && qr >= R) return MAXV[RT];    int LV =-INT_MAX,RV =-int_max;    if (QL <= M) LV = query (Lson);    if (qr > M) rv = query (Rson); Return Max (LV,RV);}    int main () {int n,m;    char cmd; while (~SCANF ("%d%d", &n,&m)) {for (int i = 1; I <= n;i++) scanf ("%d", Val + i);        Build (root);            for (int i = 1;i <= m;i++) {scanf ("%c", &cmd);                if (cmd = = ' Q ') {scanf ("%d%d", &AMP;QL,&AMP;QR);            printf ("%d\n", query (root));                } else {scanf ("%d%d", &tar,&v);            Update (root); }}} 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.