传送门

Luogu

解题思路

想要做这道题,只要会维护区间最大子段和就好了。

而这个可以用线段树维护模板点这里

对于重复的情况,我们可以对每一个位置记一个前驱表示和当前位置种类相同的前一个位置。

然后通过这个来消除贡献。

于是就做完了?

细节注意事项

  • 咕咕咕

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
} typedef long long LL;
const int _ = 1000010; int n, m, f[_], w[_], pre[_], las[_];
struct node { LL sum, L, R, mx; }t[_ << 2]; inline int lc(int rt) { return rt << 1; } inline int rc(int rt) { return rt << 1 | 1; } inline void pushup(int rt) {
t[rt].sum = t[lc(rt)].sum + t[rc(rt)].sum;
t[rt].L = max(t[lc(rt)].L, t[lc(rt)].sum + t[rc(rt)].L);
t[rt].R = max(t[rc(rt)].R, t[rc(rt)].sum + t[lc(rt)].R);
t[rt].mx = max(t[lc(rt)].R + t[rc(rt)].L, max(t[lc(rt)].mx, t[rc(rt)].mx));
} inline void update(int id, LL v, int rt = 1, int l = 1, int r = n) {
if (l == r) { t[rt] = (node) { v, v, v, v }; return; }
int mid = (l + r) >> 1;
if (id <= mid) update(id, v, lc(rt), l, mid);
else update(id, v, rc(rt), mid + 1, r);
pushup(rt);
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(m);
for (rg int i = 1; i <= n; ++i) read(f[i]);
for (rg int i = 1; i <= m; ++i) read(w[i]);
for (rg int i = 1; i <= n; ++i)
pre[i] = las[f[i]], las[f[i]] = i;
LL ans = 0;
for (rg int i = 1; i <= n; ++i) {
if (pre[i]) update(pre[i], -w[f[i]]);
if (pre[pre[i]]) update(pre[pre[i]], 0);
update(i, (LL) w[f[i]]), ans = max(ans, t[1].mx);
}
printf("%lld\n", ans);
return 0;
}

完结撒花 \(qwq\)

「POI2015」KIN的更多相关文章

  1. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  2. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  3. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

  4. 「C++」理解智能指针

    维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...

  5. 「JavaScript」四种跨域方式详解

    超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...

  6. 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management

    写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...

  7. 「2014-3-18」multi-pattern string match using aho-corasick

    我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...

  8. 「2014-3-17」C pointer again …

    记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...

  9. 「2014-3-13」Javascript Engine, Java VM, Python interpreter, PyPy – a glance

    提要: url anchor (ajax) => javascript engine (1~4 articles) => java VM vs. python interpreter =& ...

随机推荐

  1. CCF认证 2019-12-3

    分析 后面的数据,坐标分布太离散,不能用一个二位数组来模拟垃圾分布.因此,考虑用一个数组记录每个垃圾点的位置. 先根据x坐标.再根据y坐标进行排序. 再遍历数组中的每一处垃圾点,判断其是否能建回收站( ...

  2. sql 中u.*什么意思

    i.*  i是一个表的别名,i.*是这个表的所有列,比如 select i.* from customer i; 相当于 select id,name,password from customer;

  3. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 网格系统实例:手机、平板电脑、台式电脑

    <!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 手机.平板电脑.台式电脑</title&g ...

  4. DHCP原理及报文格式

    DHCP原理及报文格式 DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是IETF为实现IP的自动配置而设计的协议,它可以为客户机自动分配IP地址. ...

  5. PW数据库ER图

  6. ANSYS 瞬态热分析---零件在水中冷却

    目录 1. 案例 2. APDL分析 1. 案例 一个温度为300℃的铜环和一个温度为200℃的铁环,放置到22℃的水中进行淬火.水桶为铁质的圆形.分析中忽略水的流动. 材料参数 热性能 铜 铁 水 ...

  7. 树莓派4B踩坑指南 - (7)root账户及权限设置

    树莓派启用root账户 树莓派默认用户是pi 密码为raspberry. root账户默认无密码,但是账户锁定. 开启root账户命令: sudo passwd root #执行后提示设置密码,输入2 ...

  8. [方法]季节调整与hp滤波方法

    进行时间序列的数据分析时,季节因素调整与hp滤波是进行数据处理与准备工作的常见必要环节.本文简要梳理季节调整与hp滤波的应用场景,以及在Python中的实现方法. 1. 季节调整方法 季节调整的目的是 ...

  9. leetCode练题——13. Roman to Integer

    1.题目13. Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D ...

  10. idea取消参数标记