洛谷P2572 [SCOI2010]序列操作(珂朵莉树)
珂朵莉树是个吼东西啊
这题线段树代码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]序列操作(珂朵莉树)的更多相关文章
- 洛谷$P2572\ [SCOI2010]$ 序列操作 线段树/珂朵莉树
正解:线段树/珂朵莉树 解题报告: 传送门$w$ 本来是想写线段树的,,,然后神仙$tt$跟我港可以用珂朵莉所以决定顺便学下珂朵莉趴$QwQ$ 还是先写线段树做法$QwQ$? 操作一二三四都很$eas ...
- 洛谷 P2572 [SCOI2010]序列操作
题意简述 维护一个序列,支持如下操作 把[a, b]区间内的所有数全变成0 把[a, b]区间内的所有数全变成1 把[a,b]区间内所有的0变成1,所有的1变成0 询问[a, b]区间内总共有多少个1 ...
- 洛谷P2572 [SCOI2010]序列操作
线段树 pushdown写的很浪~ #include<cstdio> #include<cstdlib> #include<algorithm> #include& ...
- 洛谷P2572 [SCOI2010]序列操作(ODT)
题解 题意 题目链接 Sol ODT板子题..... // luogu-judger-enable-o2 #include<bits/stdc++.h> #define LL long l ...
- [洛谷P3987]我永远喜欢珂朵莉~
[洛谷P3987]我永远喜欢珂朵莉~ 题目大意: 给你\(n(n\le10^5)\)个数\(A_{1\sim n}(A_i\le5\times10^5)\),\(m(m\le5\times10^5)\ ...
- 洛谷P3987 我永远喜欢珂朵莉~(set 树状数组)
题意 题目链接 Sol 不会卡常,自愧不如.下面的代码只有66分.我实在懒得手写平衡树了.. 思路比较直观:拿个set维护每个数出现的位置,再写个线段树维护区间和 #include<bits/s ...
- [转]我的数据结构不可能这么可爱!——珂朵莉树(ODT)详解
参考资料: Chtholly Tree (珂朵莉树) (应某毒瘤要求,删除链接,需要者自行去Bilibili搜索) 毒瘤数据结构之珂朵莉树 在全是珂学家的珂谷,你却不知道珂朵莉树?来跟诗乃一起学习珂朵 ...
- 洛谷 P5350 序列 珂朵莉树
题目描述 分析 操作一.二.三为珂朵莉树的基本操作,操作四.五.六稍作转化即可 不会珂朵莉树请移步至这里 求和操作 把每一段区间分别取出,暴力相加 ll qh(ll l,ll r){ it2=Spli ...
- 【题解】Luogu P2572 [SCOI2010]序列操作
原题传送门:P2572 [SCOI2010]序列操作 这题好弱智啊 裸的珂朵莉树 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 操作1:把区间内所有数推平成0,珂朵莉树基本操作 ...
随机推荐
- strcpy c标准库函数
C语言标准库函数strcpy,把从src地址开始且含有NULL结束符的字符串复制到以dest开始的地址空间. 已知strcpy函数的原型是: char *strcpy(char *dst, const ...
- sgu208:Toral Tickets(Pólya定理)
题意简述:给你N和M,对于一个N∗M的单面方格纸你能够对它的每 个个格子黑白染色.然后把方格纸的长边卷起来,卷成一个圆柱体,然后再把 两个短边形成的圆也接起来.形成一个游泳圈的形状(我们染的色仅仅在游 ...
- Android中传递对象的三种方法
Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! Android中,Activity和Fragment之间传递对象,可以通过将对象序列化并存入Bundle或者I ...
- 【APUE】文件I/O
Linux的内核将所有外部设备都可以看做一个文件来操作.那么我们对与外部设备的操作都可以看做对文件进行操作.我们对一个文件的读写,都通过调用内核提供的系统调用:内核给我们返回一个file descri ...
- Android中的动画具体解释系列【2】——飞舞的蝴蝶
这一篇来使用逐帧动画和补间动画来实现一个小样例,首先我们来看看Android中的补间动画. Android中使用Animation代表抽象的动画类,该类包含以下几个子类: AlphaAnimation ...
- Part1-Redefining your data-access strategy 重新定义你的数据访问策略
欢迎来到Entity Framework 4 In Action,EF是微软3.5 SP1推出的ORM工具,现在已经更新到4.0版本(...)本书能确保你in a robust and model- ...
- 2016/04/26 权限 数据库mydb2 五个表 分别是 1,用户 2,角色 3,权限 4,用户对应的角色 5,角色对应的权限
权限: 1,后台分配角色 角色对应权限 2,各用户通过登录页面登录 查看到各自的权限 五个页面 加引入一个jquery-1.11.2.min.js 1,guanli.php ...
- The uWSGI project aims at developing a full stack for building hosting services.
https://github.com/unbit/uwsgi-docs/blob/master/index.rst
- ubuntu安装ibus-goolepinyin通用方法
1:获取安装包 http://code.google.com/p/libgooglepinyin/downloads/list
- YTU 2851: 数字游戏
2851: 数字游戏 时间限制: 1 Sec 内存限制: 128 MB 提交: 164 解决: 85 题目描述 输入若干个正整数,将其中能写成其它两个正整数的平方和的数输出来. 例,若输入的数中有 ...