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 ...
随机推荐
- ecshop 实现购物车退出不清空
ecshop模板在使用过程中会遇到会员退出再登陆时购物车里面的商品会被清空掉的,通过ecshop开发中心的技术,整理的文档,对程序做简单修改即可实现会员退出不清空购物车 ECShop版本:V2.7.3 ...
- Android接入支付宝和银联
支付宝接入参考链接:https://software.intel.com/zh-cn/node/542608 银联接入参考链接:http://blog.csdn.net/gf771115/articl ...
- ThinkPhP 分页
<?php namespace User\Service; use Think\Controller; use Think\Exception; class UserService { // 每 ...
- Json字符串和Json对象的简单总结
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.JSON成为理想的数据交换语言. 易于人阅读和编写,同时也易于机器解析和生成(一般用于提升网络传输速率). ...
- Description Resource Path Location Type Java compiler level does not match the version of the instal
解决办法 在项目上右键Properties->Project Facets,在打开的Project Facets页面中的Java下拉列表中,选择相应版本. 有可能是java1.6 改成java6 ...
- Javascript 俄罗斯方块 游戏代码解释!
俄罗斯方块代码说明 /** 名称:Javascript 俄罗斯方块! 作者:Gloot 邮箱:glootz@gmail.com QQ:345268267 网站:http://www.cnblogs.c ...
- 【转载】使用pandas进行数据清洗
使用pandas进行数据清洗 本文转载自:蓝鲸的网站分析笔记 原文链接:使用python进行数据清洗 目录: 数据表中的重复值 duplicated() drop_duplicated() 数据表中的 ...
- 关于session和cookie
一.cookie机制和session机制的区别 **************************************************************************** ...
- Mongodb profile(慢查询日志)
在MySQL中,慢查询日志是经常作为我们优化数据库的依据,那在MongoDB中是否有类似的功能呢?答案是肯定的,那就是MongoDB Database Profiler.所以MongoDB 不仅有,而 ...
- Thrift的TCompactProtocol紧凑型二进制协议分析
Thrift的紧凑型传输协议分析: 用一张图说明一下Thrift的TCompactProtocol中各个数据类型是怎么表示的. 报文格式编码: bool类型: 一个字节. 如果bool型的字段是结构体 ...