【题解】Luogu P2572 [SCOI2010]序列操作
原题传送门:P2572 [SCOI2010]序列操作
这题好弱智啊
裸的珂朵莉树
前置芝士:珂朵莉树
窝博客里对珂朵莉树的介绍
没什么好说的自己看看吧
操作1:把区间内所有数推平成0,珂朵莉树基本操作
操作2:把区间内所有数推平成1,珂朵莉树基本操作
操作3:把区间内所有数取反(异或1),split后扫描一遍,值域取反
操作4:区间和,珂朵莉树基本操作
操作5:区间最长连续的1,暴力扫描累加
就是这样简单
好像跑的比线段树还快???喵喵喵
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define IT set<node>::iterator
using namespace std;
inline int read()
{
register int x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline int Max(register int a,register int b)
{
return a>b?a:b;
}
struct node
{
int l,r;
mutable bool v;
node(int L, int R=-1, bool V=0):l(L), r(R), v(V) {}
bool operator<(const node& o) const
{
return l < o.l;
}
};
set<node> s;
inline IT split(register int pos)
{
IT it = s.lower_bound(node(pos));
if (it != s.end() && it->l == pos)
return it;
--it;
int L = it->l, R = it->r;
bool V = it->v;
s.erase(it);
s.insert(node(L, pos-1, V));
return s.insert(node(pos, R, V)).first;
}
inline void assign_val(register int l,register int r,register bool val)
{
IT itr = split(r+1),itl = split(l);
s.erase(itl, itr);
s.insert(node(l, r, val));
}
inline void rev(register int l,register int r)
{
IT itr = split(r+1),itl = split(l);
for(; itl != itr; ++itl)
itl->v ^= 1;
}
inline int sum(register int l,register int r)
{
IT itr = split(r+1),itl = split(l);
int res = 0;
for (; itl != itr; ++itl)
res += itl->v ? itl->r - itl->l + 1 : 0;
return res;
}
inline int count(register int l,register int r)
{
int res=0,temp=0;
IT itr = split(r+1),itl = split(l);
for(; itl != itr; ++itl)
{
if(itl->v == false)
{
res = Max(res, temp);
temp=0;
}
else
temp += itl->r - itl->l + 1;
}
return Max(res, temp);
}
int main()
{
int n=read(),m=read();
for(register int i=0;i<n;++i)
s.insert(node(i,i,read()));
s.insert(node(n,n,0));
while(m--)
{
int op=read(),a=read(),b=read();
if(op==0)
assign_val(a,b,0);
else if(op==1)
assign_val(a,b,1);
else if(op==2)
rev(a,b);
else if(op==3)
printf("%d\n",sum(a,b));
else
printf("%d\n",count(a,b));
}
return 0;
}
【题解】Luogu P2572 [SCOI2010]序列操作的更多相关文章
- Luogu P2572 [SCOI2010]序列操作 线段树。。
咕咕了...于是借鉴了小粉兔的做法ORZ... 其实就是维护最大子段和的线段树,但上面又多了一些操作....QWQ 维护8个信息:1/0的个数(sum),左/右边起1/0的最长长度(ls,rs),整段 ...
- P2572 [SCOI2010]序列操作
对自己 & \(RNG\) : 骄兵必败 \(lpl\)加油! P2572 [SCOI2010]序列操作 题目描述 lxhgww最近收到了一个01序列,序列里面包含了n个数,这些数要么是0,要 ...
- 洛谷 P2572 [SCOI2010]序列操作
题意简述 维护一个序列,支持如下操作 把[a, b]区间内的所有数全变成0 把[a, b]区间内的所有数全变成1 把[a,b]区间内所有的0变成1,所有的1变成0 询问[a, b]区间内总共有多少个1 ...
- 洛谷P2572 [SCOI2010]序列操作(ODT)
题解 题意 题目链接 Sol ODT板子题..... // luogu-judger-enable-o2 #include<bits/stdc++.h> #define LL long l ...
- 洛谷$P2572\ [SCOI2010]$ 序列操作 线段树/珂朵莉树
正解:线段树/珂朵莉树 解题报告: 传送门$w$ 本来是想写线段树的,,,然后神仙$tt$跟我港可以用珂朵莉所以决定顺便学下珂朵莉趴$QwQ$ 还是先写线段树做法$QwQ$? 操作一二三四都很$eas ...
- 洛谷P2572 [SCOI2010]序列操作
线段树 pushdown写的很浪~ #include<cstdio> #include<cstdlib> #include<algorithm> #include& ...
- 洛谷P2572 [SCOI2010]序列操作(珂朵莉树)
传送门 珂朵莉树是个吼东西啊 这题线段树代码4k起步……珂朵莉树只要2k…… 虽然因为这题数据不随机所以珂朵莉树的复杂度实际上是错的…… 然而能过就行对不对…… (不过要是到时候noip我还真不敢打… ...
- bzoj 1858: [Scoi2010]序列操作
1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MB 线段树,对于每个区间需要分别维护左右和中间的1和0连续个数,并在op=4时特殊 ...
- BZOJ 1858: [Scoi2010]序列操作( 线段树 )
略恶心的线段树...不过只要弄清楚了AC应该不难.... ---------------------------------------------------------------- #inclu ...
随机推荐
- 从零开始一起学习SLAM | 神奇的单应矩阵
小白最近在看文献时总是碰到一个奇怪的词叫“homography matrix”,查看了翻译,一般都称作“单应矩阵”,更迷糊了.正所谓:“每个字都认识,连在一块却不认识”就是小白的内心独白.查了一下书上 ...
- css 清除一些默认的设置
一.input标签的placeholder的设置 input::-webkit-input-placeholder{ /*WebKit browsers*/ //重置样式 } input::-moz- ...
- mysql基础常用命令
数据库 1查询 Select * From table select host,user,password from mysql.user where user='ybb' and host='%'; ...
- C# - 匿名对象取值
在new出匿名对象的函数内可以直接调用该匿名对象的属性取值. 可是在其它函数就无法调用匿名对象的属性或方法. 这时,我们可以通过c#的反射机制取值: 文章出处:https://www.cnblogs. ...
- js控制元素隐藏和显示
原生: 方法一: document.getElementById("idname").style.visibility="hidden"; document.g ...
- tfs分支操作
1.在代码管理器中找到代码项 右击——分支与合并——分支——默认所有选项——确定. 2.可能刚打出的分支为红色,签入,修改代码,待测试后代码合并到主干中(下拉选出他的上级,一般为主干),删除分支. 3 ...
- Python之words count
要求: 对文件单词进行统计,不区分大小写,并显示单词重复最多的十个单词 思路: 利用字典key,value的特性存单词及其重复的次数 每行进行特殊字符的处理,分离出被特殊字符包含的单词 def mak ...
- 基于TCP/IP协议的socket通讯server
思路: socket必须要随项目启动时启动,所以需用Spring自带的监听器,需要保持长连接,要用死循环,所以必须另外起线程,不能阻碍主线程运行 1.在项目的web.xml中配置listener &l ...
- 反射(I)
反射获取属性和属性值 let item = DoctorGroup() guard let dic = InterfaceTests.obtainValues(subObject: item) els ...
- 【Hive学习之六】Hive Lateral View &视图&索引
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...