[考试总结]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,这一 ...
随机推荐
- 微信开发者工具获取位置错误(定位到北京)---调用wx.getLocation不出现获取定位提示
微信开发者工具获取不到自己当前的位置可能是以下几个原因: 1.调用wx.getLocation方法之后需要在app.json中声明permission字段 { "pages": [ ...
- Django GIS SQL注入漏洞(CVE-2020-9402)
影响版本 Django 1.11.29之前的1.11.x版本.2.2.11之前的2.2.x版本和3.0.4之前的3.0.x版本中存在SQL注入漏洞 提示有admin.vuln.vuln2,3个页面,存 ...
- @FeignClient常用属性
@FeignClient(name = "gateway-test", value = "gateway-test", url = "localhos ...
- Nacos 自动更新配置不生效问题
版本 Nacos 1.4.1 SpringCloud 2020.0.3 解决方案 bootstrap.properties 增加应用名配置即可 spring.application.name=serv ...
- Java流程控制02——顺序结构
- Android 已发行多年,移动 App 已经趋近饱和,那么 Android 开发还会有那么吃香吗?
一.关于Android的前景 不断地也听见很多人在谈做Android是否还有前途.Android研发在走下坡路了.Android的工作太难找了.Android是不是已经凉了...... 对于这些其实我 ...
- 【Lua篇】静态代码扫描分析(二)词法分析
一.词法分析 词法分析(英语:lexical analysis)是计算机科学中将字符序列转换为单词(Token)序列的过程.进行词法分析的程序或者函数叫作词法分析器(Lexical analyzer, ...
- Java中解决多线程数据安全问题
同步代码块 基本语句 synchronized (任意对象) { 操作共享代码 } 代码示例 public class SellTicket implements Runnable { private ...
- 直流电机、减速器、编码器与TB6612FNG知识整理
之前把MPU6050的相关知识了解了一下,可以做到测量欧拉角,在平衡小车的开发中需要测量小车的倾角来调整小车姿态.接下来该学习小车的电机驱动部分了,这里整理一下直流电机.减速器.编码器以及TB6612 ...
- noip36
开场先看一遍题面,凭着错误的感觉t3叫naive是一个原因,312开局.然后就死的很惨. T1 朴素暴力40pts,细想就有80pts,然而我只写了十分钟左右就爬回T3了,所以... 其实都是借口 正 ...