题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFnoi%E8%80%83%E5%90%8E%E6%AC%A2%E4%B9%90%E8%B5%9B%29/%E4%B9%8C%E9%B8%A6%E5%96%9D%E6%B0%B4

题解:真是一道神题!考场上绝对想不到标算orz!

题解写在代码注释里

代码:

 #include<cstdio>

 #include<cstdlib>

 #include<cmath>

 #include<cstring>

 #include<algorithm>

 #include<iostream>

 #include<vector>

 #include<map>

 #include<set>

 #include<queue>

 #include<string>

 #define inf 1000000000

 #define maxn 100000+5

 #define maxm 500+100

 #define eps 1e-10

 #define ll long long

 #define pa pair<int,int>

 #define for0(i,n) for(int i=0;i<=(n);i++)

 #define for1(i,n) for(int i=1;i<=(n);i++)

 #define for2(i,x,y) for(int i=(x);i<=(y);i++)

 #define for3(i,x,y) for(int i=(x);i>=(y);i--)

 #define mod 1000000007

 using namespace std;

 inline int read()

 {

     int x=,f=;char ch=getchar();

     while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}

     while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}

     return x*f;

 }
int n,m,h,s[maxn],a[maxn],b[maxn],id[maxn];
inline void add(int x,int y){for(;x<=n;x+=x&(-x))s[x]+=y;}
inline int sum(int x){int t=;for(;x;x-=x&(-x))t+=s[x];return t;}
inline bool cmp(int x,int y){return b[x]==b[y]?x<y:b[x]<b[y];} int main() { freopen("input","r",stdin); freopen("output.txt","w",stdout); n=read();m=read();h=read();
for1(i,n)a[i]=read();
for1(i,n)
{
int x=read();
if(a[i]<=h)b[i]=(h-a[i])/x+;//b[i]表示该点最多可以被饮几次水
if(b[i]>)add(i,);id[i]=i;
}
//可以证明,最后的答案一定是某个b[i],所以我们按b[i]从小到大处理
sort(id+,id+n+,cmp);
int now=,pos=,ans=,st=n+;//now 表示当前的趟数
//for1(i,n)cout<<i<<' '<<id[i]<<' '<<b[i]<<endl;
for1(i,n)if(b[id[i]]){st=i;break;}
for2(i,st,n)
{
while(now<=m)
{
int t=sum(n)-sum(pos);
if(ans+t<b[id[i]])ans+=t,now++,pos=;//如果可以走完这一趟
else break;
}
if(now>m)break;
int l=pos,r=n,t=sum(pos);
while(l<=r)
{
int mid=(l+r)>>;
if(sum(mid)-t+ans>=b[id[i]])r=mid-;else l=mid+;
}//二分到下一个点
ans=b[id[i]];pos=l;
for(;b[id[i]]==b[id[i+]];i++)add(id[i],-);//去除不能再次饮水的点
add(id[i],-);
}
printf("%d\n",ans); return ; }

Beta Round #9 (酱油杯noi考后欢乐赛)乌鸦喝水的更多相关文章

  1. Beta Round #9 (酱油杯noi考后欢乐赛)随机数生成器

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  2. Beta Round #9 (酱油杯noi考后欢乐赛)PLQ和他的小伙伴们

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  3. Beta Round #9 (酱油杯noi考后欢乐赛)PLQ的寻宝

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  4. Beta Round #9 (酱油杯noi考后欢乐赛)最大伤害

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  5. 洛谷---小L和小K的NOIP考后放松赛

    链接: https://www.luogu.org/contestnew/show/11805?tdsourcetag=s_pcqq_aiomsg 题解: 没人过的题我就没看 t2: 考虑每个点是朋友 ...

  6. Codeforces Beta Round #22 (Div. 2 Only)

    Codeforces Beta Round #22 (Div. 2 Only) http://codeforces.com/contest/22 A 水题 #include<bits/stdc+ ...

  7. Codeforces Beta Round #16 (Div. 2 Only)

    Codeforces Beta Round #16 (Div. 2 Only) http://codeforces.com/contest/16 A 水题 #include<bits/stdc+ ...

  8. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...

  9. Codeforces Beta Round #57 (Div. 2)

    Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...

随机推荐

  1. ADB操作多台设备

    1.adb devices 查看所有连接设备. 2.adb -s <设备名> shell 指定device来执行adb shell. 3.adb -s <设备名> <指令 ...

  2. 学习笔记_过滤器应用_1(分ip统计网站的访问次数)

    分ip统计网站的访问次数 ip count 192.168.1.111 2 192.168.1.112 59 统计工作需要在所有资源之前都执行,那么就可以放到Filter中了. 我们这个过滤器不打算做 ...

  3. JS数值输入控制

    在html文本框录入数值时,可用如下方法进行控制判断. 整数:<input type="text" name="aaa" onkeypress=" ...

  4. Parameters

    Quote from: http://ss64.com/nt/syntax-args.html Parameters A parameter (or argument) is any value pa ...

  5. Java中printStackTrace()、toString()、getMessage()的区别

    一.三者之间的关系图: 二.演示 1.printStackTrace()演示: public class Test {     public int div(int a, int b)     {   ...

  6. Python3 高级特性

    切片 L[0:3]表示,从索引0开始取,直到索引3为止,但不包括索引3.即索引0,1,2,正好是3个元素. 如果第一个索引是0,还可以省略: >>> L =['Michael', ' ...

  7. HTML5的全局属性

    contentEditable:是否允许用户编辑元素中的内容.contentEditable有两个值,一个True 一个False. 例子: <ul contentEditable=" ...

  8. react native学习1-安装,执行

    demo地址 http://www.oschina.net/p/reactnative http://my.oschina.net/luyongfugx/blog/394427#OSC_h1_1 翻译 ...

  9. 解决 nginx 返回数据不完整的方法

    通过PHP请求接口时发现接口的内容输出没有完整的返回整个数据,早上只修改了nginx api_metrics插件里的计算response大小的代码,观察日志发现一条: 2012/08/28 02:13 ...

  10. mongodb3.2系统性学习——2、write concern mongodb 写安全机制

    为了尊重作者原文章位置:http://kyfxbl.iteye.com/blog/1952941 首先讲一下mongodb 的写操作过程: mongodb有一个write concern的设置,作用是 ...