/*多么变态的一道题,交了18次*/

 #include<cstdio>
#include<cstring>
#include<cmath>
#define max(a,b) (a>b?a:b)
int dp[][],llog2[];//用llog2数组进行优化
int n,k; void DpMax(){
for(int j=;j<=llog2[n]+;j++){//llog2
for(int i=;i+(<<j)-<=n;i++){
dp[i][j]=max(dp[i][j-],dp[i+(<<(j-))][j-]);
}
}
} int GetMax(int L,int R){
int j=llog2[R-L+];//llog2
return max(dp[L][j],dp[R-(<<j)+][j]);
} int work(){
int pre_num = -, pre_tot = -, pre_sum;
for(int i = ; i <= n; ++i) //分成i组
{
int num = n / i; //每组num个
int sum = num * i; //总的多少人
int tot = ;
if(num == pre_num) //如果和前一次一样则从前一次继续累加即可
{
tot = pre_tot;
for(int j = pre_sum + num; j <= sum; j+= num)
{
tot += GetMax(j - num + , j);
if(tot > k)
return i;
}
pre_tot = tot;
pre_sum = sum;
}
else
{
for(int j = num; j <= sum; j += num)
{
tot += GetMax(j-num+, j);
if(tot > k)
return i;
}
pre_num = num;
pre_tot = tot;
pre_sum = sum;
}
}
return -;
} int main(){
for(int i=;i<;++i){//llog2
llog2[i]=(i&(i-))==?llog2[i-]+:llog2[i-];
}
while(scanf("%d%d",&n,&k),n>||k>){
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
scanf("%d",&dp[i][]);
}
DpMax();
printf("%d\n",work());
}
}

HDU3486 RMQ的更多相关文章

  1. *HDU3486 RMQ+二分

    Interviewe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. [hdu3486]rmq+枚举优化

    题意:给n个数,求最小的段数,使得每一段的最大值之和大于给定的k.每一段的长度相等,最后若干个丢掉. 思路:从小到大枚举段数,如果能o(1)时间求出每一段的和,那么总复杂度是O(n(1+1/2+1/3 ...

  3. BZOJ 3489: A simple rmq problem

    3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit] ...

  4. UVA 11235Frequent values(RMQ)

    训练指南P198 题意:给出一个非降序排列的整数数组a1, a2…… an,你的任务是对于一系列询问(i,j),回答ai, ai+1 ……aj 中出现的次数最多的次数 这题不仅学到了rmq的应用还学到 ...

  5. 51nod1174(RMQ)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1174 题意:中文题诶- 思路:RMQ模板题 关于RMQ: h ...

  6. 2016 ACM/ICPC Asia Regional Dalian Online 1008 Function 二分+RMQ

    Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submissio ...

  7. Gym 100646 F Tanks a Lot RMQ

    Problem F: Tanks a Lot Imagine you have a car with a very large gas tank - large enough to hold what ...

  8. (RMQ版)LCA注意要点

    inline int lca(int x,int y){ if(x>y) swap(x,y); ]][x]]<h[rmq[log[y-x+]][y-near[y-x+]+]])? rmq[ ...

  9. 洛谷P2412 查单词 [trie树 RMQ]

    题目背景 滚粗了的HansBug在收拾旧英语书,然而他发现了什么奇妙的东西. 题目描述 udp2.T3如果遇到相同的字符串,输出后面的 蒟蒻HansBug在一本英语书里面找到了一个单词表,包含N个单词 ...

随机推荐

  1. half adder vs. full adder

    1, half adder 2-input, 2-output input: A, B; output out, carry; 2, full adder 3-input, 2-output inpu ...

  2. 关于set_multicycle_path的最后总结

    (1) –start/-end决定移动的距离以start_clock/end_clock为单元: (2) 对于-setup选项,移动距离是在默认关系的基础上移动(数值-1): (3) 默认往后, se ...

  3. pyqt点击右上角关闭界面但是子线程仍在运行

    现象: 通过右上角的叉关闭图形界面后,程序运行的子线程却不会被自动关闭,依然留存在系统中原因: 子线程没有正确关闭解决方法: 1.将子线程设置成守护线程 self.your_thread = thre ...

  4. PKUSC2019 D2T2

    PKUSC2019 D2T2 把n(n<=100)的树(无边权)放在m维空间上(坐标都是整点),使得任意两个点的曼哈顿距离都是原树上的距离 求最小的m,并给出构造方案 性质好题,巧妙构造题. 原 ...

  5. Installer - win10安装及卸载SQL Server2008数据库

    一.数据库安装环境 操作系统:win10 SQL server:SQL server 2008 R2 二.全新数据库安装 1.安装扩展文件 双击安装文件,弹出如下窗体:                 ...

  6. PAT甲级——A1077 Kuchiguse

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

  7. mysql80版本—yum安装—图文全过程

    这是官网的Quick Giude:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/ 以下为自己安装的步骤: 第一步:下载.rpm安装包 ...

  8. Mahout In Action-第一章:初识Mahout

    1. 初识Mahout 本章涵盖以下内容: Apache Mahout是什么? 现实中推荐系统引擎.聚类.分类概述 配置mahout 读者可能从本书的标题中猜测到,本书是一本讲解如何将mahout应用 ...

  9. Luogu P3835 【模板】可持久化平衡树(fhq Treap)

    P3835 [模板]可持久化平衡树 题意 题目背景 本题为题目普通平衡树的可持久化加强版. 题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作(对于各个以往的历史版本 ...

  10. Odoo(OpenERP)配置文件详解

    [options] ; addons模块的查找路径 addons_path = E:\GreenOdoo8.0\source\openerp\addons ; 管理员主控密码(用于创建.还原和备份数据 ...