传送门

珂朵莉树是个吼东西啊

这题线段树代码4k起步……珂朵莉树只要2k……

虽然因为这题数据不随机所以珂朵莉树的复杂度实际上是错的……

然而能过就行对不对……

(不过要是到时候noip我还真不敢打……毕竟CCF那机子……)

 //minamoto
#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
#define IT set<node>::iterator
using std::set;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,:;}
int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
char sr[<<],z[];int C=-,Z;
inline void Ot(){fwrite(sr,,C+,stdout),C=-;}
void print(int x){
if(C><<)Ot();if(x<)sr[++C]=,x=-x;
while(z[++Z]=x%+,x/=);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=1e5+;
struct node{
int l,r;mutable bool v;
node(int L,int R=-,int V=):l(L),r(R),v(V){}
inline bool operator <(const node &b)const
{return l<b.l;}
};
set<node> s;
IT split(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-,v));
return s.insert(node(pos,r,v)).first;
}
void assign(int l,int r,int v){
IT itr=split(r+),itl=split(l);
s.erase(itl,itr),s.insert(node(l,r,v));
}
void rev(int l,int r){
IT itr=split(r+),itl=split(l);
for(;itl!=itr;++itl) itl->v^=;
}
int sum(int l,int r){
IT itr=split(r+),itl=split(l);
int res=;
for(;itl!=itr;++itl) res+=itl->v?itl->r-itl->l+:;
return res;
}
int count(int l,int r){
int res=,tmp=;IT itr=split(r+),itl=split(l);
for(;itl!=itr;++itl)
itl->v?(tmp+=itl->r-itl->l+):(cmax(res,tmp),tmp=);
return std::max(res,tmp);
}
int main(){
// freopen("testdata.in","r",stdin);
int n=read(),m=read();
for(int i=;i<n;++i) s.insert(node(i,i,read()));
s.insert(node(n,n,));
while(m--){
int op=read(),l=read(),r=read();
switch(op){
case :assign(l,r,);break;
case :assign(l,r,);break;
case :rev(l,r);break;
case :print(sum(l,r));break;
case :print(count(l,r));break;
}
}
return Ot(),;
}

洛谷P2572 [SCOI2010]序列操作(珂朵莉树)的更多相关文章

  1. 洛谷$P2572\ [SCOI2010]$ 序列操作 线段树/珂朵莉树

    正解:线段树/珂朵莉树 解题报告: 传送门$w$ 本来是想写线段树的,,,然后神仙$tt$跟我港可以用珂朵莉所以决定顺便学下珂朵莉趴$QwQ$ 还是先写线段树做法$QwQ$? 操作一二三四都很$eas ...

  2. 洛谷 P2572 [SCOI2010]序列操作

    题意简述 维护一个序列,支持如下操作 把[a, b]区间内的所有数全变成0 把[a, b]区间内的所有数全变成1 把[a,b]区间内所有的0变成1,所有的1变成0 询问[a, b]区间内总共有多少个1 ...

  3. 洛谷P2572 [SCOI2010]序列操作

    线段树 pushdown写的很浪~ #include<cstdio> #include<cstdlib> #include<algorithm> #include& ...

  4. 洛谷P2572 [SCOI2010]序列操作(ODT)

    题解 题意 题目链接 Sol ODT板子题..... // luogu-judger-enable-o2 #include<bits/stdc++.h> #define LL long l ...

  5. [洛谷P3987]我永远喜欢珂朵莉~

    [洛谷P3987]我永远喜欢珂朵莉~ 题目大意: 给你\(n(n\le10^5)\)个数\(A_{1\sim n}(A_i\le5\times10^5)\),\(m(m\le5\times10^5)\ ...

  6. 洛谷P3987 我永远喜欢珂朵莉~(set 树状数组)

    题意 题目链接 Sol 不会卡常,自愧不如.下面的代码只有66分.我实在懒得手写平衡树了.. 思路比较直观:拿个set维护每个数出现的位置,再写个线段树维护区间和 #include<bits/s ...

  7. [转]我的数据结构不可能这么可爱!——珂朵莉树(ODT)详解

    参考资料: Chtholly Tree (珂朵莉树) (应某毒瘤要求,删除链接,需要者自行去Bilibili搜索) 毒瘤数据结构之珂朵莉树 在全是珂学家的珂谷,你却不知道珂朵莉树?来跟诗乃一起学习珂朵 ...

  8. 洛谷 P5350 序列 珂朵莉树

    题目描述 分析 操作一.二.三为珂朵莉树的基本操作,操作四.五.六稍作转化即可 不会珂朵莉树请移步至这里 求和操作 把每一段区间分别取出,暴力相加 ll qh(ll l,ll r){ it2=Spli ...

  9. 【题解】Luogu P2572 [SCOI2010]序列操作

    原题传送门:P2572 [SCOI2010]序列操作 这题好弱智啊 裸的珂朵莉树 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 操作1:把区间内所有数推平成0,珂朵莉树基本操作 ...

随机推荐

  1. [Bzoj4570][Scoi2016]妖怪(右上凸包)

    4570: [Scoi2016]妖怪 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1110  Solved: 336[Submit][Status][ ...

  2. 权限对于目录和文件的具体含义 linux

    权限对于具体文件的含义 文件上存储具体数据的地方,包括一般文件,数据库文件,二进制可执行文件等.因此权限对于文件的意义上这样都 r: 可读权限,表示可以读取该文件的内容 w:可写权限,表示可以编辑,新 ...

  3. mysql.bat

    cls  @echo off :设置窗口字体颜色 color 0a  :设置窗口标题 TITLE MySQL管理程序    call :checkAdmin    goto menu :菜单 :men ...

  4. intelliJ IDEA工具快捷键

    F9            resume programe 恢复程序 Alt+F10        show execution point 显示执行断点 F8            Step Ove ...

  5. 【Nginx】Nginx事件模块

    一.事件处理框架概述 事件处理框架所要解决的问题是如何收集.管理.分发事件.事件以网络事件和定时器事件为主,而网络事件中以TCP网络事件为主.事件处理框架需要在不同的操作系统内核中选择一种事件驱动机制 ...

  6. Ulua_toLua_基本案例(一)

    Ulua_toLua_基本案例 在Untiy中用Lua.必需要LuaInterface.LuaInterface的介绍请看:点击打开链接 能够先光写Lua,生成.lua的纯文件.再Unity中通过,l ...

  7. linux下weblogic11g成功安装后,启动报错Getting boot identity from user

    <2015-7-1 下午05时46分33秒 CST> <Info> <Management> <BEA-141107> <Version: Web ...

  8. Java-ReentrantReadWriteLock的简单样例

    内容:读锁时共享的.写锁时相互排斥的(可见执行结果).都是通过AQS实现的. public class ReentrantReadWriteLockTest { static class MyObje ...

  9. web 界面设计---js设置txt值

    <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312&quo ...

  10. 深入分析JavaWeb Item13 -- jsp指令具体解释

    一.JSP指令简单介绍 JSP指令(directive)是为JSP引擎而设计的.它们并不直接产生不论什么可见输出,而仅仅是告诉引擎怎样处理JSP页面中的其余部分. 在JSP 2.0规范中共定义了三个指 ...