
树状数组and线段树
文章平均质量分 77
vocaloid01
小菜鸟一只_(:з」∠)_前来膜拜各路大佬orz
展开
-
HDU-6273 Master of GCD(思维,线段树)
题意:输入T组数据,每组数据有n个数,m个操作,下面有m行,每行有三个数,前两个为区间,把这个区间中每个数都乘以第三个数(只会是 2,3)求最后这n个数的最大公约数,刚开始这n个数都是1 。题解:记录每个数乘上的2和3的数量,结果就是最少数量的2和最少数量的3的乘积。代码:#include <cstdio>#include <algorithm>...原创 2018-10-11 19:57:38 · 362 阅读 · 0 评论 -
ACM-ICPC 2018 徐州赛区网络预赛 G 题 Trace
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( x , y ) means the wave is a rectangle whose vertexes are ( 0 , 0 ), ( x , 0 ), ( 0 , y ), ( x , y ). Every t...原创 2018-09-11 15:48:34 · 351 阅读 · 0 评论 -
HDU - 5877 Weak Pair (DFS+二分+树状数组+离散化)
You are given a rooted tree of N nodes, labeled from 1 to N. To the ith node a non-negative value ai is assigned.An ordered pair of nodes (u,v) is said to be weak if (1) u is an ancestor of v (Note:...原创 2018-08-31 15:19:10 · 156 阅读 · 0 评论 -
POJ - 3368 Frequent values(线段树区间合并求区间内最长连续子串的长度模板题)
You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each query, det...原创 2018-08-27 16:09:10 · 285 阅读 · 0 评论 -
POJ - 1195 Mobile phones (二维树状数组求区间和)
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbe...原创 2018-07-29 10:21:15 · 200 阅读 · 0 评论 -
POJ - 2155 Matrix (二维树状数组入门)
Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <= i, j <= N).We can change the matrix in the...原创 2018-07-28 19:38:14 · 137 阅读 · 0 评论 -
hdu-4578-Transformation-线段树(区间更新区间求和,多lazy,绝世好题)
Time limit 8000 msMemory limit 65536 kB Yuanfang is puzzled with the question below: There are n integers, a 1, a 2, …, a n. The initial values of th...原创 2018-06-01 15:56:02 · 519 阅读 · 0 评论 -
HDU4027——Can you answer these queries? (线段树区间更新求和+开根减枝+坑)
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of end...原创 2018-05-29 19:52:30 · 341 阅读 · 0 评论 -
hdu4614——Vases and Flowers
Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N-1. When she receive some flowers, she will try to put them in the vases, one flower in one vase. Sh...原创 2018-05-29 16:40:57 · 211 阅读 · 0 评论 -
POJ2528——Mayor's posters (线段树区间更新查询+离散化)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally d...原创 2018-05-28 18:54:15 · 297 阅读 · 2 评论 -
ZOJ1610——Count the Colors (区间染色+暴力)
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can see at las...原创 2018-05-17 15:01:07 · 290 阅读 · 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. Except t...原创 2018-05-17 11:05:04 · 166 阅读 · 0 评论 -
hdu3911——Black And White (线段树区间合并)
Time limit3000 msMemory limit32768 kBThere are a bunch of stones on the beach; Stone color is white or black. Little Sheep has a magic brush, she can change the color of a continuous stone, black to w...原创 2018-05-16 18:57:10 · 230 阅读 · 0 评论 -
POJ3264——Balanced Lineup(线段树查询区间最大最小值)
Time limit5000 msCase time limit2000 msMemory limit65536 kBFor the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game...原创 2018-05-15 21:46:22 · 158 阅读 · 0 评论 -
HDU1698——Just a Hook(线段树区间修改,区间求和)
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.Now Pudge wan...原创 2018-05-15 20:36:15 · 233 阅读 · 0 评论 -
POJ3468——A Simple Problem with Integers (线段树区间加值,区间求和)
Time limit5000 msCase time limit2000 msMemory limit131072 kBYou 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 e...原创 2018-05-15 20:13:26 · 142 阅读 · 0 评论 -
HDU - 5023——A Corrupt Mayor's Performance Art(线段树+位运算压缩)
Time limit1000 msMemory limit100000 kBCorrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on ...原创 2018-05-14 21:02:43 · 119 阅读 · 0 评论 -
线段树模板
首先是建树:const int MAXN = 1005;//定义 MAXM 为线段最大长度int Tree[4*MAXN];// Data数组为 main 函数中读入的内容,Tree数组为需要查询的数的信息(如和、最值等),树的空间大小为线段最大长度的四倍!四倍!四倍! int Data[MAXN];void Build(int temp,int left,int right){//传入...原创 2018-05-14 19:33:04 · 332 阅读 · 0 评论 -
HDU 1754 I Hate It (数组实现线段树)
很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。 这让很多学生很反感。 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。 在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200000,0<M<5000 ),分...原创 2018-04-12 18:50:38 · 211 阅读 · 0 评论 -
Ultra-QuickSort (树状数组求逆序数)
In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in原创 2018-01-21 20:41:26 · 216 阅读 · 0 评论 -
敌兵布阵 (树状数组and线段树入门)
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所...原创 2018-01-20 17:42:36 · 178 阅读 · 0 评论 -
树状数组模板
#include &amp;amp;amp;amp;amp;lt;iostream&amp;amp;amp;amp;amp;gt;#include &amp;amp;amp;amp;amp;lt;cstdio&amp;amp;amp;amp;amp;gt;#include &amp;amp;amp;amp;amp;lt;cstring&amp;amp;amp;amp;amp;gt;#include &原创 2018-01-20 17:15:56 · 167 阅读 · 0 评论 -
加农炮 51Nod - 1287(线段树)
一个长度为M的正整数数组A,表示从左向右的地形高度。测试一种加农炮,炮弹平行于地面从左向右飞行,高度为H,如果某处地形的高度大于等于炮弹飞行的高度H(Ai >= H),炮弹会被挡住并落在i - 1处,则Ai−1 + 1。如果H 所有的Ai,这个炮弹也无效。现在给定N个整数的数组B代表炮弹高度,计算出最后地形的样子。例如:地形高度A = {1, 2, 0, 4, 3, 2, 1, 5,原创 2017-08-14 19:35:08 · 327 阅读 · 0 评论 -
HDU.2795 Billboard
在学校的入口处有一个巨大的矩形广告牌,高为h,宽为w。所有种类的广告都可以贴,比如ACM的广告啊,还有餐厅新出了哪些好吃的,等等。。 在9月1号这天,广告牌是空的,之后广告会被一条一条的依次贴上去。 每张广告都是高度为1宽度为wi的细长的矩形纸条。 贴广告的人总是会优先选择最上面的位置来帖,而且在所有最上面的可能位置中,他会选择最左面的位置,而且不能把已经贴好的原创 2017-08-11 15:59:09 · 219 阅读 · 0 评论 -
HDU1556 color the ball(前缀和)
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?Input:每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a原创 2017-08-08 18:19:19 · 392 阅读 · 0 评论