AC Diary----Hate It Rokua P1531

Source: Internet
Author: User

Topic background

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.

Title Description

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/output format

Input format:

In the first line, 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 ', indicates that this is an update operation, if the current a student's score is lower than B, then the student ID of a students to change to B, otherwise do not change.

Output format:

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

Input and Output Sample input example # #:
5 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5
Sample # # of output:
5659



Ideas:
Bare-wire Segment tree


Come on, on the code:
#include <cstdio>#include<iostream>#include<algorithm>using namespacestd;classT_tree { Public:        intL,r,dis,flag,mid; BOOLif_; voidMid_ () {Mid= (l+r) >>1; }                voidFlag_ () {flag=0; }                voidDis_ () {scanf ("%d",&dis); }};classT_tree tree[200000*4+1];intN,m;inlineintMaxintSome_thing_1,intsome_thing_2) {    if(some_thing_1>some_thing_2)returnsome_thing_1; Else returnsome_thing_2;} InlinevoidTREE_UP (intNow ) {Tree[now].dis=max (tree[now<<1].dis,tree[now<<1|1].dis);}voidTree_build (intNowintLintR) {TREE[NOW].L=l,tree[now].r=R; if(l==r) {tree[now].dis_ (); return ;    } tree[now].mid_ (); Tree_build ( now<<1, L,tree[now].mid); Tree_build ( now<<1|1, tree[now].mid+1, R); TREE_UP (now);}intTree_query (intNowintLintR) {    if(tree[now].l==l&&tree[now].r==r) {returnTree[now].dis; }    if(L>tree[now].mid)returnTree_query (now<<1|1, L,r); Else if(R<=tree[now].mid)returnTree_query (now<<1, L,r); Else    {        intsum_=-2333333; Sum_=max (Tree_query (now<<1, L,tree[now].mid), sum_); Sum_=max (Tree_query (now<<1|1, tree[now].mid+1, R), sum_); returnsum_; }}voidTree_change (intNowintTo,intdis) {    if(tree[now].l==to&&tree[now].l==TREE[NOW].R) {Tree[now].dis=Max (Tree[now].dis,dis); return ; }    if(tree[now].mid<to) Tree_change (now<<1|1, To,dis); ElseTree_change (now<<1, To,dis); TREE_UP (now);}intMain () {scanf ("%d%d",&n,&m); Tree_build (1,1, N); CharTy; intL,r;  for(intI=1; i<=m;i++) {cin>>Ty; scanf ("%d%d",&l,&R); if(ty=='Q') {printf ("%d\n", Tree_query (1, L,r)); }        Else{Tree_change (1, L,r); }    }    return 0;}

AC Diary----Hate It Rokua P1531

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.