# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156158 | luciocf | Worst Reporter 3 (JOI18_worst_reporter3) | C++14 | 667 ms | 23004 KiB |
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;
const int maxn = 5e5+10;
int n;
int d[maxn];
int tempo[maxn];
int busca1(int t, int pos)
{
int ini = 0, fim = n, ans = 0;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
if ((t/tempo[mid])*tempo[mid] - mid >= pos) ans = mid, ini = mid+1;
else fim = mid-1;
}
return ans;
}
int busca2(int t, int pos)
{
int ini = 0, fim = n, ans = -1;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
if ((t/tempo[mid])*tempo[mid] - mid <= pos) ans = mid, fim = mid-1;
else ini = mid+1;
}
return ans;
}
int main(void)
{
int q;
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; i++)
scanf("%d", &d[i]);
tempo[0] = 1, tempo[1] = d[1];
for (int i = 2; i <= n; i++)
{
int x = d[i]/tempo[i-1];
if (d[i]%tempo[i-1] != 0) x++;
tempo[i] = x*tempo[i-1];
}
for (int i = 1; i <= q; i++)
{
int t, l, r;
scanf("%d %d %d", &t, &l, &r);
int R = busca2(t, r);
int L = busca1(t, l);
if (R > L) printf("0\n");
else printf("%d\n", L-R+1);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |