absi2011's Blog & Daily Life.

全新的开始       我要省选翻盘       I wanna AK in 高考\化学       自此,生无可恋
[破碎的状态] [-5] BZOJ 2333
[破碎的状态] [-4] Tyvj 1728 普通平衡树

[破碎的状态] [-5] BZOJ 1455

absi2011 posted @ Jul 17, 2016 04:18:58 PM in 刷题记录 with tags 小高考 bzoj 配对堆 , 572 阅读

这是一道权限题,感谢@wnjxyk 的帮忙

可并堆练习题..

这题没啥好说的...

代码:

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
struct node
{
    int val;
    int id;
    node * right;
    node * ch;
};
node * null;
node * a[1000005];
node * new_node(int x,int y)
{
    static node a[1000005];
    static int top=0;
    node * t=&a[top++];
    t->val=x;
    t->id=y;
    t->right=null;
    t->ch=null;
    return t;
}
node * join(node * x,node * y)
{
    if (x->val<y->val) swap(x,y);
    x->right=y->ch;
    y->ch=x;
    return y;
}
node * u(node * x)
{
    if (x==null) return x;
    node * y=x->right;
    if (y==null) return x;
    x->right=null;
    node * z=y->right;
    if (z==null) return join(x,y);
    y->right=null;
    return join(u(z),join(x,y));
}
int father[1000005];
int death[1000005];
int findroot(int x)
{
    int root;
    for (root=x;father[root]!=-1;root=father[root]) ;
    int temp;
    for (;father[x]!=-1;)
    {
        temp=father[x];
        father[x]=root;
        x=temp;
    }
    return root;
}
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    null=new_node(1000000,-1);
    null->right=null;
    null->ch=null;
    int n;
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        father[i]=-1;
        int x;
        scanf("%d",&x);
        a[i]=new_node(x,i);
    }
    int m;
    scanf("%d",&m);
    for (i=0;i<m;i++)
    {
        static char c[5];
        scanf("%s",c);
        if (c[0]=='K')
        {
            int x;
            scanf("%d",&x);
            x--;
            if (death[x])
            {
                puts("0");
                continue;
            }
            x=findroot(x);
            printf("%d\n",a[x]->val);
            death[a[x]->id]=true;
            a[x]=u(a[x]->ch);
        }
        else
        {
            int x,y;
            scanf("%d%d",&x,&y);
            x--;
            y--;
            if (death[x]) continue;
            if (death[y]) continue;
            x=findroot(x);
            y=findroot(y);
            if (x==y) continue;
            a[x]=join(a[x],a[y]);
            father[y]=x;
        }
    }
    return 0;
}
boardmodelpaper.com 说:
Jan 27, 2024 05:38:00 PM

The Board model paper" typically refers to a sample or model question paper that is designed by educational boards or institutions for various exams. These papers serve as practice material for students preparing for exams, providing them with an idea of the question format, difficulty level, and the type of content that may be covered in the actual examination. boardmodelpaper.com Model papers are usually created for specific subjects or courses. They cover a range of topics and chapters that students are expected to have studied during the academic term. Students often use these educational board model papers as an integral part of their exam preparation strategy, helping them familiarize themselves with the exam pattern and refine their understanding of the subject matter.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter