procedureready; var dis_:longint; begin dis_:=0; read(n,m); for i:=1to n do begin read(num[i]); //值 place[i]:=i; //原数组编号 end; Sort(1,n); //排序 num[0]:=-1000000007; //血的教训 for i:=1to n do begin if num[i]<>num[i-1] then//去重 inc(dis_); dis[place[i]]:=dis_; //原数组的数字的主席树编号是 diss[dis[place[i]]]:=num[i]; //主席树的编号对应的原数组 end; dis_num:=dis_; //去重后的数字个数 end;
var left,right,node:array[-1..4000440] of longint; num,root:array[-1..200100] of longint; place,dis,diss:array[-1..200100] of longint; i,j,n,m,u,v,k,cnt,now,t,d,dis_num:longint; node_1,node_2:longint;
procedureSort(l,r:longint); var i,j,s,t:longint; begin i:=l; j:=r; s:=num[(l+r) div2]; repeat while num[i]<s do inc(i); while num[j]>s do dec(j); if i<=j then begin t:=num[i]; num[i]:=num[j]; num[j]:=t; t:=place[i]; place[i]:=place[j]; place[j]:=t; inc(i); dec(j); end; until i>=j; if i<r then Sort(i,r); if j>l then Sort(l,j); end;
procedureready; var dis_:longint; begin dis_:=0; read(n,m); for i:=1to n do begin read(num[i]); place[i]:=i; end; Sort(1,n); num[0]:=-1000000007; for i:=1to n do begin if num[i]<>num[i-1] then inc(dis_); dis[place[i]]:=dis_; end; for i:=1to n do diss[dis[place[i]]]:=num[i]; dis_num:=dis_; end;
functionBuild(l,r:longint):longint; var mid,now:longint; begin inc(cnt); now:=cnt; node[now]:=0;
早苗入手了最新的高级打字机。最新款自然有着与以往不同的功能,那就是它具备撤销功能,厉害吧。 请为这种高级打字机设计一个程序,支持如下3种操作: T x:在文章末尾打下一个小写字母x。(type操作) U x:撤销最后的x次修改操作。(Undo操作)(注意Query操作并不算修改操作) Q x:询问当前文章中第x个字母并输出。(Query操作)文章一开始可以视为空串。
var n,cnt,hao,tot:longint; len,lson,rson,root:array[0..2000035] of longint; value:array[0..2000035] of char; s:string; HuHa:char;
procedurebuild(var rt:longint; fa,l,r,po:longint); var mid:longint; begin if (rt=0) then begin inc(tot); rt:=tot; end; if l=r then begin value[rt]:=HuHa; exit; end;
mid:=(l+r) div2; if (po<=mid) then begin rson[rt]:=rson[fa]; build(lson[rt],lson[fa],l,mid,po); end; if (po>=mid+1) then begin lson[rt]:=lson[fa]; build(rson[rt],rson[fa],mid+1,r,po); end; end;
functionQuery(rt,l,r,po:longint):char; var mid:longint; begin if l=r then exit(value[rt]); mid:=(l+r) div2; if (po<=mid) then exit(Query(lson[rt],l,mid,po)); if (po>=mid+1) then exit(Query(rson[rt],mid+1,r,po)); end;
begin readln(n); while n>0do begin readln(s); if s[1]='T'then begin HuHa:=s[3]; inc(cnt); len[cnt]:=len[cnt-1]+1; Build(root[cnt],root[cnt-1],1,100007,len[cnt]); end;
if s[1]='U'then begin delete(s,1,2); val(s,hao); inc(cnt); len[cnt]:=len[cnt-hao-1]; root[cnt]:=root[cnt-hao-1]; end;
if s[1]='Q'then begin delete(s,1,2); val(s,hao); writeln(Query(root[cnt],1,100007,hao)); end; dec(n); end; end.