传送门

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. 为什么阿里Java手册推荐慎用 Object 的 clone 方法来拷贝对象

    图片若无法显示,可至掘金查看https://juejin.im/post/5d425230f265da039519d248 前言 在阿里Java开发手册中,有这么一条建议:慎用 Object 的 cl ...

  2. Java学习资源 - J2SE

    java.lang包教程 Java集合类详解 Java回顾之集合 Java回顾之序列化 Java回顾之反射 深入理解Java:类加载机制及反射 Java 下高效的反射工具包 ReflectASM 使用 ...

  3. NLP直播-1 词向量与ELMo模型

    翻车2次,试水2次,今天在B站终于成功直播了. 人气11万. 主要讲了语言模型.词向量的训练.ELMo模型(深度.双向的LSTM模型) 预训练与词向量 词向量的常见训练方法 深度学习与层次表示 LST ...

  4. %E3%80%90%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E3%80%91

    "%3Cdiv%20class%3D%22htmledit_views%22%20id%3D%22content_views%22%3E%0A%20%20%20%20%20%20%20%20 ...

  5. vue.js 强行赋值、刷新数组或者对象 方法之 $.set()

    实际开发过程中,数据交互的的时候需要赋值,刷新,但是不可能每次赋值之后都刷新整个页面,所以就要用到 vue.js方法 $.set(),能实现赋值对象的局部刷新 语法:Vue.set(object, k ...

  6. js加入收藏

    <script> function AddFavorite(sURL, sTitle) { try { window.external.addFavorite(sURL, sTitle); ...

  7. Do You Know These Plastic Bottle Processing Terms?

    The molding process of a plastic bottle refers to a process of making a final plastic article from a ...

  8. scp 常用命令总结

    1, 上传本地文件到服务器:scp /path/local_filename username@servername:/path 例如:例如scp /var/www/test.php  codingl ...

  9. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:列表

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. java 依赖注入

    https://blog.csdn.net/coderder/article/details/51897721 前言 在软件工程领域,依赖注入(Dependency Injection)是用于实现控制 ...