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>
using namespace std;
int main()
{
long long N, Q;
cin >> N >> Q;
N++;
vector<long long> Tab(N);
for (long long i = 1; i < N; i++)
{
cin >> Tab[i];
}
Tab[0] = 1;
vector<long long> step(N);
long long cur = 1;
for (long long i = 0; i < N; i++)
{
cur = cur * ceil((double)Tab[i] / cur);
step[i] = cur;
}
for (long long i = 0; i < Q; i++)
{
long long T, L, R;
cin >> T >> L >> R;
long long l = 0, r = N;
if (T - T % step[0] - 0 < L)
l = -1;
else
while (l + 1 != r)
{
long long m = (l + r) / 2;
if (T - T % step[m] - m >= L)
l = m;
else
r = m;
}
long long temp = l;
l = 0, r = N;
if (T - T % step[0] - 0 <= R)
l = -1;
else
while (l + 1 != r)
{
long long m = (l + r) / 2;
if (T - T % step[m] - m > R)
l = m;
else
r = m;
}
cout << temp - l << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |