实现了一下,比平衡树还是要短一些的。
AC Code:
#include<bits/stdc++.h>
#define S 1005
#define maxn 500005
#define nxt B[x].rb
using namespace std;
char cb[1<<18],*cs=cb,*ct=cb;
#define getc() (cs==ct&&(ct=(cs=cb)+fread(cb,1,1<<18,stdin),cs==ct)?0:*cs++)
inline void read(int &res){
char ch;bool f=0;
for(;!isdigit(ch=getc());) if(ch=='-') f=1;
for(res=ch-'0';isdigit(ch=getc());res=res*10+ch-'0');
(f) && (res = -res);
}
char pt[1<<18],*ps=pt;
inline void Push(char c){
if(ps-pt==(1<<18)) printf("%s",pt),ps=pt;
*ps++=c;
}
inline void put(int x){
static int sta[20];
if(!x) Push('0');
if(x<0) Push('-'),x=-