注意左旋右旋方式
LL LR RR RL 的处理方式
右 子左自右 左 子右自左
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct node{
int l, r, val;
int height, size;
}avl[maxn];
int cnt = 0, root;
inline void add(int &now,int val){
avl[now = ++ cnt].val = val;
avl[cnt].size = 1;
}
inline void update(int now){
avl[now].size = avl[avl[now].l].size + avl[avl[now].r].size + 1;
avl[now].height = max(avl[avl[now].l].height, avl[avl[now].r].height)+1;
}
inline int factor(int now){
return avl[avl[now].l].height - avl[avl[now].r].height;
}
inline void lrotate(int &now){
// 左旋
int r = avl[now].r;
avl[now].r = avl[r