Delicate Data Structures

1. Fenwich Tree

  树状数组提供复杂度为O($lg n$)的连续区域求和查询以及对指定元素的修改操作。

 1 #define N 1024
 2 #define lowbit(x) (x&(-x))
 3
 4 int arr[N];
 5
 6 void add(int idx,int delt)
 7 {
 8     while (idx<N) {
 9         arr[idx] += delt;
10         idx += lowbit(idx);
11 }
12
13 int sum(int idx)
14 {
15     int val = 0;
16     while (idx>0) {
17         val += arr[idx];
18         idx -= lowbit(idx);
19     }
20     return val;
21 }

  这里,lowbit是一个有参宏定义,用于提取整型数x的最低非零位。类似的定义方式还有:

# define divAndCeil(x,y) ((x+y-1)/y)

2. Skip List

  跳表,一种随机化数据结构,仅依赖于并联的链表,效率可比拟二叉搜索树。

  查询、插入、删除的平均时间都是O($lgn$),详见 wikipedia

  没时间分析算法、编码实现了。真心没时间了。T_T

3. Trie Tree

  字典树利用串的公共前缀节约内存,加快检索速度。

  根节点无字母;从根节点到某节点的路径上所有字母构成的序列为该节点对应的单词。

  树的结构可以用儿子链表(或数组)实现,也可以用 left-child, right-sibling tree 。

时间: 2024-08-11 09:51:49

Delicate Data Structures的相关文章

2017 UESTC Training for Data Structures

2017 UESTC Training for Data Structures A    水,找区间极差,RMQ怼上去. #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a;i<=b;i++) #define per(i,b,a) for (int i=b;i&

【DataStructure】Linked Data Structures

Arrayss work well for unordered sequences, and even for ordered squences if they don't change much. But if you want to maintain an ordered list that allows quick insertions and deletions, you should use a linked data structure. so inserting an elemen

2014 UESTC Training for Data Structures H - Cookies Test

H - Cookies Test Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status As chief programmer at a cookie production plant you have many responsibilities, one of them being that the cookies produced and packag

2014 UESTC Training for Data Structures K - 方师傅与栈

K - 方师傅与栈 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 方师傅有一个1?N的排列,排列的顺序是固定的,他想要把这个排列重新排列成他喜欢的顺序. 于是他买了一个栈,他会按顺序将排列扔进栈内,在某些时刻将栈顶元素取出,这样出栈后的排列就可以重新排序啦. 例如,原序列是1,2,他先将1入栈,再将2入栈,然后将2出栈,最后将1出栈,那么新序列就变

2014 UESTC Training for Data Structures J - 方师傅的01串

J - 方师傅的01串 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 方师傅过生日啦,于是蟹毛买了N个01串,想送给方师傅. 但是蟹毛觉得这些01串不够美,于是他想从中选出一些送给方师傅. 蟹毛对于p个01串的美值定义为: 这些01串的最长公共前缀的长度×p 所以蟹毛想从N个01串中选出一些,使得这些01串的美值最高. 请告诉蟹毛最好的美值是多少.

2014 UESTC Training for Data Structures C - 东风不与周郎便

C - 东风不与周郎便 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status "揽二乔于东南兮,乐朝夕之与共" 一首铜雀台赋,将愤怒与恐惧散播在了孙吴大军之中. 对抗曹军,万事俱备,只欠东风. 现在已经找到n个风眼,这些风眼的东风有强有弱,诸葛亮说他每次祈风都能够将一段风眼的东风增强,但需人去帮他布阵.同时他需要时刻掌控风眼的状况,以确定下一步的

2014 UESTC Training for Data Structures A - Islands

A - Islands Time Limit: 30000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status Deep in the Carribean, there is an island even stranger than the Monkey Island, dwelled by Horatio Torquemada Marley. Not only it has a re

pandas Data Structures

Series pandas Data Structures

Python Tutorial 学习(五)--Data Structures

5. Data Structures 这一章来说说Python的数据结构 5.1. More on Lists 之前的文字里面简单的介绍了一些基本的东西,其中就涉及到了list的一点点的使用.当然,它可不仅仅只有那么一点点,这里给出一个更详细一点的说明.来吧骚连,打开你的命令行窗口 >>>help(list) 看看会出来一些什么~~` list.append(x) 向一个序列里面追加元素 x a = [] a.append(x) # 假设x已经定义了 a[len(a):] = [x] l