CF Tavas and Karafs (二分)
2 seconds
256 megabytes
standard input
standard output
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.

Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
For each query, print its answer in a single line.
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
4
-1
8
-1
1 5 2
1 5 10
2 7 4
1
2
今天才发现比赛时候的算法是对的。。。只不过数据爆了,改成long long就过了,还重新找题解写了一次。。。。
不过新写的更快一点,130ms,二分查找,下界为L,二分查上界,上界的初始值可以算出来。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <ctime>
using namespace std; long long bsearch(long long,long long,long long); long long A,B;
int main(void)
{
long long l,t,m,r;
long long n; scanf("%lld%lld%lld",&A,&B,&n);
while(n --)
{
scanf("%lld%lld%lld",&l,&t,&m);
if(t < A + (l - ) * B)
{
puts("-1");
continue;
}
r = bsearch(l,t,m);
printf("%lld\n",r);
} return ;
} long long bsearch(long long l,long long t,long long m)
{
long long low = l;
long long high = (t - A) / B + ; while(low <= high)
{
long long mid = (low + high) / ;
long long box = (A + (l - ) * B + A + (mid - ) * B) * (mid - l + ) / ; if(box <= m * t)
low = mid + ;
else
high = mid - ;
} return low - ;
}
CF Tavas and Karafs (二分)的更多相关文章
- C. Tavas and Karafs 二分查找+贪心
C. Tavas and Karafs #include <iostream> #include <cstdio> #include <cstring> #incl ...
- Tavas and Karafs 二分+结论
二分比较容易想到 #include<map> #include<set> #include<cmath> #include<queue> #includ ...
- CodeForces 535C Tavas and Karafs —— 二分
题意:给出一个无限长度的等差数列(递增),每次可以让从l开始的m个减少1,如果某个位置已经是0了,那么可以顺延到下一位减少1,这样的操作最多t次,问t次操作以后从l开始的最长0序列的最大右边界r是多少 ...
- CF 535c Tavas and Karafs
Tavas and Karafs Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Codeforces 535C - Tavas and Karafs
535C - Tavas and Karafs 思路:对于满足条件的r,max(hl ,hl+1 ,hl+2 ,......,hr )<=t(也就是hr<=t)且∑hi<=t*m.所 ...
- Codeforces Round #299 (Div. 1) A. Tavas and Karafs 水题
Tavas and Karafs Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/536/prob ...
- 二分搜索 Codeforces Round #299 (Div. 2) C. Tavas and Karafs
题目传送门 /* 题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1 二分搜索:搜索r,求出sum <= t * m的最大的r 详细解释:http:/ ...
- CF 84D Doctor(二分)
题目链接: 传送门 Doctor time limit per test:1 second memory limit per test:256 megabytes Description Th ...
- ProbS CF matlab源代码(二分系统)(原创作品,转载注明出处,谢谢!)
%ProbS clear all;%% 数据读入与预处理 data = load('E:\network_papers\u1.base');test = load('E:\network_papers ...
随机推荐
- DAG的生成
DAG的生成 原始的RDD(s)通过一系列转换就形成了DAG.RDD之间的依赖关系,包含了RDD由哪些Parent RDD(s)转换而来和它依赖parent RDD(s)的哪些Partitions,是 ...
- CF#190DIV.1
/* CF#190DIV.1-C 题意:给你n个结点的树,给这些结点标记字母AB..Z,对于标记相同的结点路径上 的结点的标记必须有一个是大于该标记的:问是否可以标记(A是最大标记) 分析:整天思路就 ...
- SaltStack安装(CentOS7.x)
安装基础: 参考文档:https://docs.saltstack.com/en/latest/topics/installation/rhel.html 1.导入SaltStack仓库key: wg ...
- hibernate注解@JoinTable说明
表关联(@JoinTable)注解说明:@Target({METHOD, FIELD})public @interface JoinTable{ String name() default &q ...
- [iOS 多线程 & 网络 - 2.6] - 使用POST上传JSON数据 & 多值参数
A.上传JSON 1.思路: 必须使用POST方法才能上传大量JSON数据 设置请求头:设置Content-Type 设置请求体,JSON实际相当于字典,可以用NSDictionary NSJSONS ...
- oracle 的rowid和rownum
rowid就是唯一标志记录物理位置的一个id,对于rownum来说它是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,依此类推,这个伪字段可以用于限制查询返回的总行 ...
- UVALIVE 4970 最小权匹配
首先贴一下这道题的BNU地址,UVA地址自己找吧. http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=11852 题意:这道题的意思就是,给你N个棋子的 ...
- 【搬运】【备份】imrc文件
存档. " ============================================================================= " < ...
- QM04-生产中的QM
集成的计划 生产过程中的生产工序和检验工序逐渐变得更为相互依赖或者说被组合在一起.从而使来自生产和质量检验领域的工作小组共同创建工艺流程. 检验工序 可以把QM检验特性集成到生产计划(PP)模块的工作 ...
- SimpleTagImageView
https://github.com/wujingchao/SimpleTagImageView SimpleTagImageView ImageView with a tag in android. ...