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/problem/ADescription
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.
Output
Sample Input
1 5 3
3 3 10
7 10 2
6 4 8
Sample Output
-1
8
-1
HINT
题意
给你一个等差数列,然后10e6次询问题解:
代码:
//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=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } ll A,B,q,t,m,l; ll ans(ll x) { return A+(x-1)*B; } ll sum(ll l,ll r) { ll x1=A+(l-1)*B,x2=A+(r-1)*B; return 1ll*(x1+x2)*(r-l+1)/2; } 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>>1; if(ans(mid)<=t && sum(l,mid)<=1ll*t*m)lef=mid+1; else rig=mid-1; } if(rig==l-1)printf("-1\n"); else printf("%d\n",rig); } return 0; }