传送门

珂朵莉树是个吼东西啊

这题线段树代码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. HDU 5695 Gym Class

    拓扑排序. #include<cstdio> #include <iostream> #include<cstring> #include<cmath> ...

  2. curl post请求方式

    curl -l -H "application/x-www-form-urlencoded; charset=UTF-8" -X POST -d "query=SELEC ...

  3. 百亿级企业级 RPC 框架开源了!

    今天给大家介绍给一款性能卓越的 RPC 开源框架,其作者就是我推荐每个 Java 程序员都应该看的<Java 生态核心知识点整理>的原作者张玉龙. 说实话我第一次看到这个资料的时候,就感觉 ...

  4. jsoncpp的api简要说明

    1  jsoncpp的api简要说明 1,解析(json字符串转为对象) std::string strDataJson; Json::Reader JReader; Json::Value JObj ...

  5. Selenium系列之--03【转】页面元素找不到问题的分析思路

    如果在测试过程中遇到了NoSuchElementException 这个异常, 说明元素查找失败. Caused by: org.openqa.selenium.NoSuchElementExcept ...

  6. 基于空间直方图meanshift跟踪

    近期看了一篇文章<spatiograms versus histograms for region-based tracking>,在此把这篇文章的核心思想及算法推理进行整理. 空间直方图 ...

  7. QtQuick桌面应用开发指导 1)关于教程 2)原型和设计 3)实现UI和功能_A

    Release1.0 http://qt-project.org/wiki/developer-guides Qt Quick Application Developer Guide for Desk ...

  8. 我的gulp.js清单

    var gulp = require('gulp'), cssmin = require('gulp-clean-css'), //压缩css文件 concat = require('gulp-con ...

  9. 【MongoDB】The description of procedure in MongoDB

    In this blog the procedure of mongodb will be described in details. It is known that mongodb has pro ...

  10. makefile redefinition or previous definition

    operation.h:4: error: redefinition of 'class operation' operation.h:5: error: previous definition of ...