BZOJ-1455 Roma Games

Source: Internet
Author: User

It is also a way to stack problems. Pairing a heap template problem.

#include <cctype> #include <algorithm> #include <cstring> #include <cstdlib> #include < Cstdio> #include <iostream> #define REP (i, L, R) for (int i=l; i<=r; i++) #define CLR (x, C) memset (x, C, sizeof (x) ) #define LL Long long #define MAXN 1000009using namespace Std;inline int read () {int x=0; char Ch=getchar (); while (!isdigit (CH)) Ch=getchar (); while (IsDigit (CH)) x=x*10+ch-' 0 ', Ch=getchar (); return x;} struct Node{int l, r, ch; node () {l=r=ch;}} h[maxn];int N, M, K[MAXN], ROOF[MAXN]; bool Die[maxn];inline int Join (int v, int u) {if (v==u) return v;if (K[v]<k[u]) swap (V, u); h[v].l=u, h[v].r=h[u].ch, h[h [U].ch].l=v, H[u].ch=v;roof[v]=u;return u;} int Top (int v) {return roof[v]==v v:top (Roof[v]);} int ST[MAXN], top;inline int Kill (int v) {die[v]=true; int ans=k[v];if (h[v].ch) {top=0; int t=h[v].ch; while (t) if (h[t]. R) {int k=h[h[t].r].r;int v=h[t].r; h[v].l=h[v].r=h[t].l=h[t].r=0; roof[t]=t, Roof[v]=v;st[++top]=join (t, v); t=k;} else{st[++top]=t; h[t].l=h[t].r=0; roof[t]=t; break;} T=st[top];rep (i, 1, top-1) t=join (T, St[i]);} return ans;} Char S[5];int main () {n=read (); Rep (i, 1, N) k[i]=read (), Roof[i]=i;m=read (), Rep (i, 1, m) {scanf ("%s", s); if (s[0]== ' m ') {i NT V=read (), U=read (); if (!die[v] &&!die[u]) Join (Top (v), Top (U));} else {int V=read (), if (!die[v]) printf ("%d\n", Kill (Top (v))), Else printf ("0\n");}} return 0;}

BZOJ-1455 Roma 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.