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. LA 3295 数三角形

    https://vjudge.net/problem/UVALive-3295 题意: 数出n行m列的网格顶点能组成多少个三角形. 思路: 直接去数的话比较麻烦,这道题目是可以重复的,只要位置不同就可 ...

  2. 关于JBoss的一些项目配置

    1. 如何使用 IP:port 的形式访问项目 : [1] 在standalone.xml文件中,查找<interfaces>标签,添加如下节点 : <interface name= ...

  3. uva10002凸包重心

    把每个三角形看成一个质点,坐标就是各自的重心, #include<map> #include<set> #include<cmath> #include<qu ...

  4. mail_location not set and autodetection failed 解决方案[devecot, sendmail]

    安装dovecot比较简单, 但是也需要配置, 如果不进行任何配置时,在测试时会出现如下的提示: dovecot: pop3(wwufengg): Error: user wwufengg: Init ...

  5. vue项目搭建 (一)

    vue项目搭建 (一) 由于一直想要有自己的框架,因而一直在尝试搭建各类结构,结合vue官网及git上大神bailicangdu的项目,再看看网上一些意见,及个人思考,总结的一些,不到之处希望大家可以 ...

  6. 【fzu-2261】浪里个浪

    TonyY是一个喜欢到处浪的男人,他的梦想是带着兰兰姐姐浪遍天朝的各个角落,不过在此之前,他需要做好规划. 现在他的手上有一份天朝地图,上面有n个城市,m条交通路径,每条交通路径都是单行道.他已经预先 ...

  7. MySQL简单的操作,增删改查

    B/S架构模式与C/S架构模式的区别 B/S=WEB/SERVER C/S=CLIENT/SERVIR B/S:用户通过web浏览器打开域名就能访问服务器server的方式就叫做B/S用户不需要安装任 ...

  8. WebLogic和Tomcat

    J2ee开发主要是浏览器和服务器进行交互的一种结构.逻辑都是在后台进行处理,然后再把结果传输回给浏览器.可以看出服务器在这种架构是非常重要的. 这几天接触到两种Java的web服务器,做项目用的Tom ...

  9. cx_freeze打包EXE文件

    创建setup.py文件 import osimport sysfrom cx_Freeze import setup, Executable build_exe_options = dict(pac ...

  10. zset类型以及其操作

    sorted set类型 sorted sets类型以及其操作zset是set的一格升级版本,它在set的基础上增加了一格顺序属性,这一属性在添加元素的同时可以指定,每次指定后,zset会自动重新按照 ...