Line Segment tree with the highest value in the interval

Source: Internet
Author: User

The original question of last provincial competition ..

This year, we basically forgot about the line segment tree. I typed it again today. I found that my input processing is not bad.

This type of Weak Explosion of line tree...

Because of the inattentive thinking, WA has been around for a long time. It seems that we should be more careful in the future!

Weak nodeTime Limit: 2000/1000 ms (Java/Other) Memory Limit: 65535/32768 K (Java/Other) Total Submission (s): 22 Accepted Submission (s): 7 Font: times New Roman | Verdana | GeorgiaFont Size: Regular → Problem DescriptionCountry C preparing to attack Country J, but the specified age of troops Country C, country C to find out the location of weak Country J defense. inputLine 1: n m (1 <=n <= 100,000, 1 <= m <= 120,000)
Line 2: n numbers, respectively said the defense force of the Country J n nodes
Line 3 to 2 + m: m action, expressed as follows
Find :( I, j)
From I to j nodes to identify the weakest defense of the node, and the output of Defense
Move :( i1, i2 .....)
These points will move relative to each other position
For example, if [,], then move (, 7) yields [,] OutputFor each find, print the weakest defense of the valueSample Input
8 38 7 6 5 4 3 2 1find(2,5)move(3,5,7)find(2,5)
Sample Output
42
#include<iostream>#define MAXN 111111#define INF 0x7FFFFFFFusing namespace std;int tree[MAXN<<2];int min( int a,int b ){ return a<b?a:b; }void PushUp( int rt ){  tree[rt]=min( tree[rt<<1],tree[rt<<1|1] );}void build( int l,int r,int rt ){  if( l==r )  {   scanf( "%d",&tree[rt] );   return ; } int m=(l+r)>>1; build( l,m,rt<<1 ); build( m+1,r,rt<<1|1 );  PushUp(rt);}void update( int p,int num,int l,int r,int rt ){  if( l==r )  {   tree[rt]=num;   return ; } int m=(l+r)>>1; if( p<=m )  update( p,num,l,m,rt<<1 ); else  update( p,num,m+1,r,rt<<1|1 ); PushUp(rt);}int query( int L,int R,int l,int r,int rt ){ if( L<=l&&r<=R ){ return tree[rt];  }  int m=(l+r)>>1;  int ret=INF;  if( L<=m ) ret=min( ret,query(L,R,l,m,rt<<1) );  if( m<R ) ret=min( ret,query(L,R,m+1,r,rt<<1|1) );  return ret;}void getData( char *s,int *num,int &n ){  int bit;  s+=5;  while( strlen(s) )  {  sscanf( s,"%d%n",&num[n++],&bit );  s+=bit+1; }}int main(){ freopen( "J.in","r",stdin ); freopen( "Jans.out","w",stdout ); int N,M; while( scanf("%d %d",&N,&M )!=EOF ) {    build(1,N,1);    getchar();    char str1[11111],str2[11111];    int l,r;    for( int i=0;i<M;i++ )    {    gets(str1);    int num;    if( sscanf(str1,"find(%d,%d)",&l,&r) )       printf( "%d\n",query(l,r,1,N,1) );   else   { int rot[11],n=0; getData( str1,rot,n ); int rec=query( rot[0],rot[0],1,N,1); for( int i=0;i<n-1;i++ )  update( rot[i],query(rot[i+1],rot[i+1],1,N,1),1,N,1 );  update( rot[n-1],rec,1,N,1 );   }   }}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.