I Hate ItTime
limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 41510 Accepted Submission (s): 16458
Problem 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 outputs the highest score in a row for each query operation.
Sample Input
5 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5
Sample Output
5659HintHuge input,the C function scanf () would work better than CIN
Authorlinle
Source2007 Provincial Training Team Practice (6) _linle session
Get started with the line tree and go directly to the code. CODE:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string > #include <algorithm> #include <cstdlib> #include <set> #include <queue> #include <stack > #include <vector> #include <map> #define N 200010#define Mod 10000007#define Lson l,mid,idx<<1# Define Rson mid+1,r,idx<<1|1#define LC idx<<1#define RC Idx<<1|1const Double EPS = 1e-11;const double PI = ACOs ( -1.0); const double E = 2.718281828;typedef long long ll;const int INF = 1000010;using namespace Std;int tree[n& Lt;<2];int m,n;void push_up (int idx) {Tree[idx]=max (TREE[LC],TREE[RC]);} void build (int l,int r,int idx) {if (l==r) {scanf ("%d", &tree[idx]); Return } int mid= (L+R) >>1; Build (Lson); Build (Rson); PUSH_UP (idx);} void update (int l,int r,int idx,int x,int k) {if (l==r) {tree[idx]=k; return; } int mid= (L+R) >>1; if (x<=mid) update (Lson,X,K); if (x>mid) update (RSON,X,K); PUSH_UP (idx);} int query (int l,int r,int idx,int x,int y) {if (x<=l&&y>=r) return TREE[IDX]; int mid= (L+R) >>1; int s=-1; if (x<=mid) S=max (S,query (lson,x,y)); if (y>mid) S=max (S,query (rson,x,y)); return s;} int main () {while (~scanf ("%d%d", &n,&m)) {build (1,n,1); Char s[2]; int x, y; while (m--) {scanf ("%s%d%d", s,&x,&y); if (s[0]== ' U ') update (1,N,1,X,Y); else printf ("%d\n", Query (1,n,1,x,y)); }} return 0;}
HDU 1754 I Hate It (line tree entry)