用并查集维护线段,从后往前枚举没个删除的位置id[i] 那么,现在删除了这个,就是没有了的,但是上一个id[i + 1]就是还没删除的. 然后现在进行合并 int left = id[i + 1];(相当于每次都加入一个元素a[left]) 它在这个位置,如果能和左右的合并,就是左右邻居都有元素,那么当然是合并最好,因为元素都是大于0的,越长越好. 合并的时候再记录一个数组sum[pos]表示以这个为根的总和是多少.按并查集的思路更新整个并查集即可. 注意一点的就是, 要求ans[i] 那么an…
链接:Destroying Array C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destro…
题意:给定 n 个数,然后每次破坏一个位置的数,那么剩下的连通块的和最大是多少. 析:用并查集来做,从后往前推,一开始什么也没有,如果破坏一个,那么我们就加上一个,然后判断它左右两侧是不是存在,如果存在,那么就合并起来, 然后不断最大值,因为这个最大值肯定是不递减,所以我们一直更新就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <s…
题目链接:https://cn.vjudge.net/problem/CodeForces-722C 题意 给个数组,每次删除一个元素,删除的元素作为一个隔断,问每次删除后该元素左右两边最大连续和 思路 这个题的思路马上就想到的时候,别人直接抢答,还是比较厉害的人了 离线操作,删除变成添加,添加时注意左右两边元素的最大值即可 提交过程 WA 忘了为什么WA了 AC 代码 #include <cstdio> #include <algorithm> using namespace s…
给你n个点m条边,保证已经是个连通图,问每次按顺序去掉给定的一条边,当前的连通块数量. 与其正过来思考当前这边会不会是桥,不如倒过来在n个点即n个连通块下建图,检查其连通性,就能知道个数了 /** @Date : 2017-09-21 23:26:20 * @FileName: HDU 4496 并查集 逆向思维.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github…
Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array…
C. Destroying Array 题目连接: http://codeforces.com/contest/722/problem/C Description You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permuta…
原题链接:https://vjudge.net/problem/511814/origin Description: You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1…
原题中需要求解的是按照它给定的操作次序,即每次删掉一个数字求删掉后每个区间段的和的最大值是多少. 正面求解需要维护新形成的区间段,以及每段和,需要一些数据结构比如 map 和 set. map<int, LL>interval2Sum来维护区间段(u->v),mulitset<LL>sum 来维护最大值.那么每次删除操作后,都需要去interval2Sum中找到对应区间,然后erase掉, 重新生成left -> delId -> right两个区间段,最后在ma…
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1015 思路: 题目是要我们对当前图拆掉k个点,问,每拆一个点后图中有多少个联通块,我们可以逆向思维,先处理出所有操作完成后的最终图,题目中破坏点的操作对于这个图来说就变成了加点扔到并查集的操作了,题目说的图一开始的联通块个数其实就是最终的图加上k个点后联通块的数量,第k个点被删后的图就是一开始处理得到的最终图, 实现代码: #include<bits/stdc++.h> using na…