Contest Hunter 0601 Genius ACM
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.
Input
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.
T≤12
1≤n,m≤5×105
0≤k≤1018
0≤Pi≤220
Output
For each test case, print the answer in a single line.
Sample Input
2
5 1 49
8 2 1 7 9
5 1 64
8 2 1 7 9
Sample Output
2
1
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
//#include<queue>
//#include<set>
#define INF 0x3f3f3f3f
#define N 500005
#define re register
#define Ii inline int
#define Il inline long long
#define Iv inline void
#define Ib inline bool
#define Id inline double
#define ll long long
#define Fill(a,b) memset(a,b,sizeof(a))
#define R(a,b,c) for(register int a=b;a<=c;++a)
#define nR(a,b,c) for(register int a=b;a>=c;--a)
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
#define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
#define D_e(x) printf("\n&__ %d __&\n",x)
#define D_e_Line printf("-----------------\n")
#define D_e_Matrix for(re int i=1;i<=n;++i){for(re int j=1;j<=m;++j)printf("%d ",g[i][j]);putchar('\n');}
using namespace std;
Il read(){
ll s=,f=;char c;
for(c=getchar();c>''||c<'';c=getchar())if(c=='-')f=-;
while(c>=''&&c<='')s=s*+(c^''),c=getchar();
return s*f;
}
Iv print(int x){
if(x<)putchar('-'),x=-x;
if(x>)print(x/);
putchar(x%^'');
}
/*
Iv Count_Sort(int arr[]){
int k=0;
R(i,1,n)
++tot[arr[i]],Cmax(mx,a[i]);
R(j,0,mx)
while(tot[j])
arr[++k]=j,--tot[j];
}
Iv Merge_Sort(int arr[],int left,int right,int &sum){
if(left>=right)return;
int mid=left+right>>1;
Merge_Sort(arr,left,mid,sum),Merge_Sort(arr,mid+1,right,sum);
int i=left,j=mid+1,k=left;
while(i<=mid&&j<=right)
arr[i]<=arr[j]?
tmp[k++]=arr[i++]:
tmp[k++]=arr[j++],sum+=mid-i+1;//Sum Is Used To Count The Reverse Alignment
while(i<=mid)tmp[k++]=arr[i++];
while(j<=right)tmp[k++]=arr[j++];
R(i,left,right)arr[i]=tmp[i];
}
Iv Bucket_Sort(int arr[],int left,int right){
int mx=0;
R(i,left,right)
Cmax(mx,arr[i]),++tot[arr[i]];
++mx;
while(mx--)
while(tot[mx]--)
arr[right--]=mx;
}
*/
int n,m;
ll maximum,a[N],tmp[N],tmp_2[N];
Ib Jud(int l,int rp,int r){
ll sum=;
R(i,rp+,r)tmp[i]=a[i];
sort(tmp+rp+,tmp+r+);
merge(tmp+l,tmp+rp+,tmp+rp+,tmp+r+,tmp_2+l);
R(i,l,Min(l+r>>,m+l-)){
sum+=(tmp_2[i]-tmp_2[l+r-i])*(tmp_2[i]-tmp_2[l+r-i]);
if(sum>maximum)return ;
}
if(sum<=maximum){
R(i,l,r)
tmp[i]=tmp_2[i];
return ;
}
return ;
}
#define Outprint(x) print(x),putchar('\n')
int main(){
int Test=read();
while(Test--){
int ans=,l=;
n=read(),m=read(),maximum=read();
R(i,,n)
a[i]=read();
tmp[]=a[];
while(l<=n){
int r=l,mov=;//mov-> move step
while(mov)
(r+mov<=n&&Jud(l,r,r+mov))?
r+=mov,mov<<=:
mov>>=;
l=r+,++ans;
}
Outprint(ans);
}
return ;
}
Contest Hunter 0601 Genius ACM的更多相关文章
- CH0601 Genius ACM【倍增】【归并排序】
0601 Genius ACM 0x00「基本算法」例题 描述 给定一个整数 M,对于任意一个整数集合 S,定义“校验值”如下: 从集合 S 中取出 M 对数(即 2∗M 个数,不能重复使用集合中的数 ...
- hihocoder--1384 -- Genius ACM (倍增 归并)
题目链接 1384 -- Genius ACM 给定一个整数 m,对于任意一个整数集合 S,定义“校验值”如下:从集合 S 中取出 m 对数(即 2*M 个数,不能重复使用集合中的数,如果 S 中的整 ...
- Contest Hunter 3101
题目 Contest Hunter 3101 阶乘分解 原题传送门 题目分析 这里介绍一个本蒟蒻自己\(yy\)出来的方法. 我们发现,对于某一个单个的整数\(n\),若\(n\)能被某一个数\(x\ ...
- ACM-ICPC Beijing 2016 Genius ACM(倍增+二分)
描述 给定一个整数 M,对于任意一个整数集合 S,定义“校验值”如下: 从集合 S 中取出 M 对数(即 2∗M 个数,不能重复使用集合中的数,如果 S 中的整 数不够 M 对,则取到不能取为止),使 ...
- 【Contest Hunter【弱省胡策】Round #0-Flower Dance】组合数学+DP
题目链接: http://ch.ezoj.tk/contest/%E3%80%90%E5%BC%B1%E7%9C%81%E8%83%A1%E7%AD%96%E3%80%91Round%20%230/F ...
- [Contest Hunter#17-C] 舞动的夜晚
[题目链接] http://contest-hunter.org:83/contest/CH%20Round%20%2317/%E8%88%9E%E5%8A%A8%E7%9A%84%E5%A4%9C% ...
- hihoCoder#1384 : Genius ACM
对于一个固定的区间$[l,r]$,显然只要将里面的数字从小到大排序后将最小的$m$个和最大的$m$个配对即可. 如果固定左端点,那么随着右端点的右移,$SPD$值单调不降,所以尽量把右端点往右移,贪心 ...
- Contest Hunter Round #70 - 连续两大交易事件杯省选模拟赛
orz lydrainbowcat [Problem A]「艦これ市」70万幕后交易事件 排序机器=-=.重要的是相同的处理. 我们可以从小到大添加数字,然后维护一个位置的序列.每一种相等的数字都在一 ...
- 【Contest Hunter 5302】金字塔
[原题链接]传送门 [题解思路] 1.考虑如何将序列与树相对应,想到类似dfs序和欧拉序,同一个子树对应序列连续 2.暴力分子树过于复杂,考虑简化(划重点: 若当前区间为[l,r],考虑第一颗子树所在 ...
随机推荐
- Linux常用基本命令 1
useradd 创建用户. password 修改密码. date 查看时间 man date 帮助文档.f往后翻 b往前翻 q退出.软修改 man hwclock 修改硬件时钟, cal 查看日历 ...
- java代理模式与装饰者模式
静态代理和装饰者模式的区别: 先来看一下装饰者模式的定义:装饰者模式动态地将责任附加到对象上.若要扩展功能,装饰者提供了比继承更有弹性的替代方案. 总结一下采用装饰者模式是为了增强或拓展原对象的功能. ...
- apt-get update 时的问题 W:Failed to fetch gzip:/var/lib/apt/lists/partial...解决办法
http://askubuntu.com/questions/149454/upgrade-from-11-04-to-11-10-getting-wfailed-to-fetch-gzip 这个问题 ...
- 475. Heaters 加热范围
[抄题]: Winter is coming! Your first job during the contest is to design a standard heater with fixed ...
- POI 生成exel报表
去官网下载相关jar包 http://poi.apache.org/ package poi.zr.com; import java.io.File; import java.io.FileNot ...
- hadoop2.2分布式环境搭建
hadoop2.2的分布式环境需要配置的参数更多.但是需要安装的系统软件和单节点环境是一样的. 运行hadoop在非安全环境 hadoop的配置文件有两类: 1:只读的默认配置文件: core-def ...
- keydown、input 和 keyup 事件
keydown.keyup 属于键盘事件,input 属于文本事件. keydown:当用户按下键盘上的任意按键时触发,如果按住不放,会重复触发此事件. keyup:当用户释放键盘上的按键时触发. i ...
- LightOJ 1258 Making Huge Palindromes (Manacher)
题意:给定上一个串,让你在后面添加一些字符,使得这个串成为一个回文串. 析:先用manacher算法进行处理如果发现有字符匹配超过最长的了,结束匹配,答案就是该字符前面那个长度加上该串原来的长度. 代 ...
- jsp-MySQL连接池
1.将数据库驱动程序的JAR文件放在Tomcat的 common/lib 中: mysql-connector-java-5.1.18-bin.jar 下载地址:https://yunpan.cn/c ...
- brk/sbrk和mmap行为分析程序
#include <stdio.h> #include <stdlib.h> #include <unistd.h> // #include <malloc. ...