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 ...
随机推荐
- 1JavaEE应用简介----青软S2SH(笔记)
这本书主要是讲解Struts2,spring,Hibernate框架的, 因为工作中用的较多的是SpringMVC,Struts2用的较少,所以想系统学习一下,就买了这本书. 这本书是青软的,虽然是培 ...
- thinkphp一句话疑难解决笔记 2
php中的_ _call()方法? 它是php5后为对象 类 新增的一个自动方法. 它会监视类的其他方法的调用, 当调用类的不存在的方法时, 会自动调用类的__call方法. tp的 "命名 ...
- hashicorp/consul
https://github.com/hashicorp/consul/tree/master/vendor/github.com/boltdb/bolt
- svn 版本转为git
git clone 相当于git init 和 git svn fetch.git svn rease git svn fetch 从svn服务器取指定区间的版本转化成git库 git svn reb ...
- spring常见问题
问题1:提示说:cvc-elt.1: Cannot find the declaration of element 'beans' 解决方法:从网上搜了一些,有的说是因为网络原因访问不到xsd文件,因 ...
- PhpStorm 9.03 集成 开源中国(oschina.net)的Git项目,提交SVN时注意事项
第一步:配置 git.exe File -> Default Settings -> Version Control -> Git -> Path go Git executa ...
- 【Android学习】android布局中几个距离单位的区别:px、dp、sp
一.px 像素,我们经常说的400*800这种的就是像素,这个比较好理解. 二.dp 要理解dp,首先要先引入dpi这个概念,dpi全称是dots per inch,对角线每英寸的像素点的个数,所以, ...
- poj 1655
这道题我有很多要说 首先是基础的解题思路: 树形dp(dfs)用dp[i]保存以i为根结点的子树的大小(含i) balance(i)=max{n-dp[i],max{dp[j]}(j is a son ...
- mediastreamer使用教程
mediastreamer使用教程 1.各个函数功能简介 ms_filter_destroy 释放filter资源 ms_ticker_destroy释放ticker 说明:ticker为定时器线程, ...
- Is there a difference between `==` and `is` in Python?
There is a simple rule of thumb to tell you when to use == or is. == is for value equality. Use it w ...