Bzoj 1455: Roman games (paired heap + and check set)

Source: Internet
Author: User

Can be stacked water problem


#include <bits/stdc++.h>using namespace std;const int MAXN = 1000009;struct Node {Node *l, *r, *ch;int v, id;} POOL[MAXN], *null, *pt = Pool, *q[maxn];node* newNode (int v, int id) {pt->l = Pt->r = Pt->ch = null; pt->v = v; pt->id = ID;return pt++;}void init () {null = pt++;null->l = Null->r = Null->ch = null;}node* Join (node* x, node* y) {if (X->v < y->v) swap (x, y);x->l = y; x->r = y->ch;y->ch->l = x; y->ch = x;return y;}struct PH {node* Root;void init () {root = null;}inline node* Top () {return root;}inline void push (int id, int v) {node* t = NewNode (v, id);root = root = = null? t:join (root, t);}void Pop () {if (root->ch! = null) {int n = 0;for (node* t = root->ch; t! = null; q[n++] = t, t = t->r);int m = n >> 1;for (int i = 0; i < m; i++) {q[i]->l = Q[i]->r = null;q[i + m]->l = q[i + m]->r = null;Q[i] = join (Q[i], Q[i + M]);}root = q[0];if ((N & 1) && m) root = Join (root, q[n-1]);for (int i = 1; i < m; i++)root = Join (root, q[i]);} elseroot = null;}} S[MAXN];bool ALIVE[MAXN];int FA[MAXN]; int find (int x) {return x = = Fa[x]? x:fa[x] = Find (fa[x]);} int main () {init ();int N; scanf ("%d", &n);for (int i = 0; i < N; i++) {Fa[i] = i;Alive[i] = true;int mark; scanf ("%d", &mark);s[i].init ();S[i].push (i, Mark);}int M; scanf ("%d", &m);While (m--) {char C; scanf ("%c", &c);if (c = = ' M ') {int u, v; scanf ("%d%d", &u, &v); u--; v-- ;if (!alive[u] | |!alive[v]) continue;u = Find (u); v = find (v);if (U = = v)continue;ElseFa[u] = v;s[v].root = Join (S[u].root, s[v].root);} else {int t; scanf ("%d", &t); t--;if (!alive[t]) {puts ("0");continue;}t = find (t);node* o = s[t].top (); S[t].pop ();Alive[o->id] = false;printf ("%d\n", o->v);}}return 0;}


1455: Roman Games time limit: 5 Sec Memory Limit: MB
Submit: 877 Solved: 354
[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
M 1 5
K 1
K 1
M 2 3
M 3 4
K 5
K 4
Sample Output



Bzoj 1455: Roman games (paired heap + and check set)

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: 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.