线段树
xuanweiace
一个热爱算法竞赛的弱校ACMer路过。青大本,浙大硕,方向后端开发,菜鸡一枚,奋斗ing...
展开
-
【北航oj】(线段树取模运算)
题干:https://buaacoding.cn/contest-ng/index.html#/334/problemsKwjj 的自动售货机时间限制:1000ms 内存限制:131072kb通过率:14/26(53.85%) 正确率:14/119(11.76%)wjj 最近很看好线下实体销售的行业, 他觉得可以先投资自动售货机来试试水。于是他在北航的新主楼...原创 2019-04-08 10:56:15 · 714 阅读 · 0 评论 -
【CodeForces - 438D】The Child and Sequence(线段树区间取模操作)
题干:At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks.Fortun...原创 2019-03-25 21:57:55 · 286 阅读 · 0 评论 -
【csust】最小素因子问题(树状数组)
题干:http://csustacm.com:4803/problem/1083Description寒冰射手艾希新学会了一个技能,艾希通过这个技能成为了一名声名远扬的神箭手,从此再也无人敢侵犯弗雷尔卓德!这个技能的描述如下(假设英雄联盟内的每个人都有一个编号):假设艾希有x-1(x>=2)x−1(x>=2)个敌人,每个敌人的编号分别为1\;\;1~\;\;x-1x...原创 2019-03-13 14:16:18 · 789 阅读 · 0 评论 -
【牛客 - 157C】PH试纸(前缀和,或权值线段树,主席树)
题干:链接:https://ac.nowcoder.com/acm/contest/157/C来源:牛客网题目描述PH试纸,是一种检测酸碱度的试纸,试纸红色为酸性,蓝色为碱性。HtBest有一个PH试纸,试纸被分成了n段,每一段都可以被染色成红色或者蓝色,WHZ在试纸的每一段上都染为一种颜色,HtBest有m个询问,对于每个询问,Ta想知道某种颜色第qi次在什么地...原创 2019-03-20 13:07:28 · 343 阅读 · 0 评论 -
【HDU - 5091】Beam Cannon(线段树,扫描线)
题干:Recently, the γ galaxies broke out Star Wars. Each planet is warring for resources. In the Star Wars, Planet X is under attack by other planets. Now, a large wave of enemy spaceships is approachi...原创 2019-03-16 08:19:09 · 269 阅读 · 0 评论 -
【牛客 - 370A】签到题(线段树扫描线 或 STLset)(求线段并)
题干:链接:https://ac.nowcoder.com/acm/contest/370/A来源:牛客网恭喜你找到了本场比赛的签到题!为了让大家都有抽奖的机会,只需要复制粘贴以下代码(并且稍微填下空)即可 AC:(我超良心的)#include <algorithm> #include <iostream> #include <cstrin...原创 2019-02-17 21:19:42 · 429 阅读 · 0 评论 -
【HDU - 1542】Atlantis (线段树,扫描线)
题干:There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe...原创 2019-02-17 21:10:59 · 208 阅读 · 0 评论 -
【HDU - 5700】【51nod - 1672】 区间交(贪心,STLset 或线段树第k大)
题干:小A有一个含有n个非负整数的数列与m个区间,每个区间可以表示为li,ri。它想选择其中k个区间, 使得这些区间的交的那些位置所对应的数的和最大。(是指k个区间共同的交,即每个区间都包含这一段,具体可以参照样例) 在样例中,5个位置对应的值分别为1,2,3,4,6,那么选择[2,5]与[4,5]两个区间的区间交为[4,5],它的值的和为10。 收起输入第一行三个数...原创 2019-02-17 21:11:17 · 238 阅读 · 0 评论 -
【牛客 - 331E】炫酷划线(权值线段树,树状数组哈希,随机数)
题干:链接:https://ac.nowcoder.com/acm/contest/331/E来源:牛客网 平面上有一个圆,圆环上按顺时针顺序分布着从1到n,一共n个点。现在无聊的小希开始按某种顺序对其在圆内两两连线,小希尽量避免让两条线碰撞,可是有的时候,这显然避免不了。现在你知道小希划线的顺序是什么,请你判断小希在最优情况下,什么时候会被迫使得线相交,输出最早的时刻(是第几条线...原创 2019-01-31 23:38:48 · 423 阅读 · 0 评论 -
【HDU - 6186】CS Course(按位与,按位或,按位异或的区间统计,二进制拆位)
题干:Little A has come to college and majored in Computer and Science.Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework.Here is the problem:You are givin...原创 2019-04-10 21:09:54 · 397 阅读 · 0 评论 -
【Gym - 101608G】WiFi Password (区间或,线段树 或 按位处理+尺取 或 二分)
题干:Just days before the JCPC, your internet service went down. You decided to continue your training at the ACM club at your university. Sadly, you discovered that they have changed the WiFi passwor...原创 2019-04-04 16:51:21 · 350 阅读 · 0 评论 -
【HDU - 5649】DZY Loves Sorting(线段树,区间更新区间查询,思维,01缩数变换,线段树分割)
题干:DZY has a sequencea[1..n]a[1..n]. It is a permutation of integers1∼n1∼n.Now he wants to perform two types of operations:0lr0lr: Sorta[l..r]a[l..r]in increasing order.1lr1lr: Sorta[l..r...原创 2019-04-07 19:05:14 · 325 阅读 · 0 评论 -
【HDU - 5489】Removed Interval(离散化,权值线段树,思维,最长上升子序列)
题干:Given a sequence of numbersA=a1,a2,…,aNA=a1,a2,…,aN, a subsequenceb1,b2,…,bkb1,b2,…,bkofAAis referred as increasing ifb1<b2<…<bkb1<b2<…<bk. LY has just learned how to find...原创 2019-09-13 21:57:54 · 305 阅读 · 0 评论 -
【HDU - 5493】Queue(思维,贪心,线段树)
题干:NNpeople numbered from 1 toNNare waiting in a bank for service. They all stand in a queue, but the queue never moves. It is lunch time now, so they decide to go out and have lunch first. When ...原创 2019-09-13 18:57:42 · 204 阅读 · 0 评论 -
【HDU - 5875】Function(线段树,区间第一个小于某个数的数 或 RMQ二分)
题干:The shorter, the simpler. With this problem, you should be convinced of this truth.You are given an arrayAAofNNpostive integers, andMMqueries in the form(l,r)(l,r). A functionF(l,...原创 2019-08-30 22:15:31 · 422 阅读 · 0 评论 -
【2019牛客暑期多校训练营(第二场)- E】MAZE(线段树优化dp,dp转矩阵乘法,线段树维护矩阵乘法)
题干:链接:https://ac.nowcoder.com/acm/contest/882/E?&headNav=acm来源:牛客网Given a maze with N rows and M columns, where bijb_{ij}bij represents the cell on the i-row, j-th column. If bi,j="1"b_{i,...原创 2019-08-21 22:11:21 · 329 阅读 · 0 评论 -
【HDU - 5475】An easy problem(线段树,思维)
题干:One day, a useless calculator was being built by Kuros. Let's assume that number X is showed on the screen of calculator. At first, X = 1. This calculator only supports two types of operation.1...原创 2019-07-15 14:54:48 · 191 阅读 · 0 评论 -
【2019浙江省赛 - A】Vertices in the Pocket(权值线段树下二分,图,思维)
题干:DreamGrid has just found an undirected simple graph withvertices and no edges (that's to say, it's a graph withisolated vertices) in his right pocket, where the vertices are numbered from 1 t...原创 2019-04-30 11:59:23 · 1194 阅读 · 5 评论 -
【HDU - 6183】Color it(CDQ分治 或 动态开点线段树)
题干:Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B is painting. To prevent him from drawing messy painting, Little D asks you to write a program ...原创 2019-04-12 15:20:32 · 251 阅读 · 0 评论 -
【HDU - 4056】Draw a Mess (并查集 or 线段树)
题干:It's graduated season, every students should leave something on the wall, so....they draw a lot of geometry shape with different color. When teacher come to see what happened, without getting an...原创 2018-12-24 09:15:34 · 302 阅读 · 0 评论 -
【牛客 - 297C】little w and Segment Coverage(差分数组,区间差分,思维,卡线段树)☆
题干: 小w有m条线段,编号为1到m。用这些线段覆盖数轴上的n个点,编号为1到n。第i条线段覆盖数轴上的区间是L[i],R[i]。覆盖的区间可能会有重叠,而且不保证m条线段一定能覆盖所有n个点。现在小w不小心丢失了一条线段,请问丢失哪条线段,使数轴上没被覆盖到的点的个数尽可能少,请输出丢失的线段的编号和没被覆盖到的点的个数。如果有多条线段符合要求,请输出编号最大线段的编号(编...原创 2018-12-24 09:10:25 · 286 阅读 · 0 评论 -
【CodeForces - 527C】Glass Carving(线段树或者SBT或者set)
题干:Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutter and lots ...原创 2018-11-19 15:27:04 · 256 阅读 · 0 评论 -
【POJ - 3468 】 A Simple Problem with Integers (线段树模板 区间更新 + 区间和查询)(不能树状数组或差分数组)
题干: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 in a given interval. The other is to ask for...原创 2018-08-11 11:30:58 · 228 阅读 · 0 评论 -
【HDU - 1698】 Just a Hook(线段树模板 区间覆盖更新(laz标记) + 区间和查询 )
题干:In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length. No...原创 2018-08-11 11:26:24 · 462 阅读 · 0 评论 -
【HDU - 1754】I Hate It (线段树模板 单点覆盖更新+区间最大值查询)
题干:很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。 这让很多学生很反感。 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。 在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200000,0<M...原创 2018-08-11 11:18:32 · 242 阅读 · 0 评论 -
【HDU - 1166】敌兵布阵 (线段树模板 单点更新+ 区间查询)
题干:C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。 中央情报局要研究敌人究竟演习什...原创 2018-08-11 11:13:18 · 246 阅读 · 0 评论 -
【HDU - 1540】 Tunnel Warfare (线段树进阶操作 区间合并+ 单点更新+ 最长覆盖区间查询 )
题干:During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Exc...原创 2018-08-11 11:00:58 · 243 阅读 · 0 评论 -
【HDU - 3974】 Assign the task (dfs序 + 线段树维护 区间更新+ 单点查询)
题干:There is a company that has N employees(numbered from 1 to N),every employee in the company has a immediate boss (except for the leader of whole company).If you are the immediate boss of someone,...原创 2018-08-09 20:35:23 · 369 阅读 · 0 评论 -
【POJ - 3321】 Apple Tree(dfs序 + 线段树维护 或 dfs序 + 树状数组维护)
题干:There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree.The tree h...原创 2018-08-09 19:03:17 · 308 阅读 · 0 评论 -
*【HDU - 4006】 The kth great number(优先队列 or 线段树)
题干:Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao ...原创 2018-07-30 00:10:12 · 211 阅读 · 0 评论 -
【51nod - 1065】 最小正子段和( 前缀和排序 )
题干:N个整数组成的序列a11,a22,a33,…,ann,从中选出一个子序列(aii,ai+1i+1,…ajj),使这个子序列的和>0,并且这个和是所有和>0的子序列中最小的。例如:4,-1,5,-2,-1,2,6,-2。-1,5,-2,-1,序列和为1,是最小的。Input第1行:整数序列的长度N(2 <= N <= 50000) 第2 - N+1行:...原创 2018-08-11 21:20:54 · 360 阅读 · 0 评论 -
【51Nod - 1279】 扔盘子(思维)(on-p会超时)
题干:有一口井,井的高度为N,每隔1个单位它的宽度有变化。现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,则圆盘被卡住(恰好等于的话会下去)。盘子有几种命运:1、掉到井底。2、被卡住。3、落到别的盘子上方。盘子的高度也是单位高度。给定井的宽度和每个盘子的宽度,求最终落到井内的盘子数量。 如图井和盘子信息如下:井:5 6 4 3 6 2 3盘子:2...原创 2018-08-05 15:56:42 · 254 阅读 · 0 评论 -
【HihoCoder - 1881】特殊任务 (树形图,遍历)
题干:H公司一共有N名员工,编号1~N,其中CEO是1号员工。除了CEO之外,其他员工都有唯一的直接上司,所以N名员工上下级关系恰好形成了一棵树形结构。 我们知道每一名员工向H公司的代码库贡献了多少行代码。具体来说,第i名员工贡献了Ai行代码。现在有一项特殊的任务需要2名员工完成,这两名员工需要满足:1. 其中一名是另一名的直接或者间接上司2. 两人贡献代码行数的差值越大越好...原创 2018-11-19 15:13:52 · 324 阅读 · 0 评论 -
【POJ - 3347 】Kadj Squares (计算几何,思维 或 扫描线)
题干:In this problem, you are given a sequence S1, S2, ..., Sn of squares of different sizes. The sides of the squares are integer numbers. We locate the squares on the positive x-y quarter of the pla...原创 2018-10-30 22:03:02 · 364 阅读 · 0 评论 -
【HDU - 4217 】Data Structure? (线段树求第k小数)
题干:Data structure is one of the basic skills for Computer Science students, which is a particular way of storing and organizing data in a computer so that it can be used efficiently. Today let me in...原创 2018-09-06 18:16:20 · 374 阅读 · 0 评论 -
*【CodeForces - 799C】Fountains (线段树 或 树状数组,类似二元组问题)
题干:Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There arenavailable fountains, for each fountain its beauty and cost are known. There are two types of money in the gam...原创 2018-09-09 01:14:45 · 571 阅读 · 2 评论 -
jsk Star War (线段树维护区间最小最大值 + 二分)
Description公元20XX年,人类与外星人之间的大战终于爆发。现有一个人类军团,由n名士兵组成,第i个士兵的战斗力值对应一个非负整数ai (1 \leq i \leq n1≤i≤n)。有一天,某个战力爆表的外星人NaN单独向地球人宣战,已知它的战力值为k (1 \leq k \leq 1e131≤k≤1e13)。现在该军团指挥官决定派遣编号在某个区间(l,r)内的士兵去与敌方决...原创 2018-10-27 00:54:33 · 236 阅读 · 0 评论 -
【HDU - 4509】湫湫系列故事——减肥记II(合并区间模板 or 离散化标记 or 线段树)
题干:虽然制定了减肥食谱,但是湫湫显然克制不住吃货的本能,根本没有按照食谱行动! 于是,结果显而易见… 但是没有什么能难倒高智商美女湫湫的,她决定另寻对策——吃没关系,咱吃进去再运动运动消耗掉不就好了? 湫湫在内心咆哮:“我真是天才啊~\(≧▽≦)/~” 可是,大家要知道,过年回家多忙啊——帮忙家里做大扫除,看电影,看小说,高中同学聚餐,初中同学聚餐,小学同学聚餐,吃东西,睡觉,吃东西...原创 2018-07-14 15:59:52 · 249 阅读 · 0 评论