[考试总结]noip模拟40
最近真的是爆炸啊。。。
到现在还是有不少没改出来。。。。
所以先写一下 \(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的更多相关文章
- 2021.8.15考试总结[NOIP模拟40]
T1 送花 线段树.枚举右端点,线段树记录左端点对应的值. 每次对当前颜色上上次出现的位置到上次出现的位置区间减,上次出现的位置到当前位置区间加. $code:$ 1 #include<bits ...
- 6.17考试总结(NOIP模拟8)[星际旅行·砍树·超级树·求和]
6.17考试总结(NOIP模拟8) 背景 考得不咋样,有一个非常遗憾的地方:最后一题少取膜了,\(100pts->40pts\),改了这么多年的错还是头一回看见以下的情景... T1星际旅行 前 ...
- 5.23考试总结(NOIP模拟2)
5.23考试总结(NOIP模拟2) 洛谷题单 看第一题第一眼,不好打呀;看第一题样例又一眼,诶,我直接一手小阶乘走人 然后就急忙去干T2T3了 后来考完一看,只有\(T1\)骗到了\(15pts\)[ ...
- 5.22考试总结(NOIP模拟1)
5.22考试总结(NOIP模拟1) 改题记录 T1 序列 题解 暴力思路很好想,分数也很好想\(QAQ\) (反正我只拿了5pts) 正解的话: 先用欧拉筛把1-n的素数筛出来 void get_Pr ...
- 2021.9.17考试总结[NOIP模拟55]
有的考试表面上自称NOIP模拟,背地里却是绍兴一中NOI模拟 吓得我直接文件打错 T1 Skip 设状态$f_i$为最后一次选$i$在$i$时的最优解.有$f_i=max_{j<i}[f_j+a ...
- 20190908 NOIP 模拟40
考试过程: 刚看完题,发现T1是个类lis 问题,但要求$O(nlogn)$,应该是个数据结构优化dp,T2应该是个数据结构,T3是个字符串?没有匹配,不会是后缀数组吧,这是NOIP模拟啊,可能是个d ...
- [考试总结]noip模拟23
因为考试过多,所以学校的博客就暂时咕掉了,放到家里来写 不过话说,vscode的markdown编辑器还是真的很好用 先把 \(noip\) 模拟 \(23\) 的总结写了吧.. 俗话说:" ...
- 6.11考试总结(NOIP模拟7)
背景 时间分配与得分成反比,T1 20min 73pts,T2 1h 30pts,T3 2h 15pts(没有更新tot值,本来应该是40pts的,算是本次考试中最遗憾的地方了吧),改起来就是T3比较 ...
- 6.7考试总结(NOIP模拟5)
前言 昨天说好不考试来着,昨晚就晚睡颓了一会,今天遭报应了,也没好好考,考得挺烂的就不多说了. T1 string 解题思路 比赛上第一想法就是打一发sort,直接暴力,然后完美TLE40pts,这一 ...
随机推荐
- php 几个算法
/** * 返回当前运行文件名 * @acces private * @return string */ private function run_filename() { $tmparr = exp ...
- Hadoop 3.1.1 - Yarn - 使用 GPU
在 Yarn 上使用 GPU 前提 目前,Yarn 只支持 Nvidia GPU. YARN NodeManager 所在机器必须预先安装了 Nvidia 驱动器. 如果使用 Docker 作为容器的 ...
- 记一次 GitLab 的迁移过程
目录 1. 迁移背景 2. GitLab 整体架构介绍 3. GitLab 安装 配置选择 安装方式选择 安装的网络区域 安装 GitLab GitLab 常用命令 配置管理员账号密码 4. 配置 G ...
- Flutter集成高德定位和地图功能
定位集成 配置高德定位依赖库 新建 Flutter 项目,使用 Android Studio 打开项目里的 android 工程,或者右键 android 目录-> flutter -> ...
- [论文阅读] LCC-NLM(局部颜色校正, 非线性mask)
[论文阅读] LCC-NLM(局部颜色校正, 非线性mask) 文章: Local color correction using non-linear masking 1. 算法原理 如下图所示为, ...
- Haskell Interactive Development in Emacs
Installation Following haskell-mode. Use MELPA repository: add the following into ~/.emacs (require ...
- JavaScript学习01(js概述)
JavaScript概述 JavaScript历史 要了解JavaScript,我们首先要了解一下JavaScript的诞生. 在上个世纪的1995年,当时的网景公司正凭借其Navigator浏览器成 ...
- Linux文件系统与日志文件
目录 一.inode和block 1.1.inode和block概述 1.2.inode的内容 inode包含文件的元信息: 查看inode号两种方式 目录文件的结构 1.3.inode的号码 用户通 ...
- Shell-12-linux信号
信号类型 信号:信号是在软件层次上对中断机制的一种模拟,通过给一个进程发送信号,执行相应的处理函数 进程可以通过三种方式来响应一个信号: 1.忽略信号,即对信号不做任何处理,其中有两个信号不能忽略: ...
- Git-06-远程仓库
本地仓库推送到远程仓库 1 创建ssh key 用户主目录下运行如下命令,然后一路回车 ssh-keygen -t rsa -C "1029612787@qq.com" 2 找到公 ...