题意:给出长度为n的序列,每次去掉一个数,使得序列分成几块,问当前权值最大块的权值。
思路:提供两种,第一种用multiset和前缀和直接暴力模拟。
第二种用并差集,假设坐标i为一个去掉的数,那么f[i]记录的是i所在连续的去掉的数的区间的最左端,其余的看代码QAQ。

第一种
#include<bits/stdc++.h>
using namespace std;
long long   a[100001], t[100001];
int main() {int n;cin >> n;for(int i = 1; i <= n; ++i)cin >> a[i], t[i] = t[i - 1] + a[i];multiset<long long>s {0, n + 1}, q {t[n]};for(int i = 0; i < n; ++i) {int p;cin >> p;auto j = s.insert(p), k = j, l = j;q.erase(q.find(t[*++l - 1] - t[*--k]));q.insert(t[*j - 1] - t[*k]);q.insert(t[*l - 1] - t[*j]);cout << *--q.end() << endl;}return 0;
}
#include<bits/stdc++.h>
using namespace std;
int b[100005], f[100005];
long long a[100005], ans[100005];
int find(int x) {return f[x] == x ? x : f[x] = find(f[x]);
}
int main() {int n;scanf("%d\n", &n);for (int i = 1; i <= n; i++)scanf("%I64d", &a[i]);for (int i = 1; i <= n; i++)scanf("%d", &b[i]);ans[n] = 0;for (int i = n; i > 1; i--) {int x = b[i];f[x] = x;if (f[x + 1])a[f[x + 1] = x] += a[x + 1];if (f[x - 1])a[f[x] = find(x - 1)] += a[x];ans[i - 1] = max(ans[i], a[find(x)]);}for (int i = 1; i <= n; i++)printf("%I64d\n", ans[i]);
}

codeforces 722C Destroying Array相关推荐

  1. Codeforces 722C. Destroying Array

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. CodeForces - 722C Destroying Array (并查集/集合的插入和删除)

    原题链接:https://vjudge.net/problem/511814/origin Description: You are given an array consisting of n no ...

  3. CodeForces - 722C Destroying Array(倒着并查集+离线处理)

    题目链接:点击查看 题目大意:给出一个数列a,现在给出操作b,每次操作都会删除掉数列a中指定位置的数,问每次删除后,最大连续字段和是多少 题目分析:一开始看到最大连续字段和,以为是要用dp,又看了一下 ...

  4. CodeForces 722C Destroying Array

    并查集,离线操作. 将操作倒着进行,一开始所有数字都没有加入到数组中,然后倒着一个一个加入,更新最大值. #pragma comment(linker, "/STACK:1024000000 ...

  5. Codeforces C. Destroying Array

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round 722C:Destroying Array(离线)

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. 并查集巧妙用法(codeforces)C. Destroying Array

    C. Destroying Array 题意:对样例进行分析: ,n == 4,数组是1 3 2 5,然后下一行就是每一个数就得输出,代表的是删除数组中的第几个数,然后在删除后的数组中找到分成的段的和 ...

  8. Codeforces 1054D Changing Array

    Codeforces 1054D Changing Array 做法:给定一个序列,每个数可以把在2进制k位下取反,也可以不变,在改变后,这个序列异或和不为0的区间的个数.考虑如何求出尽可能少的异或为 ...

  9. CodeForces - 1610B Kalindrome Array

    B. Kalindrome Array time limit per test1 second memory limit per test256 megabytes An array [b1,b2,- ...

最新文章

  1. LED,硅光电池的光能-电能转换是可逆的吗?
  2. Ubuntu下Qt配置Opencv
  3. docker的学习总结
  4. php print_r this,PHP 打印函数之 print print_r
  5. 计算机科学讨论,第七章计算机科学讨论报告
  6. HDU2066:一个人的旅行(Dijkstra)
  7. 静态代理、动态代理、AOP
  8. php知识点_PHP那些琐碎的知识点(整理)
  9. 线性表的基本操作Basic operation of SequenceList
  10. LeetCode题解:幂集
  11. u盘虚拟启动cd linux,CDlinux系统用U盘搭建启动盘
  12. 11gR2 RAC vip和network资源的依赖性与频繁failover
  13. codeup3692 星期英文单词
  14. 复习————吃饭睡觉打豆豆
  15. 推荐一款免费的内网穿透工具ngrok
  16. logback日志文件
  17. BIM IFC模型在线查看工具
  18. 雅可比(Jacobi)方法
  19. 关于win7注册表中文件关联应用程序的规则
  20. HTML标签:头部相关标签

热门文章

  1. x64dbg 实现插件Socket反向通信
  2. 10 款免费 PDF 阅读器软件工具分享
  3. chm打开秒退_用熊猫看书来看chm,却自动退出,什么原因?
  4. Apex英雄手游国服何时上线 Apex英雄手游和端游互通吗
  5. ISIS详细配置实验
  6. php汽车租赁网站_ThinkPHP实战开发汽车租赁网站项目教程
  7. 什么是数据湖?为什么需要数据湖?
  8. SCI 论文常用词汇 持续更新中。。。
  9. 我的专业作文300字计算机,我喜爱的职业300字
  10. 阿里巴巴在知乎上又出事了