Summary of Line Segment tree questions

Source: Internet
Author: User
Tags ranges

I. Single Point update

1. hdu1166 enemy army deployment: There are n barracks, each of which provides the number of AI (subscript starts from 1), there are four commands, (1) "addij ", add J members to camp I. (2) "sub I j" indicates that J people are reduced in camp I. (3) "query IJ": queries the total number of people from camp I to Camp J. (4) "end" indicates that the command has ended. Solution report here.

2. hdu1754 I hate it: give you n numbers, M operations, and operations in two categories. (1) "QAB", the maximum value in the query interval [a, B. (2) "UAB", change the number of A to B. Solution report here.

3. hdu1394minimum inversion number: give you n numbers, and count the minimum values of all forms of Reverse Order pairs. It means that the first number starting with the array is placed at the end of the array. Solution report here.

4. hdu2795 billboard: There is a board, the specification is H * W, and then there are n posters, each of which is 1 * WI, select the position of the poster: as high as possible, for the same height, select the place to the left as far as possible. The height of each poster must be output. Solution report here.

5. poj2828 buytickets: There are n people in the queue. Each person has a Val, and each person who comes later inserts a position POS of the current team. Output the final status of the team. Solution report here.

6. poj2886 who getsthe Most candies? : N Children in a circle are numbered 1 to n clockwise. Each child has a card with a non-zero number on it. The game starts from the K child and he tells other children the number on his card and leaves the circle, the number A on his card indicates that the next child leaves. If a is greater than 0, the next child leaves is the first child on the left side. If a is less than 0, it is the first child on the right hand side. The game will continue until all the children leave. In the game, the children who leave P will get f (p) candy, and f (p) is the approximate number of P, ask who will get the most candy. Output The Name Of The lucky child and the candy he can get. Solution report here.

7. hdu4288 coder & CF85-DSum of medians: There are three types of actions, (1). "add X", indicating to add number X to the set. (2). "del X" indicates to delete the number X in the set. (3). "sum" is used to obtain the sum of the numbers in the subscripts of the Set in ascending order. The number in the set is unique. Solution report here.

8. codeforcesbeta round #19 D. points: There are three operations: Add x y to add the (x, y) point to the plane, "remove x y", to add existing points (x, y) on the plane) delete. Find x y to find the point with the coordinate strictly greater than (x, y) on the plane. If multiple points have the smallest X, find the smallest y. Solution report here.

9. poj2481 cows: There is an nheaded ox, and each ox has a test value [s, E]. If for ox I and ox J, when their test values meet the following conditions, it proves that Niu I is stronger than Niu J: Si <= sjand j <= EI and EI-Si> ej-SJ. It is now known that each cow's test value is required to output the number of cows per cow to be stronger than its own. Solution report here.

10. hdu3950 parking log: There are T groups of test data. N and Q of each group of data indicate N locations in the parking lot (subscript starts from 1) and Q Operations respectively. There are two types of operations: (1) "a m l r", indicating that this fleet has m vehicles. If the front is vacant, the distance between the front and the front is not more than l, if there is a car in the back end, the distance between the car and the back end must not exceed R. If there is no car in the front or back end, the restrictions of condition L and R are ignored. If a subscript of the start point is output at a location that meets the conditions, if there are multiple positions that meet the condition and the output subscript is the smallest, if the condition is not met, the output is-1. (2) "BK" indicates that K teams are left to the right. Solution report here.

11. hdu4521 Xiao Ming series problems-Xiao Ming sequence: there are multiple groups of test data, N and D of each group of data, there are n numbers, find the longest ascending sequence with spacing greater than D. Solution report here.

12. codeforcesbeta round #99 (div. 1) C mushroom gnomes-2: There are n trees and M mushrooms. Each tree has coordinates a, height h, and the probability of inverted to the left, probability to the right (probability is represented by 0-), the mushroom in the descending left range [X-h, x) is destroyed, and the inverted right range (X, mushrooms in the x + H] range are damaged. Each mushroom has coordinate B and its magic value Z. Solution report here.

13. HDU 4605 Magic Ball Game: An X ball falls from the root node. Every time it falls into a node, 1. if X = W [I] or no son node exists, the ball stops dropping. 2. If x <W [I], each ball has a 1/2 probability of falling to the left and right son nodes. 3. If x> W [I], 1/8 of the ball's probability falls to the left son, and 7/8 of the probability falls to the right son. Ask the probability of the ball falling to point V (the probability is expressed by 7 ^ X/2 ^ y, that is, output X and Y ). Solution report here.

14. ural 1989 subpalindromes: give you a string of N length, there are m operations, there are two types of operations (1) "change I a", which means to change the character I to, (2) "palindrome? J k ", ask whether the string of [j, k] constitutes a return string. Solution report here.

15. HDU 4777 rabbit kingdom: returns n numbers and has m queries. The number of [L, R] ranges is mutually correlated with other numbers in this interval. Solution report here.

Ii. segment update

A Simple Description: latency tags (or lazy tags) are required for segment update. in simple words, do not update the end of each update, the latency tag causes the update to be delayed until the next update or query is performed. The latency mark indicates that the Left and Right sons of this interval must be updated, but the current interval has been updated.

1. hdu1698 just a hook: Give You T group data, N number (the value of each number is 1 at the beginning), m operation, each operation interval [, the number in B] is updated to C, and the sum of the N is asked. Solution report here.

2. poj3468 A simpleproblem with integers: give you n numbers and then have m operations. There are two types of operations. (1) "ca B c" indicates adding the number in the range [a, B] to C. (2) "q a B" indicates the sum of the number of [a, B] in the query range. Solution report here.

3. poj2528 mayor's sposters: There are T groups of test data, there are n posters, the posters are covered in the order given by the question, and you can see several posters at last. Solution report here.

4. poj1436horizontally visible segments: (I do not understand this question ..)

5. poj2991 Crane: There are N poles. The first and second poles are connected by one node. Each node can rotate at a certain angle. Each operation (s, A) is given to you) the angle between S and S + 1 is changed to a degree, and the position of the nth node needs to be obtained after each operation. Solution report here.

