传送门

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. StringUtils中isEmpty方法和isBlank方法的区别

    1.StringUtils.isEmpty没有忽略空格参数,是以是否为空和是否存在为判断依据. 示例: StringUtils.isEmpty("yyy") = false Str ...

  2. Cisco Cat4500系列High CPU故障步骤摘要

    在实际网络环境中,很多时候都会出现设备high CPU的情况,有些时候可能是bug,而某些情况下,也可能是网络中发生了变化,导致了设备出现high CPU情况,这里主要记录一下Cisco Cat450 ...

  3. Kindle阅读产品体验报告-随时随地畅享阅读

    产品入门-第一份产品体验报告Kindle阅读-随时随地畅享阅读时间:2018/11/18-11/22   Kindle阅读 一.产品概括 (1)体验环境 机型:荣耀8 系统:EMUI 8.0(Andr ...

  4. leetcode 0207

    目录 ✅ 561. 数组拆分 I ✅ 1025. 除数博弈 聪明的数学归纳法: 动态规划又来了(没理解,todo 0207): ✅ 557. 反转字符串中的单词 III py 中的 字符 split ...

  5. 第二章linux网络基础设置总结!

    一:查看及测试网络 (1)查看活动的网络接头命令:ifconfig (2)查看所有网络接口命令:ifconfig -a (3)查看指定的网络接口(不论该网络接口是否处于激活状态)命令:ifconfig ...

  6. Ubantu 固定IP

    ubantu固定IP设置 1.以root身份登录 2. vi /etc/network/interfaces 参照截图修改,保存退出 3.刷新接口,重启服务 /etc/init.d/networkin ...

  7. Servlet返回的数据js解析问题

    Servlet返回的数据js解析问题 方式1:Json 接收函数:ajax.responseText后面没括号 其实在之前所说的ajax中还遗留了一些问题就是,Servlet返回给js的数据是如何被j ...

  8. Tensorflow机器学习入门——ModuleNotFoundError: No module named 'tensorflow.keras'

    这个bug的解决办法: # from tensorflow.keras import datasets, layers, models from tensorflow.python.keras imp ...

  9. 循环语句(while语句和do...while语句)

    1.while语句:如果条件成立,就继续循环,直到条件不成立为止.格式如下: while (条件) {               循环体(语句或语句块) } 2.do…while语句:如果条件成立, ...

  10. word2vec 构建中文词向量

    词向量作为文本的基本结构——词的模型,以其优越的性能,受到自然语言处理领域研究人员的青睐.良好的词向量可以达到语义相近的词在词向量空间里聚集在一起,这对后续的文本分类,文本聚类等等操作提供了便利,本文 ...