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 ...
随机推荐
- marquee标签,好神奇啊...
<html><body><div style="height:190; margin-top:10; margin-bottom:10; width:96%; ...
- java 集合list遍历时删除元素
本文探讨集合在遍历时删除其中元素的一些注意事项,代码如下 import java.util.ArrayList; import java.util.Iterator; import java.util ...
- js高级群的一些整理6月
https://github.com/the5fire/backbonejs-learning-note/blob/master/chapters/01-hello-backbonejs.rst Ba ...
- 马化腾称春节前推出微信小程序
腾讯马化腾在第二届深商大会“互联与时代”论坛上透露,会在2017年春节前推出微信小程序.在谈到“互联网+”.开放生态等话题时,马化腾表示,腾讯从过去5年来,从封闭的环境变成一个开放的环境,变成一个真正 ...
- CSS背景background详解,background-position详解
背景(background)是css中一个重要的的部分,也是需要知道的css的基础知识之一.这篇文章将会涉及css背景(background)的基本用法,包括诸如 background-attachm ...
- PHP exec/system启动windows应用程序,执行.bat批处理,执行cmd命令
exec 或者 system 都可以调用cmd 的命令 直接上代码: <?php /** 打开windows的计算器 */ exec('start C:WindowsSystem32calc.e ...
- java基础 集合类
java集合类主要有以下集中: List结构的集合类: ArrayList类, LinkedList类, Vector类, Stack类 Map结构的集合类: HashMap类,Hashtable类 ...
- TouchSlide1.1,手机上的幻灯片
TouchSlide 是纯javascript打造的触屏滑动特效插件 http://pan.baidu.com/s/1bpoWNin 官网:http://www.superslide2.com/Tou ...
- Servlet 之 GenericServlet
我们都知道javaweb中servlet的三大组件 servlet filter listener 实现动态资源的 是可以继承 Servlet接口,或者集成GenericServlet .Http ...
- Linux服务器模型及其对应的程序流程
一.TCP循环服务器 TCP循环服务器一次只能处理一个客户端的请求,处理完成后,才能接受下一个客户端的请求,程序流程如下: socket(......);//创建套接字 bind(......);// ...