Cutting Bamboos(牛客多校第九场H主席树+二分+思维)
鏈接:https://ac.nowcoder.com/acm/contest/889/H
來源:牛客網
There are n bamboos arranged in a line. The i-th bamboo from the left has height h_{i}h
i
?
.
You are given q queries of the type (l, r, x, y). For each query (l, r, x, y) we consider only the l-th to r-th bamboo inclusive. We want to make y horizontal cuts through these bamboos, such that after each cut, the total length of bamboo cut is the same, and after all y cuts there is no bamboo left. For example, if there are 3 bamboos of height 3, 4, 5 respectively and y = 4. The first cut should be at height 3, after which the heights of the bamboos are 3, 3, 3 respectively and the total amount of bamboo cut is 0 + 1 + 2 = 3. Then, the next 3 cuts should be at height 2, 1, 0 respectively. You want to find out what is the height the x-th cut is performed.
Note that after each query, the bamboos are not actually cut, so the heights of the bamboos remain constant after each query.
輸入描述:
The first line of input contains two space-separated integers n, q (1 <= n <= 200000, 1 <= q <= 100000).
The next line of input contains n space-separated integers, the i-th of which denotes hi, the height of the i-th bamboo (1 <= hi <= 100000).
The next q lines of input contains 4 space-separated integers each, denoting l, r, x, y (1 <= l <= r <= n, 1 <= x <= y <= 109).
輸出描述:
Output q lines of real numbers, the i-th line contains the answer to the i-th query. Your answer will be accepted if its absolute or relative error is less than 10-6.
示例1
輸入
復制
5 4
3 5 1 7 4
2 4 3 5
1 4 4 9
1 3 1999 101111
2 2 1 1
輸出
復制
2.100000005215406
2.629629638046026
4.822066854685545
0.000000026077032
說明
For the first query, we only consider the bamboos of height 5, 1, 7.
The first cut should be at height 4.7, the total amount of bamboo obtained is 0.3 + 0 + 2.3 = 2.6.
The second cut should be at height 3.4, the total amount of bamboo obtained is 1.3 + 0 + 1.3 = 2.6.
The third cut should be at height 2.1, the total amount of bamboo obtained is 1.3 + 0 + 1.3 = 2.6.
The fourth cut should be at height 13/15, the total amount of bamboo obtained is 37/30 + 2/15 + 37/30 = 2.6.
The fifth cut should be at height 0, the total amount of bamboo obtained is 13/15 + 13/15 + 13/15 = 2.6.
Note that the output values are not exact, but are within the precision requirements.
題意:有n棵樹,每棵樹有高度hi。有m次操作,每次要從l到r砍樹,每次砍相同的總高度,砍y次砍完。問砍到第x次的時候該砍哪兒。
看到l到r,不自覺的就想到線段樹,主席樹等等。
對于l到r區間內的樹,總高度我們是知道的,求一個前綴就可以求出來。砍y次砍完,那么我們每一次砍樹的總高度我們是知道的。砍掉x次之后剩余的樹的總高度我們也是可以求出來的。第x次該砍哪兒,我們二分去找這個高度。找出來之后,我們可以求出來低于這個高度的樹的數量和總高度(主席樹),那么我們就能求出來根據這個高度求出砍完之后剩余的樹高度,我們可以去和標準的答案去比較。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Cutting Bamboos(牛客多校第九场H主席树+二分+思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: All men are brothers
- 下一篇: Super Mario HDU - 44