BZOJ1493 [NOI2007]项链工厂
未完待续。。。
终于改对了 热泪盈眶.jpg
错误原因:pushdown的时候没有判断是否有左右儿子,也没当x=0 return,于是出现一些奇怪的错误
#include<bits/stdc++.h>
using namespace std;
#define N 500005
char s[];
int n,m;
int root,fa[N],sz[N],ch[N][],lc[N],rc[N],num[N],c[N],rev[N],tag[N];
void pushup(int x){
int l=ch[x][],r=ch[x][];
sz[x]=sz[l]+sz[r]+;
num[x]=num[l]+num[r]+;
lc[x]=rc[x]=c[x];
if(l)num[x]-=rc[l]==c[x],lc[x]=lc[l];
if(r)num[x]-=lc[r]==c[x],rc[x]=rc[r];
}
void pushdown(int x){
if(!x)return;
int l=ch[x][],r=ch[x][];
if(tag[x]){
tag[x]=;
if(l){
num[l]=;tag[l]=;
lc[l]=rc[l]=c[l]=c[x];
}
if(r){
num[r]=;tag[r]=;
lc[r]=rc[r]=c[r]=c[x];
}
}
if(rev[x]){
rev[x]^=;rev[l]^=;rev[r]^=;
if(l){
swap(lc[l],rc[l]);
swap(ch[l][],ch[l][]);
}
if(r){
swap(lc[r],rc[r]);
swap(ch[r][],ch[r][]);
}
}
}
void rotate(int x){
int y=fa[x],z=fa[y],k=ch[y][]==x;
fa[ch[y][k]=ch[x][!k]]=y;
fa[ch[x][!k]=y]=x;
fa[x]=z;
if(z)ch[z][ch[z][]==y]=x;else root=x;
pushup(y);
}
void splay(int x,int f){
pushdown(x);
while(fa[x]!=f){
int y=fa[x],z=fa[y];
pushdown(z);pushdown(y);pushdown(x);
if(z==f)rotate(x);
else{
if((ch[z][]==y)==(ch[y][]==x))rotate(y);
else rotate(x);
rotate(x);
}
}
pushup(x);
}
int select(int k,int f){
int x=root;pushdown(x);
while(sz[ch[x][]]!=k-){
if(sz[ch[x][]]>=k)x=ch[x][];
else k-=sz[ch[x][]]+,x=ch[x][];
pushdown(x);
}
splay(x,f);
return x;
}
void build(int l,int r,int f){
int mid=l+r>>;
fa[mid]=f;if(mid<f)ch[f][]=mid;else ch[f][]=mid;
if(l==r){sz[mid]=;lc[mid]=rc[mid]=c[mid];num[mid]=;return;}
if(l<mid)build(l,mid-,mid);
if(r>mid)build(mid+,r,mid);
pushup(mid);
}
void change(int k){
int x=select(n-k-,),y=select(n,root);
int z=ch[y][];fa[z]=;ch[y][]=;
pushup(y);pushup(x);
x=select(,);y=select(,root);
ch[y][]=z;fa[z]=y;
pushup(y);pushup(x);
}
void Flip(){
int x=select(,),y=select(n,root);
int z=ch[y][];
if(tag[z])return;
rev[z]^=;swap(ch[z][],ch[z][]);swap(lc[z],rc[z]);
pushup(y);pushup(x);
}
void Swap(int x,int y){
x=select(x+,);
int cx=c[x];
y=select(y+,);
int cy=c[y];
c[y]=cx;pushup(y);
splay(x,);
c[x]=cy;pushup(x);
}
void Paint(int x,int y,int cc){
if(x<=y){
x=select(x,);
y=select(y+,root);
int z=ch[y][];
tag[z]=;
c[z]=lc[z]=rc[z]=cc;num[z]=;
splay(z,);
}
else{
change(n--x);
Paint(,n--x+y,cc);
change(x-);
}
}
int CountSeg(int x,int y){
if(x<=y){
x=select(x,);y=select(y+,root);
return num[ch[y][]];
}
else{
change(n--x);
int ans=CountSeg(,n--x+y);
change(x-);
return ans;
}
}
int Count(){
int ans=num[root]-;
int x=select(,),y=select(n,root);
int z=ch[y][];
ans-=lc[z]==rc[z];
return max(ans,);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n+;i++)scanf("%d",&c[i]);
n+=;build(,n,);root=(+n)>>;
scanf("%d",&m);
int x,y,z;
while(m--){
scanf("%s",s);
if(s[]=='R'){
scanf("%d",&x);change(x);
}
else if(s[]=='F')Flip();
else if(s[]=='S'){
scanf("%d%d",&x,&y);Swap(x,y);
}
else if(s[]=='P'){
scanf("%d%d%d",&x,&y,&z);
Paint(x,y,z);
}
else if(s[]=='S'){
scanf("%d%d",&x,&y);
printf("%d\n",CountSeg(x,y));
}
else printf("%d\n",Count());
}
return ;
}
1493: [NOI2007]项链工厂
Time Limit: 30 Sec Memory Limit: 64 MB
Submit: 1320 Solved: 576
[Submit][Status][Discuss]
Description
.png)

