2761: [JLOI2011] No repetition number (balance tree)

Source: Internet
Author: User
Tags repetition

2761: [JLOI2011] do not repeat digital time limit:10 Sec Memory limit:128 MB
submit:2133 solved:825
[Submit] [Status] [Discuss] Description gives the number of N, requires the repetition of the removal, only the first occurrence of the number. For example, the number given is 1 2 18 3 3 19 2 3 6 5 4, of which 2 and 3 have duplicates, the result of removal is 1 2 18 3 19 6 5 4. Input enters the first behavior positive integer t, which indicates that there is a T group of data. Next, each set of data consists of two rows, the first positive integer n, which indicates the number of N. The second behavior is to go to a heavy n positive integer. Output for each set of data, a single line, the number left after the deduplication, separated by a space between the numbers. Sample Input2
11
1 2 18 3 3 19 2 3 6 5 4
6
1 2 3 4 5 6
Sample OUTPUT1 2 18 3 19 6 5 4
1 2 3 4 5 6
HINT

For 30% of the data, 1 <= N <= 100, the number given is not greater than 100, are non-negative integers;


For 50% of the data, 1 <= N <= 10000, the number given is not greater than 10000, are non-negative integers;


For 100% of the data, 1 <= N <= 50000, given the number within the 32-bit signed integer range.


Tips :


Because of the large amount of data, students using C + + use scanf and printf for input and output operations to avoid wasting unnecessary time.


Source

The problem: After a long time, I saw this problem again = = This time I use the balance tree query, simple \ (O\left (n\log N \right) \), and the speed seems to be faster than the last hash
1/**************************************************************2Problem:27613 User:hansbug4 language:pascal5 result:accepted6Time:1840Ms7Memory:2180KB8****************************************************************/9  Ten var One I,j,k,l,m,n,head:longint; AB:Array[0..100000] ofLongint; -Lef,rig,fix:Array[0..100000] ofLongint; - procedureRtvarx:longint); the           varF,l:longint; -           begin -                if(x=0)or(lef[x]=0) Thenexit; -f:=x;l:=Lef[x]; +lef[f]:=Rig[l]; -rig[l]:=F; +x:=l; A           End; at procedureLtvarx:longint); -           varF,r:longint; -           begin -                if(x=0)or(rig[x]=0) Thenexit; -f:=x;r:=Rig[x]; -rig[f]:=Lef[r]; inlef[r]:=F; -x:=R; to           End; + functionInsvarX:longint;y:longint): boolean; -          begin theins:=true; *               ifx=0  Then $                  beginPanax Notoginsengx:=y; - exit; the                  End; +               ifA[Y]&LT;A[X] Then A                  begin the                       iflef[x]=0  ThenLef[x]:=yElseins:=ins (lef[x],y); +                  End -               Else ifA[Y]&GT;A[X] Then $                    begin $                         ifrig[x]=0  ThenRig[x]:=yElseins:=ins (rig[x],y); -                    End -               Elseexit (false); the          End; - beginWuyi Readln (m); the Randomize; -       forl:=1  toM Do Wu          begin -READLN (n); head:=0; About                fori:=1  toN Do $                   begin - read (a[i]); -lef[i]:=0; rig[i]:=0; -fix[i]:=random (maxlongint); A                   End; +readln;k:=0; the                fori:=1  toN Do -                   ifINS (head,i) Then $                      begin the Inc (k); theb[k]:=A[i]; the                      End; the                fori:=1  toK Do -                   ifI<k ThenWrite (B[i],' ')ElseWriteln (B[i]); in          End; the Readln; the End.

2761: [JLOI2011] No repetition number (balance tree)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.