This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h> // PLEASE
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pp;
#define MAXN 300005
#define MAXM 1005
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
int N, Q;
ll D[MAXN];
ll calc(ll a, ll b)
{
if(a%b) return a/b + 1;
return a/b;
}
int get(ll T, ll x)
{
int l=0; int r = N; int ret = -1;
while(l <= r) {
int md = (l+r)/2;
if(x <= (T/D[md]) * D[md] - 1LL*md) {
ret = md;
l=md+1;
}
else r=md-1;
}
return ret;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> Q;
D[0] = 1;
for(int i=1; i<=N; i++) cin >> D[i];
for(int i=1; i<=N; i++) D[i] = D[i-1] * calc(D[i], D[i-1]);
while(Q--) {
ll lq, rq, t;
cin >> t >> lq >> rq;
cout << get(t, lq) - get(t, rq+1) << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |