zoukankan      html  css  js  c++  java
  • bzoj2761 用treap写了写

     1 program hehe;
     2 type
     3  shu=record
     4   l,r,w,h,y,s:longint;
     5  end;
     6 var
     7  n,i,j,k,t,ans,root,size:longint;
     8  x:array[0..100000] of shu;
     9 
    10   procedure update(a:longint);
    11   begin
    12    x[a].s:=x[x[a].l].s+x[x[a].r].s+x[a].w;
    13   end;
    14 
    15   procedure rturn(var a:longint);
    16   var
    17    t:longint;
    18   begin
    19    t:=x[a].l;
    20    x[a].l:=x[t].r;
    21    x[t].r:=a;
    22    x[t].s:=x[a].s;
    23    update(a);
    24    a:=t;
    25   end;
    26 
    27   procedure lturn(var a:longint);
    28   var
    29    t:longint;
    30   begin
    31    t:=x[a].r;
    32    x[a].r:=x[t].l;
    33    x[t].l:=a;
    34    x[t].s:=x[a].s;
    35    update(a);
    36    a:=t;
    37   end;
    38 
    39   procedure insert(var a:longint;b:longint);
    40   begin
    41    if a=0 then
    42    begin
    43     inc(size);
    44     a:=size;
    45     x[a].s:=1;
    46     x[a].w:=1;
    47     x[a].h:=b;
    48     x[a].y:=random(maxlongint);
    49     exit;
    50    end;
    51    inc(x[a].s);
    52    if x[a].h=b then inc(x[a].w)
    53    else if b>x[a].h then
    54    begin
    55     insert(x[a].r,b);
    56     if x[x[a].r].y<x[a].y then lturn(a);
    57    end
    58    else
    59    begin
    60     insert(x[a].l,b);
    61     if x[x[a].l].y<x[a].y then rturn(a);
    62    end;
    63   end;
    64 
    65   function find(a,b:longint):boolean;
    66   begin
    67    if a=0 then exit(false);
    68    if x[a].h=b then exit(true);
    69    if b>x[a].h then exit(find(x[a].r,b));
    70    exit(find(x[a].l,b));
    71   end;
    72 
    73 begin
    74  readln(t);
    75  for i:=1 to t do
    76  begin
    77   read(n);
    78   root:=0;
    79   size:=0;
    80   fillchar(x,sizeof(x),0);
    81   for j:=1 to n do
    82   begin
    83    read(k);
    84    if not find(root,k) then
    85    if j=1 then write(k)
    86    else write(' ',k);
    87    insert(root,k);
    88   end;
    89   writeln;
    90  end;
    91 end.
    View Code

    2761: [JLOI2011]不重复数字

    Time Limit: 10 Sec  Memory Limit: 128 MB
    Submit: 2336  Solved: 895
    [Submit][Status][Discuss]

    Description

    给出N个数,要求把其中重复的去掉,只保留第一次出现的数。
    例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4。
     

    Input

    输入第一行为正整数T,表示有T组数据。
    接下来每组数据包括两行,第一行为正整数N,表示有N个数。第二行为要去重的N个正整数。
     

    Output

     
    对于每组数据,输出一行,为去重后剩下的数字,数字之间用一个空格隔开。

    Sample Input

    2
    11
    1 2 18 3 3 19 2 3 6 5 4
    6
    1 2 3 4 5 6

    Sample Output

    1 2 18 3 19 6 5 4
    1 2 3 4 5 6

    HINT

    对于30%的数据,1 <= N <= 100,给出的数不大于100,均为非负整数;


    对于50%的数据,1 <= N <= 10000,给出的数不大于10000,均为非负整数;


    对于100%的数据,1 <= N <= 50000,给出的数在32位有符号整数范围内。


    提示:


    由于数据量很大,使用C++的同学请使用scanf和printf来进行输入输出操作,以免浪费不必要的时间。


    Source

     
    [Submit][Status][Discuss]
  • 相关阅读:
    fullCalendar改造计划之带农历节气节假日的万年历(转)
    Linked List Cycle
    Remove Nth Node From End of List
    Binary Tree Inorder Traversal
    Unique Binary Search Trees
    Binary Tree Level Order Traversal
    Binary Tree Level Order Traversal II
    Plus One
    Remove Duplicates from Sorted List
    Merge Two Sorted Lists
  • 原文地址:https://www.cnblogs.com/chensiang/p/4586666.html
Copyright © 2011-2022 走看看