Bzoj 1455: Roman Games [can be stacked]

Source: Internet
Author: User

1455: Roman Games time limit:5 Sec Memory limit:64 MB
submit:1715 solved:718
[Submit] [Status] [Discuss] Description

The Roman Emperor loved 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 will be reported)

Input

The first line is 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. Ki

Output

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 Output10
100
0
66
HINT

Some of the data are as follows Judgeonline/upload/201607/aa.rar

Naked question

Left-leaning tree

And check if the maintenance is in a heap.

Suddenly found left to write right, but still use RC dis unexpectedly only slower than 200ms too weird

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;#defineLC T[X].L#defineRC T[X].RtypedefLong Longll;Const intn=1e6+5, inf=1e9;inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; C=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; C=GetChar ();} returnx*F;}intFa[n];inlineintFindintx) {returnx==fa[x]?x:fa[x]=find (Fa[x]);}structnode{intL,r,v,dis;} T[n];intMerge (intXinty) {    if(x==0|| y==0)returnX|y; if(t[x].v>t[y].v) Swap (x, y); RC=Merge (rc,y); if(t[lc].dis<T[rc].dis) Swap (LC,RC); T[x].dis=t[rc].dis+1; returnx;} intN,q,a[n],x,y,vis[n];Chars[2];intMain () {//freopen ("In.txt", "R", stdin);n=read ();  for(intI=1; i<=n;i++) T[i].v=read (), fa[i]=i; t[0].dis=-1; Q=read ();  while(q--) {scanf ("%s", s); if(s[0]=='M') {x=read (); y=read (); if(vis[x]| | Vis[y])Continue; X=find (x); y=find (y); if(x!=y) fa[x]=fa[y]=Merge (x, y); }Else{x=read (); if(Vis[x]) puts ("0"); Else{x=find (x); vis[x]=1; printf ("%d\n", T[X].V); FA[X]=Merge (LC,RC); FA[FA[X]]=Fa[x]; }        }    }}

Bzoj 1455: Roman Games [can be stacked]

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.