跳到正文

题解

题解 P1801 【黑匣子_NOI导刊2010提高(06)】

风格EX约 2 分钟
原文
文章信息与版本

文章信息

发布
2016年6月18日
收录
2025年12月12日
更新
2026年9月6日
篇幅
约 2 分钟
获赞
1
题目
P1801

版本

  1. v1当前

咳咳 这个 小白痴什么数据结构都没用

思想 :离线做

先都读进来 排个序 然后查询时 依次把那次之后的删掉(这样比插排快吧…)

注意:每次查询第几大都是上次加一,我完全可以搞一个光标,确定当前第k大啊,输出后dec(i);就好了

于是乎。上代码。。。。。。

[/color][codep ]

C++
program project1;
var a,rank,b,weizhi:array[1..200000]of longint;
    i,n,m,k,j,hehe:longint;
procedure kuaipai(z,y:longint);
var zz,yy,mid,jiaohuan:longint;
begin
  mid:=a[(z+y)shr 1];
  zz:=z;yy:=y;
 repeat
  while a[zz]<mid do inc(zz);
  while a[yy]>mid do dec(yy);
  if zz<=yy then begin jiaohuan:=a[zz];a[zz]:=a[yy];a[yy]:=jiaohuan;
    jiaohuan:=rank[zz];rank[zz]:=rank[yy];rank[yy]:=jiaohuan;
  inc(zz);dec(yy); end;
  until zz>yy;
  if zz<y then kuaipai(zz,y);
  if z<yy then kuaipai(z,yy);
end;
procedure shanchu(yy:longint);
var hehe:longint;
begin
  hehe:=weizhi[yy];
  a[hehe]:=200001;
  if hehe<=k then begin inc(k);while a[k]=200001 do inc(k);end;
end;
begin
  readln(n,m);
  for i:=1 to n do begin read(a[i]);rank[i]:=i;end;  readln;
  for i:=1 to m do read(b[i]); readln;
  kuaipai(1,n);
  for i:=1 to n do weizhi[rank[i]]:=i;
  k:=m;  j:=m;
  for i:=m downto 1 do begin
    for hehe:=n downto (b[i]+1) do shanchu(hehe); rank[m]:=a[k];dec(m);
    dec(k);while a[k]=200001 do dec(k);
    n:=b[i];
  end;
  for i:=1 to j do writeln(rank[i]);
end.
[/codep ]
原文
存档评论1 条抓取于