# [BZOJ2028][SHOI2009]会场预约（Splay）

2$2$个操作就是询问根节点的size$size$（我的程序稍微写麻烦了点）。

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
inline int read() {
int res = 0; bool bo = 0; char c;
while (((c = getchar()) < '0' || c > '9') && c != '-');
if (c == '-') bo = 1; else res = c - 48;
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + (c - 48);
return bo ? ~res + 1 : res;
}
inline char get() {
char c; while ((c = getchar()) != 'A' && c != 'B'); return c;
}
const int N = 2e5 + 5;
int n, T, Rt, cnt, fa[N], lc[N], rc[N], sze[N], L[N], R[N];
int which(int x) {return rc[fa[x]] == x;}
void upt(int x) {
sze[x] = 1;
if (lc[x]) sze[x] += sze[lc[x]];
if (rc[x]) sze[x] += sze[rc[x]];
}
void rotate(int x) {
int y = fa[x], z = fa[y], b = lc[y] == x ? rc[x] : lc[x];
if (z) (lc[z] == y ? lc[z] : rc[z]) = x;
fa[x] = z; fa[y] = x; if (b) fa[b] = y;
if (lc[y] == x) rc[x] = y, lc[y] = b;
else lc[x] = y, rc[y] = b; upt(y); upt(x);
}
void splay(int x, int tar) {
while (fa[x] != tar) {
if (fa[fa[x]] != tar) {
if (which(x) == which(fa[x])) rotate(fa[x]);
else rotate(x);
}
rotate(x);
}
if (!tar) Rt = x;
upt(x);
}
int PreR(int v) {
int x = Rt, res = 1;
while (x)
if (R[x] < v) res = x, x = rc[x];
else x = lc[x];
return res;
}
int SufL(int v) {
int x = Rt, res = 2;
while (x)
if (L[x] > v) res = x, x = lc[x];
else x = rc[x];
return res;
}
void ins(int l, int r) {
int x = PreR(l), y = SufL(r);
splay(x, 0); splay(y, Rt);
printf("%d\n", (lc[rc[Rt]] ? sze[lc[rc[Rt]]] : 0));
if (lc[rc[Rt]]) {
cnt -= sze[lc[rc[Rt]]];
fa[lc[rc[Rt]]] = 0; lc[rc[Rt]] = 0;
upt(rc[Rt]); upt(Rt);
}
L[lc[rc[Rt]] = ++T] = l; R[T] = r; fa[T] = rc[Rt];
sze[T] = 1; upt(rc[Rt]); upt(Rt); cnt++;
}
void init() {
fa[T = rc[Rt = 1] = 2] = sze[2] = 1;
L[sze[1] = 2] = R[2] = 1e5 + 3;
}
int main() {
int i, x, y; n = read(); char c; init();
while (n--) {
c = get(); if (c == 'A') {
}