Main topic
Give a sequence that asks if there are more than half the numbers in the interval.
Ideas
Use the Chairman tree to take the interval out and find it in the weight segment tree.
CODE
#define _crt_secure_no_warnings#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 500010#define MAXR 10000010using namespace STD;structsegtree{Segtree *son[2];intCNT;} MEMPOOL[MAXR], *c = Mempool, *root[max]; Segtree *newsegtree (Segtree *_, Segtree *__,int___) {c->son[0] = _; c->son[1] = __; c->cnt = ___;returnC + +;} Segtree *insert (Segtree *consult,intLintRintx) {if(L = = r)returnNewsegtree (consult->son[0], consult->son[1], consult->cnt +1);intMid = (L + r) >>1;if(x <= mid)returnNewsegtree (Insert (consult->son[0], L, Mid, X), consult->son[1], consult->cnt +1);Else returnNewsegtree (consult->son[0], Insert (consult->son[1], Mid +1, R, X), consult->cnt +1);}intAsk (Segtree *left, Segtree *right,intLintRintc) {if(L = = r)returnLintMid = (L + r) >>1;if(right->son[0]->cnt-left->son[0]->cnt > C)returnAsk (left->son[0], right->son[0], L, Mid, c);Else if(right->son[1]->cnt-left->son[1]->cnt > C)returnAsk (left->son[1], right->son[1], Mid +1, R, c);return 0;}intCNT, asks;intMain () {root[0] = Newsegtree (c, C,0);Cin>> CNT >> asks; for(intX, i =1; I <= CNT; ++i) {scanf("%d", &x); Root[i] = Insert (Root[i-1],1, CNT, x); } for(intX, y, i =1; I <= asks; ++i) {scanf("%d%d", &x, &y);printf("%d\n", Ask (Root[x-1], Root[y],1, CNT, (Y-x +1) /2)); }return 0;}
Bzoj 3524 POI Couriers Chairman Tree