Tag-主席树

Icontofig 's Blog // 我们的征程是星辰大海!Away From OI,Come to ICPC(查看友链请点About Me)

 2019-08-01 11:29:45 |  1 Comments  |  主席树

主席树模板

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
int get_num(){
    int num = 0;
    char c;
    bool flag = false;
    while((c = getchar()) == ' ' || c == '\r' || c == '\n');
    if(c == '-')
        flag = true;
    else num = c - '0';
    while(isdigit(c = getchar()))
        num = (num<<3) + (num<<1) + c - '0';
    return (flag ? -1 : 1) * num;
}
const int maxn = 2e5+5;
struct tree{
    int l,r;
    tree *lc,*rc;
    int sum;    
}pool[maxn<<5],*root[maxn],*null;
int cnt = 0;
void init(){
    null = pool;
    null->sum = 0;
    null->lc = null->rc = null; 
    null->l = null->r = 0;
    return;
}
tree *new_node(){
    tree *node = pool + ++cnt;
    node->lc = node->rc = null;
    node->sum = 0;
    node->l = node->r = 0;
    return node;
}
tree *build(int l,int r){
    tree *node = new_node();
    node->l = l;
    node->r = r;
    if(l == r)return node;
    int mid = (l + r) >> 1;
    node->lc = 
Title - Artist
0:00