最近真的是爆炸啊。。。

到现在还是有不少没改出来。。。。

所以先写一下 \(T1\) 的题解。。。。

送花

我们移动右端点,之后我们用线段树维护全局最大值。

之后还要记录上次的位置和上上次的位置。

之后每次加和减。



#include<bits/stdc++.h>
using std::cout; using std::endl;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
#define asm(i,x) for(register signed i=head[x];i;i=edge[i].next)
namespace xin_io
{
#define debug cout<<"debug"<<endl
#define enum(x) cout<<#x" = "<<x<<endl;
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
char buf[1<<20],*p1 = buf,*p2 = buf; int ak; typedef long long ll; typedef unsigned long long ull;
class xin_stream{public:template<typename type>inline xin_stream &operator >> (type &x)
{
register type s = 0; register int f = 1; register char ch = gc();
while(!isdigit(ch)) {if(ch == '-') f = -1; ch = gc();}
while( isdigit(ch)) s = (s << 1) + (s << 3) + (ch xor 48),ch = gc(); return x = s * f,*this;
}}io;
}
using namespace xin_io; static const int maxn = 5e6+10,inf = 1e9+7,mod = 998244353; const ll llinf = 1e18+7;
#define int long long
namespace xin
{
int lst1[maxn],lst2[maxn];
class xin_seg
{
private:
#define ls(fa) (fa << 1)
#define rs(fa) (fa << 1 | 1)
inline void up(int fa) {t[fa].s = std::max(t[ls(fa)].s , t[rs(fa)].s);}
inline void down(int fa)
{
if(!t[fa].debt) return ;
t[ls(fa)].s += t[fa].debt ; t[rs(fa)].s += t[fa].debt;
t[ls(fa)].debt += t[fa].debt ; t[rs(fa)].debt += t[fa].debt;
t[fa].debt = 0;
}
public:
class xin_tree{public:int s,debt;}t[maxn];
void update(int fa,int l,int r,int ql,int qr,int val)
{
if(ql <= l and qr >= r)
{
t[fa].s += val;
t[fa].debt += val;
return ;
}
register int mid = l + r >> 1;
down(fa);
if(ql <= mid) update(ls(fa),l,mid,ql,qr,val);
if(qr > mid) update(rs(fa),mid+1,r,ql,qr,val);
up(fa);
}
}t;
int n,c[maxn],d[maxn],m;
int ans = -inf;
inline short main()
{
io >> n >> m;
try(i,1,n) io >> c[i];
try(i,1,m) io >> d[i];
try(i,1,n)
{
// cout<<"i = "<<i<<" c[i] = "<<c[i]<<" lst1[c[i]] = "<<lst1[c[i]]<<" lst2[c[i]] = "<<lst2[c[i]]<<endl;
if(!lst1[c[i]] and !lst2[c[i]]) t.update(1,1,n,1,i,d[c[i]]);
else if(lst1[c[i]] and !lst2[c[i]]) t.update(1,1,n,lst1[c[i]]+1,i,d[c[i]]),t.update(1,1,n,1,lst1[c[i]],-d[c[i]]);
else t.update(1,1,n,lst2[c[i]]+1,lst1[c[i]],-d[c[i]]),t.update(1,1,n,lst1[c[i]]+1,i,d[c[i]]);
ans = std::max(ans,t.t[1].s);
// enum(t.t[1].s);
lst2[c[i]] = lst1[c[i]];
lst1[c[i]] = i;
}
cout<<ans<<endl;
return 0;
}
}
signed main() {return xin::main();}

