最近真的是爆炸啊。。。

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

所以先写一下 \(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();}

最新文章

  1. c#和js互通的AES加密解密
  2. Linear Algebra lecture7 note
  3. 工具,如何去掉百度编辑器 ueditor 元素路径、字数统计等
  4. SEL数据类型
  5. DIY小能手|别买电动滑板车了,咱做一台吧
  6. [saiku] 将saiku自带的H2嵌入式数据库迁移到本地mysql数据库
  7. python手记(31)
  8. hdu Big Number 求一个数的位数
  9. 数组有没有 length()这个方法? String 有没有 length()这 个方法?
  10. 又见拦截导弹(LIS)
  11. map遍历性能记录
  12. Apollo的Oracle适配
  13. B树,B+树,红黑树应用场景AVL树,红黑树,B树,B+树,Trie树
  14. Asp.Net Core混合使用cookie和JwtBearer认证方案
  15. CentOS下GPT分区(转)
  16. Python3 isprintable() 方法
  17. Python异常处理try...except...finally raise assert
  18. RedHat7.4最小化安装没有ifconfig命令
  19. 微信web端生成支付二维码
  20. [IE bug] ajax请求 304解决方案

热门文章

  1. 手撸一个SpringBoot-Starter
  2. FreeRTOS-04-内核控制函数+时间管理函数
  3. 虚拟基站(VRS)
  4. 清晰易懂的RxJava入门实践
  5. 使用POI导出Word(含表格)的实现方式及操作Word的工具类
  6. Check Directory Existence in Shell
  7. Http协议中的CharacterEncoding、Content-Encoding和Transfer-Encoding
  8. 【笔记】Bagging和Pasting以及oob(Out-of-Bag)
  9. 「移动端」Web页面适配
  10. 为何要打印日志?C++在高并发下如何写日志文件(附源码)?