bzoj 1858 序列操作

  • 带有随机多个区间单值覆盖的区间操作题,可考虑用珂朵莉树解决.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline int read()
{
int x=0;
bool pos=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')
pos=0;
for(;isdigit(ch);ch=getchar())
x=x*10+ch-'0';
return pos?x:-x;
}
const int MAXN=1e5+10;
int n,m;
struct node{
int l,r;
mutable int val;
bool operator < (const node &rhs) const
{
return l<rhs.l;
}
node(int L,int R,int Val):l(L),r(R),val(Val) {}
node(int L):l(L){}
};
typedef set<node> ChthollyTree;
typedef set<node>::iterator sit;
ChthollyTree T;
sit split(int pos)//[l,pos-1],return [pos,r]
{
sit it=T.lower_bound(node(pos));
if(it!=T.end() && pos==it->l)
return it;
--it;
int l=it->l,r=it->r,val=it->val;
T.erase(it);
T.insert(node(l,pos-1,val));
return T.insert(node(pos,r,val)).first;
}
void assign(int l,int r,int v)
{
sit it2=split(r+1),it1=split(l);
T.erase(it1,it2);//[it1,it2)
T.insert(node(l,r,v));
}
void inverse(int l,int r)
{
sit it2=split(r+1),it1=split(l);
for(sit it=it1;it!=it2;++it)
{
it->val^=1;
}
}
int tot(int l,int r)
{
sit it2=split(r+1),it1=split(l);
int res=0;
for(sit it=it1;it!=it2;++it)
{
if(it->val==1)
{
int L=it->l,R=it->r;
res+=R-L+1;
}
}
return res;
}
int adj(int l,int r)
{
sit it2=split(r+1),it1=split(l);
int res=0;
int cur=0;
for(sit it=it1;it!=it2;++it)
{
if(it->val==1)
{
int L=it->l,R=it->r;
cur+=R-L+1;
res=max(res,cur);
}
else
cur=0;
}
return res;
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;++i)
{
int x=read();
T.insert(node(i,i,x));
}
T.insert(node(n+1,n+1,-1));
while(m--)
{
int op=read();
int l=read(),r=read();
++l,++r;
if(op==0)
assign(l,r,0);
else if(op==1)
assign(l,r,1);
else if(op==2)
inverse(l,r);
else if(op==3)
printf("%d\n",tot(l,r));
else if(op==4)
printf("%d\n",adj(l,r));
}
return 0;
}

bzoj 1858 序列操作的更多相关文章

  1. [bzoj]2962序列操作

    [bzoj]2962序列操作 标签: 线段树 题目链接 题意 给你一串序列,要你维护三个操作: 1.区间加法 2.区间取相反数 3.区间内任意选k个数相乘的积 题解 第三个操作看起来一脸懵逼啊. 其实 ...

  2. bzoj 2962 序列操作

    2962: 序列操作 Time Limit: 50 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 有一个长度为n的序列, ...

  3. bzoj 2962 序列操作——线段树(卷积?)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2962 如果 _,_,_,…… 变成了 (_+k),(_+k),(_+k),…… ,计算就是在 ...

  4. bzoj 2962 序列操作 —— 线段树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2962 维护 sum[i] 表示选 i 个的乘积和,合并两个子树就枚举两边选多少,乘起来即可: ...

  5. (WAWAWAWAWAWA) BZOJ 1858: [Scoi2010]序列操作

    二次联通门 : BZOJ 1858: [Scoi2010]序列操作 /* BZOJ 1858: [Scoi2010]序列操作 已经... 没有什么好怕的的了... 16K的代码... 调个MMP啊.. ...

  6. bzoj 1858: [Scoi2010]序列操作

    1858: [Scoi2010]序列操作 Time Limit: 10 Sec  Memory Limit: 64 MB 线段树,对于每个区间需要分别维护左右和中间的1和0连续个数,并在op=4时特殊 ...

  7. BZOJ 1858: [Scoi2010]序列操作( 线段树 )

    略恶心的线段树...不过只要弄清楚了AC应该不难.... ---------------------------------------------------------------- #inclu ...

  8. 1858: [Scoi2010]序列操作

    1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 3397 Solved: 1624 [Submit][Statu ...

  9. bzoj 4831 [Lydsy1704月赛]序列操作 dp

    [Lydsy1704月赛]序列操作 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 203  Solved: 69[Submit][Status][Dis ...

随机推荐

  1. SVM(三)线性支持向量机

    本文是在微信公众号发表的原创~ 额,图片粘不过来~就把链接给你们吧 http://mp.weixin.qq.com/s?__biz=MjM5MzM5NDAzMg==&mid=400740076 ...

  2. wampserver安装及安装中可能遇到的问题

    首先wampserver是windows apache Mysql PHP 集成开发环境,即在windows下的apache.php和mysql的服务器.因此wampserver是一个服务器端应用程序 ...

  3. Servlet与线程安全

    先说结论:servlet不是线程安全的. servlet运行过程 Servlet程序是由WEB服务器调用,web服务器收到客户端的Servlet访问请求后: ①Web服务器首先检查是否已经装载并创建了 ...

  4. Angular2-使用Augury来调试Angular2程序

    参考: http://www.jianshu.com/p/efecaea287f2https://augury.angular.io/ https://augury.angular.io/pages/ ...

  5. 我的Android学习路线(二)

    这两天的主要工作: 优化了一下布局界面,原本使用的是相对布局,直观省力,但是考虑了一下还是使用更加主流的线性布局. 完善了一下计算器的功能,比如加入小数运算. 使用线性布局的思路可以用下面的伪代码表示 ...

  6. 一个很有用的树形控件----zTree

    演示地址 http://www.treejs.cn/v3/demo.php#_101

  7. ls/vi等 command not found

    输入一下命令即可 export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin source / ...

  8. Back Track5学习笔记

    1.BT5默认用户名:root.密码:toor(公司是yeslabccies) 2.进入图形化界面命令:startx 3.更改密码:sudo passwd root 扫描工具 第一部分网络配置: 4. ...

  9. tensorflow入门(二)

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt #使用numpy生成200个随机点 x_data ...

  10. 练习-99乘法表 token生成器 翻译小工具

    一.99乘法表 1.1 技术点 记住: for 循环的使用,以及for的嵌套使用 range()的使用,掌握sep为负数的使用的使用. print() 函数的使用,默认的结尾的换行符 替换 end= ...