#define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define repp(i, a, b) for (int i = (a); i >= (b); --i) #define ll long long #define see(x) (cerr <<(#x) <<"=" <<(x) <#define inf 0x3f3f3f3f #define CLR(A, v) memset(A, v, sizeof A)
const int N = 1e5 + 10; int t[N <<5][2], T[N], siz[N <<5], ncnt, b[N];
void upnode(int k, int x, int pre, int &pos) { pos = ++ncnt; t[pos][0] = t[pre][0]; t[pos][1] = t[pre][1]; siz[pos] = siz[pre] + 1; if (k <0) return; int c = (x >> k) & 1; upnode(k - 1, x, t[pre][c], t[pos][c]); }
int qmax(int k, int x, int pre, int pos) { if (k <0) return 0; int c = (x >> k) & 1; if (siz[t[pos][c ^ 1]] - siz[t[pre][c ^ 1]] > 0) return (1 < else return qmax(k - 1, x, t[pre][c], t[pos][c]); }
vector node[N <<2]; int n, m, ans[N];
void addnode(int x, int L, int R, int l, int r, int pos) { if (L > R) return; if (L <= l && r <= R) { node[pos].push_back(x); return; } int m = (l + r) >> 1; if (L <= m) addnode(x, L, R, l, m, pos <<1); if (R > m) addnode(x, L, R, m + 1, r, pos <<1 | 1); }
struct marspeo { int L, R, s, t, x; } peo[N];
struct upp { int t, x, val; } up[N], s1[N], s2[N];
int cnt1, cnt0;
void calc(int L, int R, int pos) { int nn = 0; ncnt = 0; rep(i, L, R) { nn++; b[nn] = up[i].x; upnode(20, up[i].val, T[nn - 1], T[nn]); } for (auto v : node[pos]) { int l = lower_bound(b + 1, b + 1 + nn, peo[v].L) - b; int r = upper_bound(b + 1, b + 1 + nn, peo[v].R) - b - 1; int temp = qmax(20, peo[v].x, T[l - 1], T[r]); ans[v] = max(ans[v], temp); } }
void cdq(int L, int R, int l, int r, int pos) { if (L > R) return; calc(L, R, pos); if (l == r) return; int temp1 = 0, temp2 = 0, mid = (l + r) >> 1; rep(i, L, R) if (up[i].t <= mid) s1[++temp1] = up[i]; else s2[++temp2] = up[i]; rep(i, 1, temp1) up[i + L - 1] = s1[i]; rep(i, 1, temp2) up[i + L + temp1 - 1] = s2[i]; cdq(L, L + temp1 - 1, l, mid, pos <<1); cdq(L + temp1, R, mid + 1, r, pos <<1 | 1); }