1455: Roman Games

Source: Internet
Author: User

1455: Roman Games time limit:5 Sec Memory limit:64 MB
submit:721 solved:272
[Submit] [Status] [Discuss] Description Roman Emperors liked to play killing games. There are n men in his army, and everyone is a separate regiment. A plane geometry test was recently held and everyone got a score. The emperor liked plane geometry, and he sniffed at those who scored very low. He decided to play such a game. It can send two kinds of commands: 1. Merger (I, J). Merge the regiment where I resides and the group where J is located into a regiment. If I, J has a person who is dead, then ignore the command. 2. Kill (i). Kill the person with the lowest score in the group where I was located. If I were dead, this command would be ignored. The emperor wanted him to publish a kill order, and the following generals reported the scores of the people who had been killed. (If this command is ignored, then 0 points) input the first line an integer n (1<=n<=1000000). n indicates the number of soldiers, and m represents the total number of commands. The second row n integers, where number I indicates the score of the soldier numbered I. (Fractions are integers between [0..10000]) The third line, an integer m (1<=m<=100000), 3+i Line describes the article I command. The command is in the following two forms: 1. M I J 2. K ioutput If the command is kill, the corresponding output is the score of the homicide. (If this person does not exist, output 0) Sample Input5
100 90 66) 99 10
7
M 1 5
K 1
K 1
M 2 3
M 3 4
K 5
K 4
Sample Output
10
100
0
66

HINT Source

The problem: Oh hehe hehe and ~ ~ ~ This is not the left-leaning tree template question. Directly set up a left-leaning tree to engage in ... (But I was the first to write the need to maintain the Father node left-leaning tree, it seems a little trouble, but also good, is more than a few statements)
1/**************************************************************2Problem:14553 User:hansbug4 language:pascal5 result:accepted6Time:4028Ms7Memory:35384KB8****************************************************************/9  Ten var One I,j,k,l,m,n:longint; AA,lef,rig,fix,fat,mak:Array[0..1500000] ofLongint; - Ch:char; - functionmin (x,y:longint): Longint; the          begin -               ifX<y ThenMin:=xElsemin:=y; -          End; - functionMax (x,y:longint): Longint; +          begin -               ifX>y ThenMax:=xElsemax:=y; +          End; A procedureSwapvarx,y:longint); at           varZ:longint; -           begin -z:=x;x:=y;y:=Z; -           End; - procedureMergevarx,y:longint); -           begin in                ifx=0  Then -                   begin tofat[y]:=fat[x];fat[x]:=0; + swap (x, y); -                   End; the                ify=0  Thenexit; *                ifA[Y]&LT;A[X] Then $                   beginPanax Notoginsengfat[y]:=fat[x];fat[x]:=0; - swap (x, y); the                   End; + merge (rig[x],y); Afat[rig[x]]:=x; theFix[x]:=min (Fix[lef[x]],fix[rig[x]) +1; +                ifFIX[LEF[X]]&LT;FIX[RIG[X]] Thenswap (lef[x],rig[x]); -           End; $ functionGetfat (x:longint): Longint; $          begin -                whileFat[x]<>0  Dox:=Fat[x]; - exit (x); the          End; - beginWuyi READLN (n); theFillchar (Lef,sizeof (LEF),0); -Fillchar (rig,sizeof rig),0); WuFillchar (fix,sizeof (fix),0); -Fillchar (fat,sizeof (FAT),0); AboutFillchar (Mak,sizeof (MAK),0); $       fori:=1  toN Doread (a[i]); - Readln; - Readln (m); -       fori:=1  toM Do A          begin + read (CH); the                CaseUpCase (CH) of -                    'M':begin $ readln (j,k); the                             if(mak[j]=1)or(mak[k]=1) Thencontinue; theJ:=getfat (j); k:=Getfat (k); the                             ifJ=k Thencontinue; the merge (j,k); -                    End; in                    'K':begin the Readln (j); the                             ifmak[j]=1  Then About                                begin theWriteln (0); the continue; the                                End; +j:=Getfat (j); -mak[j]:=1; the Writeln (A[j]);Bayi merge (Lef[j],rig[j]); thej:=Lef[j]; thefat[j]:=0; -                    End; -               End; the          End; the Readln; the End.

1455: Roman Games

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.