ZOJ 3726 RMQ + 二分法
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072
区域赛真干的话题
通过率最高的一个问题 不到一半认为这OK 然后WA果断地 另外int无用long long WA
好久没用RMQ 调试也花了一点时间,
upper——bound返回的是大于x的第一个数的下标,最大当然是返回end的位置,注意推断下
注意一点,如果须要打印的张数为x s[i]=<x<s[i+1] 事实上 要找的是ans=min(p[i]*x,s[i+1]*p[i+1],s[i+1]*p[i+2]...s[n]*p[n]),所以单单二分必定不行啊
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath> using namespace std; const int MAXN = 1e5+100;
#define IN(s) freopen(s,"r",stdin)
#define ll long long
#define ull unsigned long long
const ll INF = ((ull)(-1))>>1;
ll s[MAXN],p[MAXN],tot[MAXN];
int n,m;
ll d[20];
ll st[MAXN][20];
void init()
{
for(int i=0;i<n;i++)st[i][0]=tot[i+1];
int k = (int)( log(double(n*1.0)/log(2.0)) ) +1;
for(int j=1;j<k;j++)
for(int i=0;i<n;i++)
{
if(i + d[j-1]-1 <n)
{
st[i][j] = min( st[i][j-1], st[i+d[j-1]][j-1] );
}
else break;
}
} void query(int q)
{
int y=n-1;
for(int i=0;i<q;i++)
{
int x,k;
scanf("%d",&x);
int id= upper_bound(s+1,s+1+n,x)-(s+1);
if(id>=n)
{
printf("%lld\n",p[n]*x);
continue;
}
ll ans=INF;
ans=min(ans,p[id]*x);
k=int( log(double(y-id+1)/log(2.0)) );
ans=min(ans,min(st[id][k],st[y-d[k]+1][k]));
printf("%lld\n",ans);
}
} int main()
{
//IN("zoj3726.txt");
d[0]=1;
for(int i=1;i<21;i++)d[i]=2*d[i-1];
int ncase;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&s[i],&p[i]);
tot[i]=s[i]*p[i];
}
init();
query(m);
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
ZOJ 3726 RMQ + 二分法的更多相关文章
- 2013 ACM/ICPC 长沙现场赛 A题 - Alice's Print Service (ZOJ 3726)
Alice's Print Service Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is providing print ser ...
- Codeforces 514 D R2D2 and Droid Army(RMQ+二分法)
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, w ...
- zoj 3665 数论 二分法 两个参数
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4888 标题两个参数,途径:小参数的枚举,然后二分法大参数 想想两个点.以后就不 ...
- I - Beautiful People ZOJ - 2319 (二分法)
The most prestigious sports club in one city has exactly N members. Each of its members is strong an ...
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...
- A - Alice's Print Service ZOJ - 3726 (二分)
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- 近几年ACM/ICPC区域赛铜牌题
2013 changsha zoj 3726 3728 3736 3735 2013 chengdu hud 4786 4788 4790 2013 hangzhou hdu 4770 4771 47 ...
- ZOJ Design the city LCA转RMQ
Design the city Time Limit: 1 Second Memory Limit: 32768 KB Cerror is the mayor of city HangZho ...
- ZOJ 3195 Design the city LCA转RMQ
题意:给定n个点,下面n-1行 u , v ,dis 表示一条无向边和边权值,这里给了一颗无向树 下面m表示m个询问,问 u v n 三点最短距离 典型的LCA转RMQ #include<std ...
随机推荐
- swift 旋转加载动画
https://github.com/naoyashiga/RPLoadingAnimation
- js进阶解决浏览器缓存不能自动更新的问题(在ajax的url上带上一个参数,可以是日期,或者是随机数)(随机数Math.random)(取得日期的毫秒数:new Date().getTime();)
js进阶解决浏览器缓存不能自动更新的问题(在ajax的url上带上一个参数,可以是日期,或者是随机数)(随机数Math.random)(取得日期的毫秒数:new Date().getTime();) ...
- ListView.setSelection(position)不起作用
选择同事列表页面,在Adapter里设置复选框背景时调用了notifyDataSetChanged(),阻碍了UI线程,因此在设置ListView.setSelection(position)时不起作 ...
- php 中英文字符串截取,字符串长度
在做PHP开发的时候,由于我国的语言环境问题,所以我们常常需要对中文进行处理.在PHP中,我们都知道有专门的mb_substr和mb_strlen函数,可以对中文进行截取和计算长度,但是,由于这些函数 ...
- bash - trap
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_02.html The syntax for the trap statement is s ...
- 从多路搜索树到 B-树
1. 什么是 B 树 B 树是为磁盘或其他直接存取的辅助存储设备而设计的一种平衡二叉树: B 树类似于红黑树,但它们在降低磁盘 I/O 操作数方面要更好一点, 许多数据库系统使用 B 树或者 B 树的 ...
- amazeui-js插件-ui增强-日期组件如何使用(把实例做一下)
amazeui-js插件-ui增强-日期组件如何使用(把实例做一下) 一.总结 一句话总结:需要jquery.js和amazeui.js一切才能使用 1.amazeui中的各种js效果要怎么才能使用? ...
- NOIP模拟 乘积 - 状压dp + 分组背包
题目大意: 给出n和k,求从小于等于n的数中取出不超过k个,其乘积是无平方因子数的方案数.无平方因子数:不能被质数的平方整除. 题目分析: 10(枚举\(n\le8\)),40(简单状压\(n\le1 ...
- 阿里云centos7.2自己安装mysql5.7远程不能访问解决方案
版权声明:转载也行 https://blog.csdn.net/u010955892/article/details/72774920 最近,无意中看到阿里云服务器降价,所以一时手痒,买了一年的服务器 ...
- 苹果抛弃的芯片公司Imagination被中资49亿溢价收购
原标题:中国资本Canyon Bridge出资5.5亿英镑收购Imagination芯片 来源:观察者网 对于一家手机硬件公司来说,被苹果看上可谓是“一夜之间,鸡犬升天”.但是如果被苹果抛弃了呢?那可 ...