F.a.qs |
Home |
discuss |
Problemset |
Status |
ranklist |
Contest |
modifyuser gryz2016 |
Logout |
Donate this site |
Notice: Since this OJ is built under the Linux platform, and many of the data are produced under Windows, please note the input, output statements and data types and ranges to avoid unnecessary re appearance. 1455: Roman Games time limit:5 Sec Memory limit:64 MB
submit:1061 solved:439
[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: Bare ground left-biased heap ... Code:
1#include <cstdio>2#include <algorithm>3 #defineN 10000054 5 using namespacestd;6 7 structZPD8 {9 intn,m,fa[n],ls[n],rs[n],d[n],v[n],cnt;Ten BOOLVis[n]; One intFindintx) {if(fa[x]==x)returnXElseFa[x]=find (Fa[x]);returnfa[x];} A intMergeintXinty) - { - if(!x)returny; the if(!y)returnx; - if(v[x]>V[y]) swap (x, y); -rs[x]=merge (rs[x],y); - if(d[rs[x]]>d[ls[x]) swap (ls[x],rs[x]); +d[x]=d[rs[x]]+1; - returnx; + } A voidInsert () at { -scanf"%d",&N); - for(intI=1; i<=n;i++) -scanf"%d",&V[i]); - for(intI=1; i<=n;i++) fa[i]=i; -d[0]=-1; inscanf"%d",&m); - Charch[Ten]; to for(intI=1; i<=m;i++) + { -scanf"%s", ch);intx, y; the if(ch[0]=='M') * { $scanf"%d%d",&x,&y);Panax Notoginseng if(vis[x]| | Vis[y])Continue; - intP=find (x), q=find (y); the if(p!=q) + { A intt=merge (p,q); thefa[p]=fa[q]=T; + } - } $ Else $ { -scanf"%d",&x); - if(Vis[x]) printf ("0\n"); the Else - {Wuyi intP=find (x); vis[p]=1; theprintf"%d\n", V[p]); -fa[p]=merge (Ls[p],rs[p]); Wufa[fa[p]]=Fa[p]; - } About } $ } - } - }ZPD; - intMain () A { + Zpd.insert (); the return 0; -}
HOME back
??? Chinese????? 中文版???
Copyright ©2008-2012 Big View Online Assessment | Xiang ICP 备 13,009,380th # | Webmaster statistics based on OpenSource project Hustoj.
C + + Path advanced--left-leaning Heap (Roman games)