[BZOJ1251] 序列终结者

2024-01-09 12:48
文章标签 序列 终结者 bzoj1251

本文主要是介绍[BZOJ1251] 序列终结者,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

传送门

http://www.lydsy.com/JudgeOnline/problem.php?id=1251

题目大意

支持
1.区间+-
2.区间翻转
3.查询区间最大值

题解

Splay模板题
注意+-标记的下放
这个节点打上+-标记表明该节点的权值和最值已被处理过

constmaxn=100005;
varw:array[-1..maxn,1..8]of longint;ans:array[0..maxn]of longint;i,j,k:longint;n,m,sum,root,a,b,c,d:longint;
procedure pushdown(a:longint);
var c:longint;
beginif w[a,7]<>0 then beginc:=w[a,1]; w[a,1]:=w[a,2]; w[a,2]:=c;w[a,7]:=0; w[w[a,1],7]:=w[w[a,1],7] xor 1; w[w[a,2],7]:=w[w[a,2],7] xor 1;end;if w[a,8]<>0 then beginif w[a,1]<>-1 then begin inc(w[w[a,1],8],w[a,8]); inc(w[w[a,1],5],w[a,8]); inc(w[w[a,1],6],w[a,8]); end;if w[a,2]<>-1 then begin inc(w[w[a,2],8],w[a,8]); inc(w[w[a,2],5],w[a,8]); inc(w[w[a,2],6],w[a,8]); end;w[a,8]:=0;end;
end;function max(a,b:longint):longint;
beginif a>b then exit(a) else exit(b);
end;procedure rotate(a,kind:longint);
var b,unkind:longint;
beginpushdown(b); pushdown(a);b:=w[a,3]; unkind:=kind xor 3;w[a,4]:=w[b,4]; dec(w[b,4],1+w[w[a,kind],4]);w[w[a,unkind],3]:=b; w[b,kind]:=w[a,unkind];w[a,unkind]:=b; w[a,3]:=w[b,3]; w[b,3]:=a;if w[a,3]<>-1thenif w[w[a,3],1]=bthen w[w[a,3],1]:=aelse w[w[a,3],2]:=a;w[b,5]:=max(max(w[w[b,1],5],w[w[b,2],5]),w[b,6]);w[a,5]:=max(max(w[w[a,1],5],w[w[a,2],5]),w[a,6]);
end;procedure splay(a,goal:longint);
var kind,b,unkind:longint;
beginwhile w[a,3]<>goal dobeginb:=w[a,3]; if w[b,1]=a then kind:=1 else kind:=2; unkind:=kind xor 3;if w[b,3]=goal then rotate(a,kind)elseif w[w[b,3],kind]=bthen begin rotate(b,kind); rotate(a,kind); endelse begin rotate(a,kind); rotate(a,unkind); end;end;if goal=-1 then root:=a;
end;procedure init(a:longint);
var tt,fa:longint;
begintt:=root;while tt<>-1 dobegin fa:=tt; inc(w[tt,4]); tt:=w[tt,2]; end;inc(sum); w[sum,1]:=-1; w[sum,2]:=-1; w[sum,3]:=fa; w[sum,4]:=1; w[sum,5]:=0; w[sum,6]:=0; w[sum,7]:=0; w[sum,8]:=0;if a=n+1 then w[sum,6]:=-maxlongint; splay(sum,-1);
end;function getkth(a:longint):longint;
var tt:longint;
begintt:=root; if (w[tt,7]<>0)or(w[tt,8]<>0) then pushdown(tt);while (w[w[tt,1],4]>=a)or(a>=w[w[tt,1],4]+2) dobeginif a<=w[w[tt,1],4]then tt:=w[tt,1]else begin dec(a,w[w[tt,1],4]+1); tt:=w[tt,2]; end;if (w[tt,7]<>0)or(w[tt,8]<>0) then pushdown(tt);end;exit(tt);
end;beginreadln(n,m); sum:=1; root:=1; w[-1,5]:=-maxlongint; w[-1,6]:=-maxlongint;w[1,1]:=-1; w[1,2]:=-1; w[1,3]:=-1; w[1,4]:=1; w[1,5]:=0; w[1,6]:=-maxlongint; w[1,7]:=0; w[1,8]:=0;for i:=1 to n+1 doinit(i);ans[0]:=0;for i:=1 to m dobeginread(a);case a of1:begin readln(b,c,d); splay(getkth(b),-1); splay(getkth(c+2),root);inc(w[w[w[root,2],1],8],d); inc(w[w[w[root,2],1],5],d); inc(w[w[w[root,2],1],6],d);end;2:begin readln(b,c); splay(getkth(b),-1); splay(getkth(c+2),root);w[w[w[root,2],1],7]:=w[w[w[root,2],1],7] xor 1;end;3:begin readln(b,c); splay(getkth(b),-1); splay(getkth(c+2),root);pushdown(w[w[root,2],1]);inc(ans[0]); ans[ans[0]]:=w[w[w[root,2],1],5];end;end;end;for i:=1 to ans[0] dowriteln(ans[i]);
end.