[考试总结]noip模拟40的更多相关文章

  1. 2021.8.15考试总结[NOIP模拟40]

    T1 送花 线段树.枚举右端点,线段树记录左端点对应的值. 每次对当前颜色上上次出现的位置到上次出现的位置区间减,上次出现的位置到当前位置区间加. $code:$ 1 #include<bits ...

  2. 6.17考试总结(NOIP模拟8)[星际旅行·砍树·超级树·求和]

    6.17考试总结(NOIP模拟8) 背景 考得不咋样,有一个非常遗憾的地方:最后一题少取膜了,\(100pts->40pts\),改了这么多年的错还是头一回看见以下的情景... T1星际旅行 前 ...

  3. 5.23考试总结(NOIP模拟2)

    5.23考试总结(NOIP模拟2) 洛谷题单 看第一题第一眼,不好打呀;看第一题样例又一眼,诶,我直接一手小阶乘走人 然后就急忙去干T2T3了 后来考完一看,只有\(T1\)骗到了\(15pts\)[ ...

  4. 5.22考试总结(NOIP模拟1)

    5.22考试总结(NOIP模拟1) 改题记录 T1 序列 题解 暴力思路很好想,分数也很好想\(QAQ\) (反正我只拿了5pts) 正解的话: 先用欧拉筛把1-n的素数筛出来 void get_Pr ...

  5. 2021.9.17考试总结[NOIP模拟55]

    有的考试表面上自称NOIP模拟,背地里却是绍兴一中NOI模拟 吓得我直接文件打错 T1 Skip 设状态$f_i$为最后一次选$i$在$i$时的最优解.有$f_i=max_{j<i}[f_j+a ...

  6. 20190908 NOIP 模拟40

    考试过程: 刚看完题,发现T1是个类lis 问题,但要求$O(nlogn)$,应该是个数据结构优化dp,T2应该是个数据结构,T3是个字符串?没有匹配,不会是后缀数组吧,这是NOIP模拟啊,可能是个d ...

  7. [考试总结]noip模拟23

    因为考试过多,所以学校的博客就暂时咕掉了,放到家里来写 不过话说,vscode的markdown编辑器还是真的很好用 先把 \(noip\) 模拟 \(23\) 的总结写了吧.. 俗话说:" ...

  8. 6.11考试总结(NOIP模拟7)

    背景 时间分配与得分成反比,T1 20min 73pts,T2 1h 30pts,T3 2h 15pts(没有更新tot值,本来应该是40pts的,算是本次考试中最遗憾的地方了吧),改起来就是T3比较 ...

  9. 6.7考试总结(NOIP模拟5)

    前言 昨天说好不考试来着,昨晚就晚睡颓了一会,今天遭报应了,也没好好考,考得挺烂的就不多说了. T1 string 解题思路 比赛上第一想法就是打一发sort,直接暴力,然后完美TLE40pts,这一 ...

随机推荐

  1. java封装基础详解

    java封装基础详解 java的封装性即是信息隐藏,把对象的属性和行为结合成一个相同的独立单体,并尽可能地隐藏对象的内部细节. 封装的特性是对属性来讲的. 封装的目标就是要实现软件部件的"高 ...

  2. Mongodb集成LDAP授权

    一.环境简介 Mongodb enterprise v4.0.16 OpenLDAP v2.4.44 二.Mongodb集成LDAP的授权过程 客户端指定某种外部验证方式链接Mongodb: Mong ...

  3. 查看filesystem type及ftype的值

    查看Filesystem type df -Th 查看ftype xfs_info [filesystem_name]  | grep ftype

  4. PHP-Audit-Labs-Day1 - in_array函数缺陷

    函数缺陷原理分析 先看一段简单的源代码 class Challenge{ const UPLOAD_DIRECTORY = './solutions/'; private $file; private ...

  5. C++ //函数调用运算符重载 (仿函数)

    1 //函数调用运算符重载 2 3 #include <iostream> 4 #include <string> 5 using namespace std; 6 7 //函 ...

  6. 100的累加和 while 循环

    //100的累加和 while 循环 #include <stdio.h> int main() { int sum = 0; //5050 int i = 0; while(i < ...

  7. postman怎么调中文

    事先准备 1 安装好postman. 下载网址:https://www.postman.com/downloads/ 2 下载好app.zip中文压缩包,下载地址:https://wws.lanzou ...

  8. Java8新特性(一)之Lambda表达式

    .personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...

  9. React Native 启动流程简析

    导读:本文以 react-native-cli 创建的示例工程(安卓部分)为例,分析 React Native 的启动流程. 工程创建步骤可以参考官网.本文所分析 React Native 版本为 v ...

  10. druid与知乎平台

    背景 知乎作为知名中文知识内容平台,业务增长和产品迭代速度很快,如何满足业务快速扩张中的灵活分析需求,是知乎数据平台组要面临的一大挑战. 知乎数据平台团队基于开源的 Druid 打造的业务自助式的数据 ...