解题思路:
代码1:(非要用结构体版)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define for1(i,a,b) for (int i=a;i<=b;i++)
#define for0(i,a,b) for (int i=a;i<b;i++)
const int N = 1e5+5;
const int MAXN = 1e5+5;
struct CAT
{
int sta[MAXN],tot,sz;
int ch[MAXN][2];
int val[MAXN];
int l[MAXN],r[MAXN];
int root;
void init(){
tot = -1;
sz = 1;
root = 1;
l[0] = MAXN + 10;
r[0] = -1;
}
void insert(int id,int v){
int st_tot = tot;
ch[id][0] = ch[id][1] = 0;
while (tot>