#include "stdlib.h" #define TREAP_N 500005 // 総ノード数の上限 #define TREAP_MAX_TREES 1 // 同時に使う木の本数 typedef long long tkey_t; // treapの型 // 比較関数(変更をわすれない) static int tless(tkey_t a, tkey_t b){ return a>7; x^=x<<17; txorshift_state=x; return x; } // 乱数シードを変えるとき void tseed(unsigned long long s){ if(s==0){ txorshift_state=1; }else{ txorshift_state=s; } } static int tsize(int t){ if(t==0){ return 0; }else{ return tnode[t].size; } } static void tupdate(int t){ if(t==0) return; tnode[t].size=1+tsize(tnode[t].left)+tsize(tnode[t].right); } static int tnewnode(tkey_t val){ int idx; if(0=total) return -1; return tkth(id, total-1-k); } // 全ての木をリセット void tclear(void){ for(int i=0;i