6. uestc1425 another lcis: Contains T (t <10) groups of data, giving you n numbers and M operations (N and m are both less than 100000 ). There are two types of operations: (1) "q a B", the length of the longest continuous ascending sequence in the query interval [a, B. (2) "a l r v", increasing the number in the range [L, R] To v. Solution report here.

7. uestc1546 bracket sequence: a sequence of parentheses consisting of '(' or ')' with n characters. There are three operations (1) "set l r c ", change all elements in the range [L, R] to C, and C is one of '(' or. (2) "Reverse l r", indicating that the '(' and ')' in the range [L, R] is reversed. (3) "query l r" indicates whether the query interval [L, R] is a legal sequence of parentheses. Solution report here.

8. codeforcesround #136 (div. 2) d. little elephant andarray: For n m queries, the number of occurrences of valu in each [L, R] range is also valu. Solution report here. (This question can be used to update query points and single point update query ranges in segments)

9. ultraviolet A 12436 r0000an Winkle's code: for the interval with a length of 250000, you are given four operations: Operation A, number from St to Ed, add 1, 2 ,..., st-ed + 1. Operation B, the number in the range from St to Ed, plus, St-ed + 1, St-ed,..., 1, respectively. In operation C, assign the number from St to Ed to X. Operation S: queries the sum of the numbers in the range from St to Ed. Solution report here.

10. codeforcesround #169 (div. 2) E. little girl and problemon trees: a tree has n nodes, except for root node 1, the sum of the outbound and inbound degrees of other nodes is only 2 (that is, the tree is glued together by the first node of several links). Now there are two operations (1) "0 V x D": Add 1, (2) "1 V" to the weights of all nodes less than D to query the values of node v. Solution report here.

11. codeforcesbeta round #35 (div. 2) E. parade: give you the height of the roof of N buildings, the left coordinate l of the roof, and the right coordinate R (which can be regarded as a line segment) and ask the turning point of the outline of the whole building. Solution report here.

12. zoj3299 fall the Brick: There are n slice bricks, M boards, n columns of boundary L and R bricks falling from the sky, and then M boundary, b's height is H's wooden board to pick up those board tiles. If some board bricks in a row fall onto the board, it will stop falling, and the rest will continue to fall, ask the number of bricks on each board. Solution report here.

13. fzu2105 digits count: give you n numbers. There are four operations. (1) "andopnl R", indicating that all the numbers in the range [L, R] are connected to the UDF and the (&) operation is performed. (2) "or opn l r", indicating that all the numbers in the range [L, R] are operated by or (|. (3) "xor opn l r" indicates that all numbers in the interval [L, R] are operated differently or (^. (4) "sumopnl R", and obtain the sum of the numbers of [L, R. Solution report here.

14. HDU 4533 Wei cat series story-sun Quilt: give you n rectangles, each rectangle gives the coordinates in the lower left corner, the coordinates in the upper right corner, there are m inquiries, each query gives a time t, ask (), (t, t) the area of the rectangle within the range and (the overlap is also calculated ). Solution report here.

15. Ural 1855 trade guilds of erathia: There are n cities and M operations. The city forms a chain with subscripts ranging from 1 to n. a road is connected to an adjacent city, and the cost of passing through each road is 0. There are two types of operations: (1) "change a B d", which indicates that the cost of each road between City A and City B changes d (if D is greater than 0, increase, and vice versa ). (2) "establish a B" indicates that two cities from City A to City B are selected as the start and end points of the road, and the average cost of these roads is queried. Solution report here.

16. HDU 4578 Transformation: returns an array with an initial value of zero. There are four operations: (1) "1 x y c", representing the interval [x, all values on y] are added to C. (2) "2 x y c", which means to multiply all values in the range [x, y] by C. (3) "3 x y c" means to assign all values in the range [x, y] to C. (4) "4 x y p" represents the P subvertex and 1 <= P <= 3 in the result range [x, y. Solution report here.

17. HDU 4455 substrings: given an integer string, There Is a q group to ask the sum of the numbers in the substring with the length of W in this string. Solution report here.

18. HDU 4614 vases and flowers: Given a range [0, N-1], the numbers at each position are initially 0, there are two operations, 1. start searching for F at location a (if there are not so many, then there will be as many as). The value is 0 and the number at the position is changed to 1, return the location of the first and last changes. 2. query the number of 1 in the range [a, B] and change the number in each position of the range [a, B] to 0. Solution report here.

19. HDU 4747 Mex: give you n numbers, enumerate all L and R, and ask which number does not appear in the set composed of numbers in the range [L, R, if there are multiple, find the earliest one, set it to X, and calculate the sum of X. Solution report here.

20. zoj 3724 delivery: n vertices. For each vertex I, there is a directed edge directed to I + 1, and m other directed edges, there are Q queries (u, v) to find the nearest short circuit from u to v. Solution report here.

21. cf343d Water Tree: a tree has n nodes and has three operations (1) "1 V", indicating that all the Subtrees with point V as the root node are assigned 1, (2) "2 V" indicates that all the ancestor nodes of vertex v and vertex v are assigned 0, (3) "3 V", indicating the value of the query vertex v. Solution report here. Solution report here.

22. ural 1977 energy wall: There are n (n <10 ^ 9) points, P (P <10 ^ 5) operations, after each second, therefore, a value T is added to the number. Each operation has an operation time before it starts. The initial time is 0. There are two types of operations: (1) "save l r ", returns the sum of the numbers between the intervals [L, R], adds it to the tot, and clears [L, R] to zero. (2) "enforce I D ", it indicates that vertex I-d + 1 and vertex I + D-1 are added with the value x, and vertex I-d + 2 and vertex I + D-2 are added with the value 2 * x ...... In addition, the sum of X added to all numbers is equal to tot. After this operation, the tot is cleared. Solution report here.

3. Merge intervals

When you query an online segment tree, merge the Left and Right sons of the current range.

1. poj3667 Hotel: There are n rooms and M operations. There are two types of operations (1) "1A", indicating that an empty room with a continuous length of A is found. If there are multiple solutions, the left-side is given priority, indicating that the room is checked in. (2) "2 B len", clear the Len room with the B-length starting point, that is, check out. Solution report here.

2. hdu3308 lcis: give you n integers, there are two kinds of operations, (1) "u a B", indicates to change the number of A to B, "QAB ", indicates the longest continuous ascending sequence of the query range [a, B. Solution report here.

3. hdu3397 sequence operation: There are N 0 or 1 numbers, M operations, and 5 types of operations. (1) "0 a B" indicates that all the numbers in the range [a, B] are set to 0. (2) "1 a B" indicates that all the numbers in the range [a, B] are set to 1. (3) "2 a B" indicates that the number 0 in the range [a, B] is changed to 1, 1 and 0. (4) "3AB" indicates the number of 1 in the range of [a, B. (5) "4 a B" indicates the longest continuous 1 in the range of [a, B. Solution report here.

4. hdu2871 memory control: Give N Units of memory (number starts from 1), there are four operations, (1) "reset", indicates to clear all the memory, then output "Reset now ". (2) "new x" indicates applying for a memory block with a length of X (for example, multiple solutions, priority on the left side), and then outputting "New at ", a Indicates the starting point of the memory block. (3) "free X" indicates to clear the memory block containing the X block unit memory, and then output "free from a TOB ", A and B indicate the start point and end point of the memory block (4) "Get X", respectively, indicating that the start memory unit number of the memory block X is returned, then output "get at ". Solution report here.

5. hdu1540 tunnel Warfare: There are n villages in a straight line. Each village connects two villages (except the leftmost and rightmost). There are three operations, (1) "d x" indicates the destruction of the village X. (2) "QX" indicates the number of villages directly and indirectly connected to village X. (3) "R" indicates restoring the village that was first destroyed. Solution report here.

6. codeforcesbeta round #43 d. parking lot: There is a street with a length of L, there are N operations, there are two kinds of operations, (1) "1 ", A car with a length of a needs to drive in and find a parking space. The parking space must be at least B from its front and at least F from its rear. if such a parking space can be found, output the starting position of the car (and the location is the smallest), otherwise output-1. (2) "2 A", indicating that the car that came in and parked in the event a was taken out. Solution report here.

Iv. Scanning line

1. hdu1542 Atlanta: give you n rectangles. Each rectangle is given the coordinates in the lower left corner and in the upper right corner. End with n = 0. You need to find the area after the rectangle. Solution report here.

2. hdu1828 picture & poj 1177 picture: give you n rectangles. Each rectangle is given the coordinates in the lower left corner. The coordinates in the upper right corner require the rectangle and the perimeter. Solution report here.

3. area covered by hdu1255: There are T groups of test data. Each group of data is given a number n first. In the next n rows, four floating point numbers in each row represent the coordinates in the upper left corner and the lower right corner of the rectangle, it is required that these rectangles cover at least two areas. Solution report here.

4. HDU 3642get the Treasury: There is t for the test data, each group of data first gives a number N, and in the next n rows, there are 6 numbers in each row, respectively X1, Y1, Z1, x2, Y2, Z2, indicates that the X-axis direction of the cuboid ranges from X1 to X2. The Y coordinate is similar to the zcoordinate, and the volume of the intersection of at least three cuboid is determined. Solution report here.

5. poj2482 stars inyour window: give you the coordinates of the stars within 10000 and the brightness of the Stars (X, Y, C, respectively). You must enclose an area with a rectangle of W * H, this maximizes the brightness of the stars in this area, and requires that the stars on the border of the rectangle be excluded. The rectangle can be translated but cannot be rotated. Solution report here. (PS: The question is very good ~)

6. poj2464 browniepoints II: Give You N points in the Cartesian coordinate system of the plane. Stan and Ollie play a game. First, Stan draw a straight line in the vertical direction, this straight line must pass through a certain point, and then Ollie draws a straight line in the horizontal direction. The requirement of this straight line is the point drawn before a Stan. At this time, the plane is divided into four parts. At this time, two people will have a score, and Stan's score is the number of points in the 1st and 3 quadrant planes, the Ollie score is the number of points in the 2nd and 4 quadrants on the plane. The points on the drawn line are not counted. Find the final Stan to make his worst score the highest, and output the Ollie score at this time. Solution report here.

7. hdu3255 farming: There are n farmland, one type of crop in each farmland, each of which has a price. When two different crops are planted in the same region, when the price of crops is high, the cost of crops is small. Find the total amount of money that can be bought for all the final crops. Solution report here.

8. Ultraviolet A 11983 weirdadvertisement: N rectangles are given, and the area of these rectangles that overwrite more than K times is obtained. Solution report here.

9. hdu4052 adding new machine: Give You A w x H rectangle, n of which are not available (given the coordinates of the two vertices in this region (x1, Y1) and (X2, Y2. Solution report here.

10. uestc1525 Fruit Ninja: There are T groups of test data, N, H, W of each group of data indicates there are n bombs or fruits, H and W indicate the length and width of the plate for "cutting" the fruit. W must be parallel to the X axis, and H must be parallel to the Y axis. Ask how many fruits can be taken when a board of bricks goes down (requires no bombs, ask how many fruit shooting schemes are available for panel tiles (that is, if the four sides of the Panel tiles are "sacrificed", calculate the number one; otherwise, the Panel tiles can be moved, the number of solutions is so far !). Solution report here.

11. hdu4419 colourful rectangle: it gives you 10000 rectangles of three colors. Different rectangles of different colors form different colors. Ask the area of the seven colors. Solution report here.

12. zoj 3521 fairy wars: There are n bullets on the plane. The coordinates of each bullet are known. Now, in the circle with the distance x0 and Y0 as R, so all bullets will become ice cubes L * l, and all other bullets in the L * l range will also become ice cubes. Q: When the chain reaction ends, the number of bullets that turn into ice cubes. Solution report here.
13. zoj 3525 disappearance: There are N points (n <5000) in a three-dimensional space. It is required to use a cuboid LB * LW * LH to enclose some points, this minimizes the weights and values of vertices in a long body. Solution report here.


V. Others

1. hdu3954 level up: There are n heroes. Each hero has an initial level of 1, an initial experience of 0, K levels, and QW operations. The next row has a K-1 value, which indicates that it is upgraded to level 2, level 3 ...... Experience. In the next QW row, each row is an operation. There are two types of operations: (1) "l r e", representing the interval [L, r. (2) "LR" indicates the maximum empirical value in the query range [L, R. Solution report here.

2. hdu4027 can you answer these queries? : N number, M operation, and operation. (1) "0 l r" indicates that each number in the range [L, R] is rooted. (2) "1 l r" indicates the sum of all numbers in the query interval [L, R. Solution report here.

3. hdu3333turing Tree & hdu3874neck.pdf: Contains T groups of data. Each data is given n numbers and Q queries. Each query requires the sum of numbers between [L, R, however, a value that appears multiple times can only appear once. Solution report here.

4. hdu3016 man down: There are n boards, each of which has four properties, high H (h> 0), left border XL, Right Border XR, and drop on it, how much life value (which may be negative) is obtained. A person jumps down from the highest wooden board. The initial life value is 100, ask the maximum number of lifecycles that can be obtained after the last drop to the ground (if the life is 0, the person will die). If the person cannot jump to the ground, output-1. Solution report here.

5. hdu3340 rain in acstar: A number of images (three sides, four sides, and pentagons) are dropped in the sky to calculate the area and. Solution report here.

6. zoj3511 cake robbery: There is a n Convex Edge, numbered 1 to n clockwise, M knife is cut along the diagonal line, to ensure that any two knives do not intersection (except the endpoint ), ask the maximum number of edges of the convex polygon in the process of cutting the M-knife. Solution report here.

7. uestc1558 charitable exchange: star starts to have 1 yuan of things, there are n kinds of transactions, each type of transaction VI, RI, Ti means to use at least Ri things to get VI things, this process requires ti. Ask how long it takes to get at least m yuan. Solution report here.

8. spojgss21557 canyou answer these queries II, for each query, the maximum subinterval in the interval [x, y] is the sum, and the repeated values can only be calculated once (if it is a negative number, the output is 0, that is, the subinterval can be null ). Solution report here.

9. poj1_2 walkingrace: give you a tree with N nodes. The edge of the tree is the weight value. You need to find the maximum distance from each point on the tree to other points. Find the longest segment from node 1 to the maximum node N value so that the node with the maximum and minimum values in this segment is less than or equal to M. Solution report here.

10. hdu4358 boring counting: Give You A tree. Each node on the tree has a tree value. Give m a query and ask how many types of weights appear exactly K times under the tree rooted at each vertex u. Solution report here.

11. hdu1_7 a simple problem with integers: two operations are provided for you. (1) "1 A B k c" indicates that the position within the range [a, B] is satisfied (I-) % K = 0 plus C, and K ranges from 1 to 10. (2) "2 A" indicates the number of A queries. Solution report here. (Tree array is used in the solution report)

12. hdu4417 Super Mario: give you n numbers and M queries. For a query, ask how many numbers smaller than C in the range of [a, B. Solution report here. (Tree array is used in the solution report)

13. uvalive4730 kingdom: on a two-dimensional coordinate plane, there are n cities and M operations. There are two types of operations: (1) (1) "Road a B ", it means connecting city a and City B through a road. If A and B were originally different urban agglomerations, after this operation, A and B would be in the same urban agglomeration, ensure that each road does not meet other roads (except endpoints A and B ). (2) "linec" indicates the number of urban agglomerations and the total number of cities in these urban groups when the Y = C line is crossed. Solution report here.

14. codeforcesround #163 (Div. 2) E. More queries toarray. (1) "= L rk", which means to change the number of [L, R] to K. (2 )"? L rk ", in the range of the query range [L, R], the sum of K in the formula ai * (I-l + 1) ^ K. Solution report here.

15. HDU 4638 group: 1 ~ The number of consecutive segments in the interval [L, R. For example, if there are five numbers in the range: 3, 1, 2, 5, and 6, then there are three, 1, 2, and 5, and 6. Solution report here.

16. HDU 4630 no pain no game: Give an arrangement of N and 1 to n, ask Q times, and pick any two numbers in each query [L, R, what is the maximum value of the maximum common appointment. Solution report here.





Summary of Line Segment tree questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.