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 ...
随机推荐
- Mac 效率工具
我的Mac开发环境 http://blog.csdn.net/feelang/article/details/45071249 iterm2 http://iterm2.com/documentati ...
- 浅谈Android中拍照、从相册选择图片并截图相关知识点
前言 我们在Android开发中经常会需要使用相机或者从相册中选取图片的情况,今天就把这里面相关的知识点总结下,方便以后开发的时候使用. 1.相机拍照并可自定义截图功能 我们先来看如何使用Intent ...
- .NET导入Excel到SQL数据库
在我们开发各类应用型系统,经常会遇到导入导出Excel,为什么会用到他呢?企业或者单位在从无信息化到信息化的一个转变过程.在没有信息化的企业或单位之前,一般都采用Excel来记录相应的数据,做统计计算 ...
- jQuery如何给body绑定事件?
jQuery如何给body绑定事件? 代码如下: $(document).bind("resize", function () { alert("php-note.com ...
- Linux C 字符串输入函数 gets()、fgets()、scanf() 详解
一.gets() 函数详解 gets()函数用来从 标准输入设备(键盘)读取字符串直到 回车结束,但回车符('\n')不属于这个字符串. 调用格式为: gets(str); 其中str为字符串变量(字 ...
- codeblock 编译googletest
1.cmake安装 2.codeblock 16.01 3.Google Test 1.7.0 4.PATH路径添加(重启电脑,保证设置的PATH路径生效) 5.python安装 6.编译安装: ...
- Linux下c开发 之 线程通信(转)
Linux下c开发 之 线程通信(转) 1.Linux“线程” 进程与线程之间是有区别的,不过Linux内核只提供了轻量进程的支持,未实现线程模型.Linux是一种“多进程单线程”的操作系统.Linu ...
- espcms内容页上下篇按后台手动排序号
模板文件: {%get name=plist class="did":$read.did,pid:$read.pid%} <li class="fl"&g ...
- [转]Struts2工作原理
Struts2请求响应流程: 在struts2的应用中,从用户请求到服务器返回相应响应给用户端的过程中,包含了许多组件如:Controller.ActionProxy.ActionMapping.Co ...
- MySQL备份之【mydumper 学习】
MySQL在备份方面包含了自身的mysqldump工具,但其只支持单线程工作,这就使得它无法迅速的备份数据.而mydumper作为一个实用工具,能够良好支持多线程工作,这使得它在处理速度方面十倍于传统 ...