1. 程式人生 > >ACM-ICPC Beijing 2016 Genius ACM(二分+倍增)

ACM-ICPC Beijing 2016 Genius ACM(二分+倍增)

---恢復內容開始---

描述

給定一個整數 M,對於任意一個整數集合 S,定義“校驗值”如下:

從集合 S 中取出 M 對數(即 2∗M 個數,不能重複使用集合中的數,如果 S 中的整 數不夠 M 對,則取到不能取為止),使得“每對數的差的平方”之和最大,這個最大值 就稱為集合 S 的“校驗值”。

現在給定一個長度為 N 的數列 A 以及一個整數 T。我們要把 A 分成若干段,使得 每一段的“校驗值”都不超過 T。求最少需要分成幾段。

Advanced CPU Manufacturer (ACM) is one of the best CPU manufacturer in the world. Every day, they manufacture n CPU chips and sell them all over the world.

As you may know, each batch of CPU chips must pass a quality test by the QC department before they can be sold. The testing procedure is as follows:

1) Randomly pick m pairs of CPU chips from the batch of chips (If there are less than 2m CPU chips in the batch of chips, pick as many pairs as possible.)

2) For each pair, measure the Relative Performance Difference (RPD) between the two CPU chips. Let Di be the RPD of the i-th pair

3) Calculate the Sqared Performance Difference (SPD) of the batch according to the following formula:

SPD=∑Di2

If there are only 1 CPU in a batch, then the SPD of that batch is 0.

4) The batch of chips pass the test if and only if SPD≤k, where k is a preseted constant

Usually they send all the n CPU chips as a single batch to the QC department every day. As one of the best CPU manufacturer in the world, ACM never fail the test. However, with the continuous improvement of CPU performance, they find that they are at risk!

Of course they don't want to take any risks. So they make a decision to divide the n chips into several batches to ensure all of them pass the test. What’s more, each batch should be a continuous subsequence of their productions, otherwise the QC department will notice that they are cheating. Quality tests need time and money, so they want to minimize the number of batches.

Given the absolute performance of the n chips P1 ... Pn mesured by ACM in order of manufacture, your task is to determine the minimum number of batches to ensure that all chips pass the test. The RPD of two CPU chips equals to the difference of their absolute performance.

輸入格式

The first line contains a single integer T, indicating the number of test cases.

In each test case, the first line contains three integers n, m, k. The second line contains n integers, P1 ... Pn.

輸出格式

For each test case, print the answer in a single line.

樣例輸入

2
5 1 49
8 2 1 7 9
5 1 64
8 2 1 7 9

樣例輸出

2
1

資料範圍與約定

  • T≤12
  • 1≤n,m≤5e5
  • 0≤k≤1e18
  • 0≤Pi≤2e20

 

思路:

①暴力列舉,列舉每個sum <= T的最大位置, Σ(ilogi) ≈  O(n²logn)

②二分      如果每次都只是向右擴充套件一位,那麼二分的複雜度將會比列舉要高  O(n²log²n)

③倍增+二分   我們讓其快速增長,過頭後,快速下降。     (二分+倍增 logn、排序校驗nlogn)    O(nlog²n)

 

 

 

---恢復內容結束---