HDU Summer Multi-school eighth field J-taotao picks Apples

Source: Internet
Author: User

First, test instructions

Given a sequence, then give a number of modifications, the content of the modification is based on the original sequence, the value of one element is changed to a given value < each modification is independent of each other, does not save the modified results >. Then ask, in the case of selecting the first element, what is the length of the longest increment sub-sequence.

Second, the

Consider the case without modification, you should set Dp[i] to select the length of the longest increment substring in the current bit case. For this problem, it should be considered that for modifying a to B, set L_pos to the position of the largest element on the left of a, R_pos is the position of the element with a right greater than Max (B,r_pos). Then there is ans = dp[1]-Dp[l_pos] + 1 + dp[r_pos]; for b itself is greater than the element in L_pos, the result +1 should be given.

#include <bits/stdc++.h>using namespacestd;#definell Long LongConst intMAXN =1000233;classnode{ Public:        intL,r,lc,rc,maxx;}; Node NODES[MAXN];intNodes_num;intt,n,m;intARR[MAXN];intDP[MAXN];voidTree_init (intAintb) {    intnow = nodes_num++; NODES[NOW].L=A; NODES[NOW].R=b; if(A = = b1) {Nodes[now].maxx=Arr[a]; return ; }    intMid = (a+b)/2; NODES[NOW].LC=Nodes_num;    Tree_init (A,mid); Nodes[now].rc=Nodes_num;    Tree_init (MID,B); Nodes[now].maxx=Max (Nodes[nodes[now].lc].maxx,nodes[nodes[now].rc].maxx);}intFind_max (intNow ) {    intL =NODES[NOW].L; intR =NODES[NOW].R; if(L = = r1)returnl; intMaxx =Nodes[now].maxx; intLC =nodes[now].lc; intrc =nodes[now].rc; if(Maxx = = Nodes[lc].maxx)returnFind_max (LC); Else returnFind_max (RC);}intFind_biggest (intNowintAintb) {    intL =NODES[NOW].L; intR =NODES[NOW].R; if(L = = A&&r = =b) {        returnFind_max (now); }    intMid = (l+r)/2; intret; intLC =nodes[now].lc; intrc =nodes[now].rc; if(a<mid) {ret=find_biggest (Lc,a,min (B,mid)); if(b>mid) {            intTMP =find_biggest (RC,MID,B); RET= Arr[ret] >= arr[tmp]?ret:tmp; }    }ElseRET =find_biggest (RC,A,B); returnret;}intFind_left (intNowintkey) {    intL =NODES[NOW].L; intR =NODES[NOW].R; if(L = = r1)returnl; intLC =nodes[now].lc; intrc =nodes[now].rc; if(Nodes[lc].maxx > key)returnFind_left (Lc,key); Else returnFind_left (Rc,key);}intFind_first (intNowintPosintkey) {    intL =NODES[NOW].L; intR =NODES[NOW].R; if(L >=POS) {        returnFind_left (Now,key); }    intMid = (l+r)/2; intLC =nodes[now].lc; intrc =nodes[now].rc; intret; if(Pos < mid && Nodes[lc].maxx >key) {ret=Find_first (Lc,pos,key); if(Ret >= pos && Arr[ret] > key)returnret; }    if(Nodes[rc].maxx <= key)returnR1; returnFind_first (Rc,pos,key); }voidinit () {scanf ("%d%d",&n,&m); Nodes_num=0; arr[0] = -100233; Arr[n+1] =Int_max;  for(intI=1; i<=n;++i) scanf ("%d",&Arr[i]); Tree_init (0, n+2); Memset (DP,0,sizeof(DP));  for(inti=n;i>=1;--i) {Dp[i]= Dp[find_first (0, i+1, Arr[i])]+1; } dp[0] = dp[1]+1;  for(intI=0; i<m;++i) {        intb; scanf ("%d%d",&a,&b); intL_pos = Find_biggest (0,0, a); intKey =Max (B,arr[l_pos]); intR_pos = Find_first (0, A +1, Max (B,arr[l_pos])); intAns = dp[1]-Dp[l_pos] +1+Dp[r_pos]; if(b > Arr[l_pos]) ans++; cout<<ans<<'\ n'; }}intMain () {CIN>>T;  while(t--) init (); return 0;}

HDU Summer Multi-school eighth field J-taotao picks Apples

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.