这篇关于[BZOJ1251] 序列终结者的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/587163

相关文章

uva 10131 最长子序列

题意: 给大象的体重和智商,求体重按从大到小,智商从高到低的最长子序列,并输出路径。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vect

POJ1631最长单调递增子序列

最长单调递增子序列 import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.io.PrintWriter;import java.math.BigInteger;import java.util.StringTokenizer;publ

leetcode105 从前序与中序遍历序列构造二叉树

根据一棵树的前序遍历与中序遍历构造二叉树。 注意: 你可以假设树中没有重复的元素。 例如,给出 前序遍历 preorder = [3,9,20,15,7]中序遍历 inorder = [9,3,15,20,7] 返回如下的二叉树: 3/ \9 20/ \15 7   class Solution {public TreeNode buildTree(int[] pr

day-50 求出最长好子序列 I

思路 二维dp,dp[i][h]表示nums[i] 结尾,且有不超过 h 个下标满足条件的最长好子序列的长度(0<=h<=k),二维数组dp初始值全为1 解题过程 状态转换方程: 1.nums[i]==nums[j],dp[i,h]=Math.max(dp[i,h],dp[j,h]+1) 2.nums[i]!=nums[j],dp[i,h]=Math.max(dp[i,h],dp[j,h-1

LeetCode:3177. 求出最长好子序列 II 哈希表+动态规划实现n*k时间复杂度

3177. 求出最长好子序列 II 题目链接 题目描述 给你一个整数数组 nums 和一个非负整数k 。如果一个整数序列 seq 满足在下标范围 [0, seq.length - 2] 中 最多只有 k 个下标i满足 seq[i] != seq[i + 1] ,那么我们称这个整数序列为好序列。请你返回 nums中好子序列的最长长度。 实例1: 输入:nums = [1,2,1,1,3],

用Python实现时间序列模型实战——Day 14: 向量自回归模型 (VAR) 与向量误差修正模型 (VECM)

一、学习内容 1. 向量自回归模型 (VAR) 的基本概念与应用 向量自回归模型 (VAR) 是多元时间序列分析中的一种模型,用于捕捉多个变量之间的相互依赖关系。与单变量自回归模型不同,VAR 模型将多个时间序列作为向量输入,同时对这些变量进行回归分析。 VAR 模型的一般形式为: 其中: ​ 是时间  的变量向量。 是常数向量。​ 是每个时间滞后的回归系数矩阵。​ 是误差项向量,假

时间序列|change point detection

change point detection 被称为变点检测,其基本定义是在一个序列或过程中,当某个统计特性(分布类型、分布参数)在某时间点受系统性因素而非偶然因素影响发生变化,我们就称该时间点为变点。变点识别即利用统计量或统计方法或机器学习方法将该变点位置估计出来。 Change Point Detection的类型 online 指连续观察某一随机过程,监测到变点时停止检验,不运用到

Leetcode面试经典150题-128.最长连续序列-递归版本另解

之前写过一篇这个题的,但是可能代码比较复杂,这回来个简洁版的,这个是递归版本 可以看看之前的版本,两个版本面试用哪个都保过 解法都在代码里,不懂就留言或者私信 class Solution {/**对于之前的解法,我现在提供一共更优的解,但是这种可能会比较难懂一些(思想方面)代码其实是很简洁的,总体思想如下:不需要排序直接把所有数放入map,map的key是当前数字,value是当前数开始的

go json反序列化成指定类型

简介 简单的介绍一下使用go的json库,将json字符串反序列化成接口中指定的实现类 代码如下 package usejsontype ExamInterface interface {CheckRule(data any) bool}type IntStru struct {DefalutVal int `json:"defalut_val"`Max int `json:

代码随想录刷题day25丨491.递增子序列 ,46.全排列 ,47.全排列 II

代码随想录刷题day25丨491.递增子序列 ,46.全排列 ,47.全排列 II 1.题目 1.1递增子序列 题目链接:491. 非递减子序列 - 力扣(LeetCode) 视频讲解:回溯算法精讲,树层去重与树枝去重 | LeetCode:491.递增子序列_哔哩哔哩_bilibili 文档讲解:https://programmercarl.com/0491.%E9%80%92%E