Intention:
There are a total of n positions, one attribute k[i] for each position, indicating that the i position will be instantaneously transferred to i+k[i] (and then transferred in turn). Ask how many times out of a point will go out of bounds. And support for modifying k[i].
answer:
I move i to i+k[i] and if i+k[i] is out of bounds, it will connect to the outer root. Asking is asking for depth.
After a node is splayed to the root (provided that the root is the root of the original tree), the left side must be shallower than it (and must be a chain to the root of the original tree (because of the access operation)), so the left son Size is its depth (the depth of the root is 0).
Actually, I had to write a day of LCT for half an hour to write it, if it is not BZOJ's compiler stack space is not enough 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 ) ;
}
}
Flange Sensor
Flange type NTC temperature sensor we made with high precision, reliable NTC Thermistor connected to qualified FEP, PVC insulated wire, heat conductive and water resistant materials into custom shapes so as to facilitate long-distance temperature measurement and control. Our sensors that have beautiful appearance and fix convenient have been applied for dryer, rice cooker, automotive air conditioner, water heater, toaster, water closet and more. Temperature range of this sensor is from -30°C to 200°C.
Flange Sensor,Washing Machine Sensor,Toaster Sensor,Rice Cooker Sensor
Feyvan Electronics Technology Co., Ltd. , https://www.fv-cable-assembly.com