bzoj 1858 序列操作
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 序列操作的更多相关文章
- [bzoj]2962序列操作
[bzoj]2962序列操作 标签: 线段树 题目链接 题意 给你一串序列,要你维护三个操作: 1.区间加法 2.区间取相反数 3.区间内任意选k个数相乘的积 题解 第三个操作看起来一脸懵逼啊. 其实 ...
- bzoj 2962 序列操作
2962: 序列操作 Time Limit: 50 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description 有一个长度为n的序列, ...
- bzoj 2962 序列操作——线段树(卷积?)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2962 如果 _,_,_,…… 变成了 (_+k),(_+k),(_+k),…… ,计算就是在 ...
- bzoj 2962 序列操作 —— 线段树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2962 维护 sum[i] 表示选 i 个的乘积和,合并两个子树就枚举两边选多少,乘起来即可: ...
- (WAWAWAWAWAWA) BZOJ 1858: [Scoi2010]序列操作
二次联通门 : BZOJ 1858: [Scoi2010]序列操作 /* BZOJ 1858: [Scoi2010]序列操作 已经... 没有什么好怕的的了... 16K的代码... 调个MMP啊.. ...
- bzoj 1858: [Scoi2010]序列操作
1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MB 线段树,对于每个区间需要分别维护左右和中间的1和0连续个数,并在op=4时特殊 ...
- BZOJ 1858: [Scoi2010]序列操作( 线段树 )
略恶心的线段树...不过只要弄清楚了AC应该不难.... ---------------------------------------------------------------- #inclu ...
- 1858: [Scoi2010]序列操作
1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 3397 Solved: 1624 [Submit][Statu ...
- bzoj 4831 [Lydsy1704月赛]序列操作 dp
[Lydsy1704月赛]序列操作 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 203 Solved: 69[Submit][Status][Dis ...
随机推荐
- linux主机之间无密钥ssh访问
ssh-keygen -t rsa ssh-copy-id -i /root/.ssh/id-rsa.pub root@10.0.0.109 # 实现和109互通 vim /etc/hosts DNS ...
- php isset
isset函数是检测变量是否设置. 格式:bool isset ( mixed var [, mixed var [, ...]] ) 返回值: 若变量不存在则返回 FALSE 若变量存在且其值为NU ...
- spring boot 之Rabbitmq 基本配置
/* * Copyright (c) 2017 4PX Information Technology Co.,Ltd. All rights reserved. */package com.fpx.p ...
- web项目整合Shiro框架
1.修改pom.xml文件 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>s ...
- Promise相关网址
1.https://github.com/fsjohnhuang/iPromise 2.https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/ ...
- django 使用form组件提交数据之form表单提交
django的form组件可以减少后台在进行一些重复性的验证工作,极大降低开发效率. 最近遇到一个问题: 当使用form表单提交数据后,如果数据格式不符合后台定义的规则,需要重新在前端页面填写数据. ...
- 设计模式--命令模式C++实现
命令模式C++实现 1定义 将一个请求封装成一个对象,从而让你使用不同的请求把客户端参数化,对请求队列或者记录请求日志,可以提供命令的撤销和恢复功能 2类图 角色描述: Receiver接受者角色,就 ...
- 联表更新SQL语句
联表更新语句第一次写,,,主要是在实现功能上需要向repay_detail添加一个新的字段item_id.但是以前的老数据的话这个字段的值就为null 所以就写了下面一条语句就更新了老数据...SQL ...
- Python之NumPy(axis=0 与axis=1)区分
转自:http://blog.csdn.net/wangying19911991/article/details/73928172 https://www.zhihu.com/question/589 ...
- UVA-10537 The Toll! Revisited (dijkstra)
题目大意:每经过一个地方就要交出相应的货物作为过路费,问将一批货物从起点运到终点,最少需要携带多少货物? 题目分析:在每一站交的过路费由当前拥有的货物量来决定,所以,要以终点为源点,求一次单源最短路即 ...