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. MyEclipse2014.Maven自动更新

    1.我把 "Do not automatically update dependencies from remote repositories" 和 "Download ...

  2. A4纸网页打印 html网页页面的宽度设置成多少

    A4纸竖向打印,html网页页面的宽度设置成多少?这个问题是我们大家所疑惑的,于是网上搜集整理下,希望可以帮助你们 最近开发项目时遇到了网页打印的问题,这是问题之二,打印宽度设置 在公制长度单位与屏幕 ...

  3. CSS 左边div固定,右边div自适应

    有时候我们会有这样的需求,如图,aside是导航或者某些链接,右边的main是显示重要的内容,左边需要定宽,右边的main能够自适应剩余的宽度: <!DOCTYPE html PUBLIC &q ...

  4. python学习大纲目录(转自alex博客https://www.cnblogs.com/alex3714/)

    day01: 介绍.基本语法.流程控制 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 ...

  5. hadoop2.6.0的eclipse插件安装

    1.安装插件 下载插件hadoop-eclipse-plugin-2.6.0.jar并将其放到eclips安装目录->plugins(插件)文件夹下.然后启动eclipse. 配置 hadoop ...

  6. TestNG,多个场景结合运行Suite.xml

    方法一.首先新增一个.xml文件(经过一段时间的练习,找到其他方法添加XML,如下) 再到文件中添加如下: <suite name = "Selenium school"&g ...

  7. css 权威指南笔记

    部分属性选择: 选择class 属性中包含warning的元素 [class~="warning"]{font-weight:bold} 子串匹配属性选择器: 在现代浏览器中得到支 ...

  8. HIVE学习(待更新)

    1 安装hive 下载 http://mirrors.shu.edu.cn/apache/hive/hive-1.2.2/,红框中的不需要编译. 由于hive是默认将元数据保存在本地内嵌的 Derby ...

  9. poj1679次小生成树入门题

    次小生成树求法:例如求最小生成树用到了 1.2.4这三条边,总共5条边,那循环3次的时候,每次分别不用1.2.4求得最小生成树的MST,最小的MST即为次小生成树 如下代码maxx即求最小生成树时求得 ...

  10. 重新学习MySQL数据库5:根据MySQL索引原理进行分析与优化

    重新学习MySQL数据库5:根据MySQL索引原理进行分析与优化 一:Mysql原理与慢查询 MySQL凭借着出色的性能.低廉的成本.丰富的资源,已经成为绝大多数互联网公司的首选关系型数据库.虽然性能 ...