HDU-1754 I hate it--point update interval query __hdu

Source: Internet
Author: User

I Hate It Time limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 83692 accepted Submission (s): 32139


Problem Description Many schools have a more popular habit. Teachers like to ask, from So-and-so to So-and-so, the highest score is how much.
This makes many students very disgusted.

Whether you like it or not, what you need to do now is to follow the teacher's request, write a program, simulate the teacher's inquiry. Of course, teachers sometimes need to update the results of a certain classmate.
Input This topic contains multiple sets of tests, please handle to end of 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.
The student ID number is compiled from 1 to N, respectively.
The second row contains n integers, representing the initial scores of the N students, with the number I representing the scores of the students with ID i.
Next there is M line. Each row has a character C (only ' Q ' or ' U '), and two positive integers a,b.
When C is ' Q ', it means that this is a query operation, and it asks how many of the students with the ID from a to B (including a,b) have the highest score.
When C is ' U ', it means that this is an update operation that requires that the student with ID A be changed to B.

Output for each query operation, the highest performance in one line.
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 () would work better than CIN


Line Tree Template problem


#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include < queue> #include <stack> #include <vector> #define MAX_ 200010 #define INF 0x3f3f3f3f #define LL long u
Sing namespace std;
struct node {int l,r,high;};
struct node tree[max_*4];
int n,m;
		void build (int i,int l,int R) {if (l==r) {scanf ("%d", &tree[i].high);
		Tree[i].l=tree[i].r=l;
	Return
	int mid= (L+R)/2;
	Build (I<<1,l,mid);
	Build (I<<1|1,mid+1,r);
	Tree[i].high=max (Tree[i<<1].high,tree[i<<1|1].high);
	Tree[i].l=l;
Tree[i].r=r;
		} void Change (int i,int id,int W) {if (TREE[I].L==TREE[I].R) {tree[i].high=w;
	Return
	int mid= (TREE[I].L+TREE[I].R) >>1;
	if (id<=mid) change (I&LT;&LT;1,ID,W);
	else change (I&LT;&LT;1|1,ID,W);
Tree[i].high=max (Tree[i<<1].high,tree[i<<1|1].high);
	int query (int i,int l,int R) {if (tree[i].l==l&&tree[i].r==r) return tree[i].high; int mid = (trEE[I].L+TREE[I].R) >>1;
	if (r<=mid) return query (I&LT;&LT;1,L,R);
	else if (l>mid) return query (I&LT;&LT;1|1,L,R);
else return Max (i<<1,l,mid), query (I&LT;&LT;1|1,MID+1,R);
		int main (int argc, char const *argv[]) {while (scanf ("%d%d", &n,&m)!=eof) {build (1,1,n);
			while (m--) {int x,y;
			char c;
			scanf ("%c%d%d", &c,&x,&y);
				Switch (c) {case ' Q ':p rintf ("%d\n", Query (1,x,y));
			Case ' U ': Change (1,x,y);
}} return 0; }


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.