F - True Liars 带权并查集】的更多相关文章

After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the foggy island, which he had heard…
题目链接:http://poj.org/problem?id=1417 Time Limit: 1000MS Memory Limit: 10000K Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despair…
题意: n块积木,m个操作或询问.每次移动积木的时候,约翰会选择两块积木X,Y,把X搬到Y的上方.如果X已经和其它积木叠在一起了,那么应将这叠积木整体移动到Y的上方:如果Y已经和其它积木叠在一起了的,假设在Y上方最高处的积木为Z,那么应将X所在的那叠积木移动到Z的上方.每次询问当前时刻,某一块积木的下方有多少块积木.n,m<=10^5 题解: 带权并查集.对于每个点x,维护当前所在并查集(也就是这一堆积木中)最下方的积木d[x],最上方的积木fa[x],x到最上方积木的距离f[x],则下方的积木…
F. Palindrome Problem Description A string is palindrome if it can be read the same way in either direction, for example "maram" is palindrome, while "ammar" is not. You are given a string of n characters, where each character is eithe…
True Liars Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2713   Accepted: 868 Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exha…
题意: 给出m个区间和,询问是否有区间和和之前给出的矛盾 NOIp之前做过hdu3038..... 带权并查集维护到根的权值和,向左合并 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; typedef long long ll; inline int read(){ ,f=; ;c=getchar();}…
此题做法多啊 带权并查集,区间dp,前缀和,差分约束 1.自己写的前缀和, 11 #include<bits/stdc++.h> #define rep(i,x,y) for(register int i=x;i<=y;i++) using namespace std; ; inline int read(){ ,f=;char ch=getchar(); ;ch=getchar();} )+(x<<)+(ch^);ch=getchar();} return x*f;} in…
题目链接:http://poj.org/problem?id=2492 题意:给出n个人,m条关系,每条关系表示的两个人异性,判断这m条关系是否有误. 思路:带权并查集,类似poj1182,并查集的向量应用.用1表示x,y异性,0表示同性,不访用f(x,y)表示x,y的关系.容易得出f(x,z)=f(x,y)^f(y,z),之后就好做了.输入一组关系t1,t2,用r1,r2表示其祖先,若相等则查询,即f[t1]与f[t2]是否相等; 若不等,则合并,f[r2]=1^f[t1]^f[t2](手动模…
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1202 题目大意: 刁姹接到一个任务,为税务部门调查一位商人的账本,看看账本是不是伪造的.账本上记录了n个月以来的收入情况,其中第i 个月的收入额为Ai(i=1,2,3...n-1,n), .当 Ai大于0时表示这个月盈利Ai 元,当 Ai小于0时表示这个月亏损Ai 元.所谓一段时间内的总收入,就是这段时间内每个月的收入额的总和. 刁姹的任务是秘密进行的,为了调查商人的账本,她只好跑到…
题面 Bzoj 洛谷 题解 考虑带权并查集,设\(f[i]\)表示\(i\)的父亲(\(\forall f[i]<i\)),\(sum[i]\)表示\(\sum\limits_{j=fa[i]}^ia[j]\),对于一组输入的\([x,y,z]\),有: 1.如果\(f[x-1]=f[y]\) 这个时候直接判断\(sum[y]-sum[x-1]\)是否等于\(z\)就行了. 2.如果\(f[x-1]\not= f[y]\) 将\(f[y]\)的\(f\)定为\(f[x-1]\),则\(sum[f…