- 博客(17)
- 收藏
- 关注
原创 splay 学习笔记
splay核心函数splay:每次访问一个节点,都把该节点转到根 (包括插入/查找/操作)思想:对于访问频率较高的节点,使其处于根节点附近,从而保证log复杂度splay可以维护中序遍历是有序序列也可维护 中序遍历是当前操作后的序列AcWing 2437. SplayP1486 [NOI2004] 郁闷的出纳员const int N=1e5+10;struct node{ int s[2],fa,v; //son,fa,val int sz,tag; //flag懒标记 }t[N];
2021-03-06 09:40:32
143
原创 可持久化数据结构——学习笔记
可持久化前提:本身的拓扑结构不改变 (平衡树左右旋,拓扑结构改变,不可持久化)核心思想:存下数据结构的所有历史版本时,只记录每个版本与前一个版本 改变的部分,每次新增部分至多log(n)个节点,m次为mlog(n)可持久化trie:算法步骤:1、插入:枚举str的每一位,当前位s[i]新建一个节点,当前位的其余字符都与上一版本相同,直接copy2、查询:查询(l,r)的某个信息时,利用历史版本的可减性,®-(l-1)得到区间(l,r)的信息P4735 最大异或和题意:在前缀和{S[i]}中
2021-03-03 21:53:32
190
1
原创 AC自动机学习笔记
AC自动机trie+kmp构建fail指针朴素思想:当前节点为p,之前已求得fail[p]trie[p,c]是p 通过字符c指向的 一个子节点,现要求fail[ trie[p,c] ],即fail[x]若trie[fail[p],c]存在,则fail[x]=trie[fail[p],c], 即p的子节点的fail = p的fail的子节点否则,让p一直跳fail指针,fail[x]=trie[fail[fail[p]],c],直到存在 / 根节点fail路径压缩后,可优化为trie图匹配查
2021-03-03 21:26:05
175
1
原创 平衡树 treap 学习笔记
平衡树 treap平衡树本质上是维护一个有序序列 (中序遍历)treap将随机性作用于堆性质,并通过左旋 / 右旋维护,将树高维护在O(logn)基本操作插入数值x删除数值x查询数值x的排名(若有多个相同的数,应输出最小的排名)。查询排名为x的数值。求数值x的前驱(前驱定义为小于x的最大的数)。求数值x的后继(后继定义为大于x的最小的数)。STL set没有的操作:1、get_rank_by_key2、get_key_by_rank1、删除操作:先查找需要删除的节点,将其旋转到叶
2021-03-01 23:16:02
138
原创 Codeforces Round #639 (Div. 2) BC
B找规律可以想象为 \\ 这样斜向右的摆放,每加一层,相当于把 最右边的 \ 向右平移复制一次,再加上最顶部的3个#include<bits/stdc++.h>using namespace std;typedef long long ll;const int MAX_N=3e4+5;long long f[MAX_N];int main(){ f[1]=2; ll x=5; long long mx=30000; for(int i=2;i<=mx;i
2020-05-14 22:19:06
207
原创 Codeforces Round #641 (Div. 2) BC
Bdp限制最长升的前后元素下标是倍数关系,只有下标是倍数关系才能转移也就是说对于每个i,只能转移到 i 的倍数,即外循环枚举i,内循环枚举倍数倍数法的时间复杂度为 nlogn#include<bits/stdc++.h>using namespace std;const int MAX_N=1e5+5;int a[MAX_N],f[MAX_N]; //表示以i结尾的最大长度 int main(){ int t; cin>>t; while(t--)
2020-05-14 22:00:33
233
原创 Codeforces Round #638 (Div. 2) BC
B要构造一个循环节为k的字符串计算相异元素个数c,若c>k,不可能构造若c<=k,取c个不同元素,再用相同元素补足k个,由于不限制插入个数,把每个数都延长为一个循环,即输出n个循环#include<bits/stdc++.h>using namespace std;const int MAX_N=105;int a[MAX_N],cnt[MAX_N],v[MAX_N];vector<int> tab; int main(){ int t; c
2020-05-14 21:36:48
176
原创 算法优化专题
题目A - Stars POJ - 2352Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars ...
2020-03-10 21:12:00
312
原创 codeforces 排位赛4
传送门题面B. Diverse Garlandtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a garland consisting of n lamps. Each lamp is colored red, g...
2020-03-10 19:55:08
296
原创 codeforces 排位赛3
传送门题面A. Wormhole Sorttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFarmer John’s cows have grown tired of his daily request that they sort...
2020-03-09 21:28:14
373
原创 codeforces 排位赛2
传送门题面A. Fence Planningtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFarmer John’s N cows, conveniently numbered 1…N (2≤N≤105), have a comp...
2020-03-09 20:40:43
226
原创 codeforces 排位赛1
传送门题面A. Cow Gymnasticstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn order to improve their physical fitness, the cows have taken up gym...
2020-03-09 20:10:36
337
原创 2019寒假专题一 L CodeForces - 1260B
题面B. Obtain Two Zeroestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers a and b. You may perform any number of opera...
2020-01-28 20:32:17
204
原创 2019寒假专题一 F bfs POJ - 1426
题面给定一个正整数n,请编写一个程序来寻找n的一个非零的倍数m,这个m应当在十进制表示时每一位上只包含0或者1。你可以假定n不大于200且m不多于100位。提示:本题采用Special Judge,你无需输出所有符合条件的m,你只需要输出任一符合条件的m即可。Input输入包含多组数据,每组数据仅一行,只包含一个正整数n (1 <= n <= 200).Output对于输入...
2020-01-28 18:50:26
243
原创 2019寒假专题一 A - 尺取模板题 POJ - 3061
题面A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal lengt...
2020-01-28 18:16:37
134
原创 二分 三分专题
题面农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,…,xN (0 <= xi <= 1,000,000,000). 但是,John的C (2 <= C <= N)头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争斗。为了不让牛互相伤害。John决定自己给牛分配隔间,使任意两...
2020-01-25 18:11:34
243
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人