随笔分类 -  线段树

摘要:题目链接 题意 多个矩形重叠在一起,求出轮廓线的长度。 分析 把矩形分成横线和竖线来处理。现在分析横线的,竖线同理。矩形的坐标都是整数,且范围不大,故此题不需要离散化。从下往上扫描横线,每遇到一条横线,就计算长度,矩形的下边标为1,上边标为-1。具体计算方法是此次区间的总覆盖长度与上次区间长度相比, 阅读全文
posted @ 2018-03-26 19:43 litos 阅读(148) 评论(0) 推荐(0)
摘要:You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number 阅读全文
posted @ 2018-03-18 22:26 litos 阅读(126) 评论(0) 推荐(0)
摘要:D. Closest Equals time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output D. Closest Equals time 阅读全文
posted @ 2018-03-14 21:32 litos 阅读(332) 评论(0) 推荐(0)
摘要:题目链接 题意:n个数m个查询,问[l,r]中的数是否为1到r-l+1的一个排列。 做法1:hash一下,对于[1...n],每个数都随机分配一个hash值,一个集合的hash值为元素异或和。预处理出[1...n]的hash值及其前缀的hash,然后就可以O(1)查询了 做法二:线段树若(l,r)中 阅读全文
posted @ 2017-07-29 21:13 litos 阅读(244) 评论(0) 推荐(0)