Blue Book 4.1-4.4 tree-like array, RMQ problem, line segment tree, multiplication and evaluation of LCA

Source: Internet
Author: User
Tags cmath

The data structure problem in this chapter is very real.

T1 Queue Bzoj 1699

Main topic:

To find the maximum value of a static interval-the minimum value

Ideas:

St Table Nude Questions

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <cmath>6#include <algorithm>7#include <queue>8#include <vector>9 #definell Long LongTen #defineINF 2139062143 One #defineMAXN 100100 A using namespacestd; -InlineintRead () - { the     intx=0, f=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') f=-1; ch=GetChar ();} -      while(IsDigit (CH)) {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; + } - intn,q,g[maxn],mn[maxn][ -],mx[maxn][ -]; + intMain () A { atN=read (), Q=read ();inta,b,t; -      for(intI=1; i<=n;i++) mn[i][0]=mx[i][0]=g[i]=read (); -      for(intj=1;j< -; j + +) -          for(intI=1; i+ (1&LT;&LT;J)-1<=n;i++) -Mn[i][j]=min (mn[i][j-1],mn[i+ (1<< (J-1))][j-1]), Mx[i][j]=max (mx[i][j-1],mx[i+ (1<< (J-1))][j-1]); -      while(q--) in     { -A=read (), B=read (), t=b-a+1, t= (int) log2 (t); toprintf"%d\n", Max (mx[a][t],mx[b-(1&LT;&LT;T) +1][t])-min (mn[a][t],mn[b-(1&LT;&LT;T) +1][t])); +     } -}
View Code

T2 Select Inn Luogu 1311

Main topic:

Each point has two value color and minimum consumption value if there is a point minimum consumption value between two point pairs <=n

Ask for the number of point pairs

Ideas:

Save each color with a linked list to record the position of the previous <=p.

For each color traversed individually

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <cmath>6#include <algorithm>7#include <queue>8#include <vector>9 #definell Long LongTen #defineINF 2139062143 One #defineMAXN 200100 A using namespacestd; -InlineintRead () - { the     intx=0, f=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') f=-1; ch=GetChar ();} -      while(IsDigit (CH)) {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; + } - intn,k,p,g[maxn],c[maxn],tmp[ -],fst[ -],LAS,CNT,RES,ANS,L[MAXN],TO[MAXN]; + intMain () A { atN=read (), K=read (), p=read (); -      for(intI=1; i<=n;i++) -     { -C[i]=read (), g[i]=read (); -         if(g[i]<=p) las=i;l[i]=Las; -         if(!tmp[c[i]]) fst[c[i]]=i,tmp[c[i]]=i; in         Elseto[tmp[c[i]]]=i,tmp[c[i]]=i; -     } to      for(intI=0, pos;i<k;i++) +     { -Pos=fst[i],cnt=1, res=0; the          while(To[pos]) *         { $             if(to[pos]>n) Break;Panax Notoginseng             if(L[to[pos]]>=pos) res=CNT; -ans+=res,cnt++,pos=To[pos]; the         } +     } Aprintf"%d", ans); the}
View Code

T3 Maximum Value Bzoj 1012

Links

T4 Bzoj 3211

Links

T5 Maintenance Sequence Bzoj 1798

Blue Book 4.1-4.4 tree-like array, RMQ problem, line segment tree, multiplication and evaluation of LCA

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.