日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 智能硬件 > 人工智能AI
[導讀]   題意:   一共n個位置,每個位置一個屬性k[i],表示在i位置會被瞬間轉移到i+k[i](然后又依次轉移)。問從一個點開始多少次會出界。并且支持修改k[i]。   題解:

  題意:

  一共n個位置,每個位置一個屬性k[i],表示在i位置會被瞬間轉移到i+k[i](然后又依次轉移)。問從一個點開始多少次會出界。并且支持修改k[i]。

  題解:

  把i向i+k[i]連邊,若i+k[i]出界就向外面的總根連邊。詢問就是求深度。

  把一個節(jié)點splay到根之后(前提是根是原樹最開始的根),左邊一定是比它淺的(且一定是它到原樹根的一條鏈(因為access操作)),所以左兒子的size就是它的深度(根的深度為0)。

  居然以前要寫一天的LCT半個小時就寫好了,要不是BZOJ的編譯器??臻g不夠就1A了

  /**************************************************************

  Problem: 2002

  User: Lazer2001

  Language: C++

  Result: Accepted

  TIme:1988 ms

  Memory:22324 kb

  ****************************************************************/

  # include 《bits/stdc++.h》

  inline int read ( ) {

  register int x, c ;

  while ( isspace ( c = getchar ( ) ) ) ;

  for ( x = -48 + c ; isdigit ( c = getchar ( ) ) ; ( x *= 10 ) += c - 48 ) ;

  return x ;

  }

  template 《 class T 》 inline T min ( const T& a, const T& b ) { return a 《 b ? a : b ; }

  template 《 class T 》 inline void swap ( T& a, T& b ) { T c ( a ) ; a = b, b = c ; }

  # define N 200010

  class LinkCutTree {

  private :

  struct node {

  int siz ;

  bool rev_flag ;

  node *ch [2], *fa ;

  inline void update ( ) {

  siz = ch [0] -》 siz + ch [1] -》 siz + 1 ;

  }

  } pool [N 《《 1], *root [N], *null ;

  int n ;

  inline void push_down ( node*& p ) {

  if ( p -》 rev_flag ) {

  swap ( p -》 ch [0], p -》 ch [1] ) ;

  if ( p -》 ch [0] != null ) p -》 ch [0] -》 rev_flag ^= 1 ;

  if ( p -》 ch [1] != null ) p -》 ch [1] -》 rev_flag ^= 1 ;

  p -》 rev_flag = 0 ;

  }

  }

  inline node* newnode ( node*& fa ) {

  staTIc node* tp ( pool + 1 ) ;

  tp -》 siz = 1 ; tp -》 rev_flag = 0 ;

  return tp -》 fa = fa, tp -》 ch [0] = tp -》 ch [1] = null, tp ++ ;

  }

  # define isroot( p ) ( p -》 fa == null || ( p -》 fa -》 ch [0] != p && p -》 fa -》 ch [1] != p ) )

  # define isrs( p ) ( p == p -》 fa -》 ch [1] )

  inline void rotate ( node* p ) {

  if ( p == null || isroot ( p ) ) return ;

  bool d ( isrs ( p ) ) ;

  node* par = p -》 fa ;

  par -》 ch [d] = p -》 ch [! d] ;

  if ( p -》 ch [! d] != null ) p -》 ch [! d] -》 fa = par ;

  if ( ! isroot ( par ) ) par -》 fa -》 ch [isrs ( par )] = p ; // !isroot(par)

  p -》 fa = par -》 fa ;

  par -》 fa = p ;

  p -》 ch [! d] = par ;

  par -》 update ( ) ; p -》 update ( ) ;

  }

  node* st [N 《《 1] ;

  inline void splay ( node* p ) {

  if ( p == null ) return ;

  // staTIc node* st [N 《《 1] ; staTIc int tp ( 0 ) ; RE?。。?!

  int tp ;

  st [tp = 1] = p ;

  for ( node* t = p ; ! isroot ( t ) ; t = t -》 fa ) st [++ tp] = t -》 fa ;

  while ( tp ) push_down ( st [tp --] ) ;

  while ( ! isroot ( p ) ) {

  if ( isrs ( p ) == isrs ( p -》 fa ) && ! isroot ( p -》 fa ) ) rotate ( p -》 fa ) ;

  rotate ( p ) ;

  }

  }

本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