date: 2018-11-25 08:31:30 updated: 2018-11-25 08:31:30 栈&队列&并查集&哈希表(julyedu网课整理) 栈和队列 1.定义 存放数据的线性表 操作:入栈/队列.出栈/队列.判断满/空 空间复杂度:O(n) 单次操作时间复杂度:O(1) 区别 先进后出(FILO, First In Last Out) 先进先出(FIFO, First In First Out) 2.实现 数组和链表皆可(线性表) 指针(辅助变量) 栈顶/底指…
Trie.并查集.堆.Hash表: Trie 快速存储和查找字符串集合 字符类型统一,将单词在最后一个字母结束的位置上打上标记 练习题:Trie字符串统计 import java.util.*; public class Main{ static int N = 100010; static int[][] son = new int[N][26]; static int[] con = new int[N]; static int idx =0; static char[] str = new…
传送门 一个朴素的做法就是暴力连边并查集,可是这是\(O(n^2)\)的.发现每一次连边可以看成两个区间覆盖,这两个区间之间一一对应地连边.可线段树对应的两个节点的size可能不同,这会导致"一一对应"的条件在线段树上失效.所以我们需要使用ST表来完成连边. 对原序列建好ST表,对于每一个修改将两个区间覆盖到ST表上然后两两之间连边.注意在ST表上连边的两个区间要对应,即如果ST表上对应\([l,r]\)的区间与对应\([L,R]\)的区间连了边,意味着对于\(\forall i \i…
度度熊保护村庄 Accepts: 13 Submissions: 488 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description 哗啦啦村袭击了喵哈哈村! 度度熊为了拯救喵哈哈村,带着自己的伙伴去救援喵哈哈村去了!度度熊与伙伴们很快的就过来占据了喵哈哈村的各个军事要地,牢牢的守住了喵哈哈村. 但是度度熊发现,这是一场旷日持久的战斗,所以度度熊决定要以逸…
Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 37340 Accepted: 9796 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straight line suc…
点击打开链接 Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27955 Accepted: 7403 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks…
Colored Sticks DescriptionYou are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straight line such that the colors of the endpoints that touch are of the same color?Inp…