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 + 二分法的更多相关文章

  1. 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 ...

  2. 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 ...

  3. zoj 3665 数论 二分法 两个参数

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4888 标题两个参数,途径:小参数的枚举,然后二分法大参数 想想两个点.以后就不 ...

  4. I - Beautiful People ZOJ - 2319 (二分法)

    The most prestigious sports club in one city has exactly N members. Each of its members is strong an ...

  5. HDU 4791 &amp; ZOJ 3726 Alice&#39;s Print Service (数学 打表)

    题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...

  6. 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 ...

  7. 近几年ACM/ICPC区域赛铜牌题

    2013 changsha zoj 3726 3728 3736 3735 2013 chengdu hud 4786 4788 4790 2013 hangzhou hdu 4770 4771 47 ...

  8. ZOJ Design the city LCA转RMQ

    Design the city Time Limit: 1 Second      Memory Limit: 32768 KB Cerror is the mayor of city HangZho ...

  9. ZOJ 3195 Design the city LCA转RMQ

    题意:给定n个点,下面n-1行 u , v ,dis 表示一条无向边和边权值,这里给了一颗无向树 下面m表示m个询问,问 u v n 三点最短距离 典型的LCA转RMQ #include<std ...

随机推荐

  1. thinkphp3.2 图片平均颜色值

    public function imgColor($imgUrl) { $imageInfo = getimagesize($imgUrl); //图片类型 $imgType = strtolower ...

  2. Centos6.5 网络配置

    网络配置 本教程配置说明 以下为本教程安装时的配置,用户依据实际情况进行调整 * 在root用户权限下安装下完毕 * IP地址设置为 10.10.108.160 * 本机DNS设置为 8.8.8.8 ...

  3. Django之文章归档

    1.任务描述:将博文按照时间月份归档 2.源代码: views.py def getPage(request, article_list): paginator = Paginator(article ...

  4. Android 监听软键盘按键的三种方式

    前言: 我们在Android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“Go”按键加载url页面:在点击搜索框的时候,点击右下角的searc ...

  5. [Vue] Conditionally Render DOM Elements in Vue.js (v-if v-else v-show)

    You can use v-if and v-else to display content based on assertions on your data. Similarly, v-show c ...

  6. iOS8.1 编译ffmpeg和集成第三方实现直播(监控类)

    iOS8.1 编译ffmpeg和集成第三方实现直播(监控类) http://www.mamicode.com/info-detail-476094.html 一,下载并在终端中运行脚本编译ffmpeg ...

  7. 理解Erlang/OTP Supervisor

    http://www.cnblogs.com/me-sa/archive/2012/01/10/erlang0030.html Supervisors are used to build an hie ...

  8. 【t045】细菌

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 近期,农场出现了D (1<= D <=15)种细菌.John 要从他的 N (1<= ...

  9. hadoop 3.x 启动过程中 Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

    出现这种状况是因为当前账号没有配置ssh免密登录 进入到以下目录,查看是否生成过秘钥对,如果有的话直接ssh-copy-id 主机名 没有的话执行ssh-keygen -t rsa后再重新执行ssh- ...

  10. ANT下载与安装--windows

    原文:ANT下载与安装--windows 1.下载地址 http://ant.apache.org/bindownload.cgi: 2.版本信息 1.10.2 .zip archive  对应jdk ...