Input
Output
对于每一个 C 和 CS 命令,应输出一个整数代表相应的答案。
Sample Input
1 2 3 2 1
4
C
R 2
P 5 5 2
CS 4 1
Sample Output
1
HINT

BZOJ1493 [NOI2007]项链工厂的更多相关文章
- bzoj1493[NOI2007]项链工厂 线段树
1493: [NOI2007]项链工厂 Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 1712 Solved: 723[Submit][Status] ...
- BZOJ1493 NOI2007 项链工厂 线段树模拟
提交地址:http://www.lydsy.com/JudgeOnline/problem.php?id=1493 题目大意:给一个数列,进行一系列操作.包括旋转,翻转,改变等操作,以及查询颜色段数. ...
- bzoj 1493: [NOI2007]项链工厂(线段树)
1493: [NOI2007]项链工厂 Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 1256 Solved: 545[Submit][Status] ...
- 数据结构(Splay平衡树): [NOI2007] 项链工厂
[NOI2007] 项链工厂 ★★★ 输入文件:necklace.in 输出文件:necklace.out 简单对比 时间限制:4 s 内存限制:512 MB [问题描述] T公司是一 ...
- 【BZOJ-1493】项链工厂 Splay
1493: [NOI2007]项链工厂 Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 1440 Solved: 626[Submit][Status] ...
- BZOJ_1493_[NOI2007]项链工厂_Splay
BZOJ_1493_[NOI2007]项链工厂_Splay Description T公司是一家专门生产彩色珠子项链的公司,其生产的项链设计新颖.款式多样.价格适中,广受青年人的喜爱. 最近T公司打算 ...
- 1493: [NOI2007]项链工厂
线段树. 真还就是个线段树.. 除去操作1,2的话,线段树很容易就处理了,问题在于如何处理操作1和2.(这点没想到).. 我们用一个delta维护操作1,如果没有旋转就+k,不然就-k. 每次读入i和 ...
- NOI2007项链工厂——sbTreap代码
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> ...
- NOI2007 项链工厂
题目链接:戳我 60pts 有一点容易写错的小细节: 比如说求全局的段数的时候,如果只有一种颜色,那么当左右端点相等时,就不要ans--了. 注意右端点小于左端点的情况. #include<io ...
随机推荐
- 在.net中使用GAC
转自:http://blog.log4d.com/2011/01/gac/ GAC GAC是什么?是用来干嘛的?GAC的全称叫做全局程序集缓存,通俗的理解就是存放各种.net平台下面需要使用的dll的 ...
- html5新增的主体结构元素
1. article 主体结构元素 通常是一篇文章.一个页面.一个独立完整的内容模块一般会带个标题,并放在 header 标签中,article 元素可以互相嵌套,使用频率极高,强调独立性,多注意下 ...
- golang笔记——数组与切片
一.切片的定义 我们可以从数组(go语言中很少直接使用数组)或者切片来初始化一个新的切片,也可以直接通过 make 来初始化一个所有元素为默认零值的切片. //1.通过数组来初始化切片 arr := ...
- Sql Server 日期格式化函数
Sql Server 中一个非常强大的日期格式化函数Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AMSelect CONVE ...
- 【荐】JavaScript编码风格
作者:阮一峰 Douglas Crockford是 JavaScript 权威,Json 格式就是他的发明. 去年 11 月他有一个演讲(Youtube),谈到了好的 JavaScript 编程风格是 ...
- 我爱模仿app之格瓦拉客户端
最近有很多人问我,这个效果该怎么实现,那个功能该怎么实现.所以我准备开个专题,找一些app模仿,写一些示例代码,以供大家参考. 第一个下手的就是格瓦拉,没用过的可以下载看看,效果做的还是可以的,专场, ...
- 十一. 一步步破解JEB 2.0demo版一
字符串解密算法还愿 jeb.jar为核心功能,所以主要分析这个 1. jar转dex在使用jeb分析 Android\sdk\build-tools\23.0.3 dx.bat --dex --out ...
- servlet 之 复习
servlet 他是我们第一个动态资源,servlet和JSP都是. servlet ===> server applet 运行在服务器端的小程序. 1.获得请求 2.处理请求 3.完成响应 s ...
- AngularJS SQL 获取数据
使用PHP从MySQL中获取数据: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- Android -- Activity,Fragment lifecycle
Activity Lifecyce Fragment Lifecycle: 程序运行: 09-16 13:59:22.883 19022-19022/com.example.android.archi ...