Tavas and Karafs
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/536/problem/A
Description
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.
Input
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.
1000000000.
Output
Sample Input
1 5 3
3 3 10
7 10 2
6 4 8
Sample Output
-1
8
-1
HINT
题意
给你一个等差数列,然后10e6次询问
题解:
傻逼题,只要每个数都小于等于t,前缀和小于等于t*m就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//**************************************************************************************
inline ll 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;
}
ll A,B,q,t,m,l;
ll ans(ll x)
{
return A+(x-)*B;
}
ll sum(ll l,ll r)
{
ll x1=A+(l-)*B,x2=A+(r-)*B;
return 1ll*(x1+x2)*(r-l+)/;
}
int main()
{
scanf("%d%d%d",&A,&B,&q);
while(q--)
{
int l,t,m;
scanf("%d%d%d",&l,&t,&m);
int lef=l,rig=inf,mid;
while(lef<=rig)
{
mid=lef+rig>>;
if(ans(mid)<=t && sum(l,mid)<=1ll*t*m)lef=mid+;
else rig=mid-;
}
if(rig==l-)printf("-1\n");
else printf("%d\n",rig);
}
return ;
}