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. 一个带展示的jsp上传控件模型

    带展示上传控件的基本模型,无样式 jsp部分: <td> <form id="form1" enctype="multipart/form-data&q ...

  2. sass的多种用法

    sass的多种用法 主要归纳总结sass的常见用法,作为个人笔记使用,部分知识点并不仔细讲解.具体可参考文档:sass官网 一.嵌套 .svg{ position: absolute; left: 0 ...

  3. ADC和RTC的寄存器的读取

    ADC的寄存器读取,int adc_read(void){ int result; #if ADSTART==0 result = ADC.ADCDAT0&0x3ff; while(!(ADC ...

  4. 常数PK系列汇总

    常数PK系列说明: 在AC的情况下得分=\(\sum_{i=1}^{10}{1000-runtime\_on\_point_i}\) RE会显示UKE UPD:之前的数据太水,导致好多题都在9000分 ...

  5. JS中call和apply区别有哪些 记录

    一.call和apply区别 传递参数的方式.用法上不同,主要是参数不完全同 (1).B.Function.call(A,arg,arg) 这个例子是讲A对象“调用”B对象的Function(某个具体 ...

  6. linux FTP 操作

    1.登陆: ftp 172.xxx.xxx.xxx 按提示输入用户名和密码 2.上传: 单个文件:put /路径/文件名 批量: 输入 prom 此命令是关闭交互(否则总是询问你是否要上传) 输入下载 ...

  7. form表单注册——HTML

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  8. hdu4453

    题解: splay模板 删除,翻转等等 代码: #include<cstdio> #include<cstring> #include<cmath> #includ ...

  9. C/C++文件指针偏移

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  10. 【css】25个漂亮的响应式布局的web设计【转】

    响应的web设计的做法是提高用户的浏览质量,并在不同设备上能够完美的浏览使用,就像大前端推出的D7主题.看看下面美丽的响应的网站布局,通过本文你会在以后的设计中找到响应的web设计的灵感. 1.Mar ...