P4971 断罪者
首先,不难看出可以给每个集合开一个可并堆,然后乱搞就可以了
主要的问题就是将罪恶值清零和减少罪恶值该怎么搞
罪恶值清零可以直接找到这个节点然后把值变为零,再把它的左右儿子分别并到这个节点所在的根节点的可并堆里
减少罪恶值可以直接把根节点减去这个值,然后把左右儿子重新合并上去就好了
明明完全不会指针却为了卡常白花了一个小时最后只好妥协用结构体
//minamoto
#include<bits/stdc++.h>
#define ll long long
#define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
inline int max(const int &x,const int &y){return x>y?x:y;}
inline void swap(int &x,int &y){x^=y^=x^=y;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
ll read(){
ll res,f=1;char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=2e6+5;
struct node{int v,l,r,d;}p[N];int fa[N],rt;
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int merge(int x,int y){
if(!x||!y)return x|y;if(p[x].v<p[y].v)swap(x,y);
p[x].r=merge(p[x].r,y),fa[p[x].r]=x;
if(p[p[x].l].d<p[p[x].r].d)swap(p[x].l,p[x].r);p[x].d=p[p[x].r].d+1;
return x;
}
void dec(int x,int val,bool typ){
p[x].v-=val;if(p[x].v<0)p[x].v=0;
int l=p[x].l,r=p[x].r;fa[l]=l,fa[r]=r;
p[x].l=p[x].r=p[x].d=0,rt=merge(l,r);
typ?merge(find(x),rt):merge(rt,x);
}
int n,m,T,w,typ,x,y,sum;bool vis[N];ll k;
void solve(){
n=read(),m=read();
fp(i,1,n)fa[i]=i,vis[i]=0,p[i].v=read(),p[i].l=p[i].r=p[i].d=0;
while(m--){
typ=read(),x=read();
switch(typ){
case 2:dec(x,p[x].v,1);break;
case 3:y=read(),dec(find(x),y,0);break;
case 4:y=read(),merge(find(x),find(y));break;
}
}
y=0,sum=0;fp(i,1,n)if(!vis[x=find(i)])vis[x]=1,sum+=p[x].v,y=max(y,p[x].v);
if(w==2)sum-=y;if(w==3)sum+=y;
if(!sum)printf("Gensokyo ");
else if(sum<=k)printf("Heaven ");
else printf("Hell ");
printf("%d\n",sum);
}
int main(){
// freopen("testdata.in","r",stdin);
T=read(),w=read(),k=read();
while(T--)solve();
return 0;
}
P4971 断罪者的更多相关文章
随机推荐
- BNUOJ 1585 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- [codeforces494B]Obsessive String
[codeforces494B]Obsessive String 试题描述 Hamed has recently found a string t and suddenly became quite ...
- Python基础之 一 字典(dict)
字典:是一种key - value的数据类型.语法:info = { key:value }特性:无序,key必须唯一(所以天生去重) 方法如下:del dict[key]:删除字典指定键len(di ...
- C#.NET 无法直接启动带有类库输出类型的项目怎么办
我把Driver.cs文件去掉了一行注释,发现报错 右击这个解决方案,选择属性,然后再启动项目中改成MySample
- Datagridview CurrentRow.Index
int index = dataGridView1.CurrentRow.Index; //获取当前选择行引导 string str = dataGridView1.Rows[index].Cell ...
- linux设备驱动归纳总结(八):2.match.probe.remove
linux设备驱动归纳总结(八):2.总线.设备和驱动的关系 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
- simple-framework(MaliSDK框架分析)
simple-framework(Mali SDK框架分析) 1.全部的定义及实现放在同一个命名空间中.文件包括#include一般在命名空间的外面. 总的命名空间为namespace MaliSDK ...
- [DLX反复覆盖] poj 1084 Square Destroyer
题意: n*n的矩形阵(n<=5),由2*n*(n+1)根火柴构成,那么当中会有非常多诸如边长为1,为2...为n的正方形,如今能够拿走一些火柴,那么就会有一些正方形被破坏掉. 求在已经拿走一些 ...
- Codeforces Round #214 (Div. 2) C. Dima and Salad 背包
C. Dima and Salad Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to ...
- js生成页面水印
路: 获取想要插入水印的文档节点的顶点坐标值x,y. 获取文档节点的高度heigt和宽度width. 用div包裹文字来生成水印. 定义好div的长宽高间距等各种属性. 定义虚拟节点createDoc ...