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 lim = 1e9;
const int Nmax = 5e5 + 5;
typedef long long ll;
int tmp, x, y, up, D, i, N, Q, n, F, S, cnt;
int d[Nmax], t[Nmax], start[Nmax], finish[Nmax];
int main()
{
// freopen("input", "r", stdin);
// freopen("output", "w", stdout);
cin.sync_with_stdio(false);
cin >> N >> Q;
n = 1, t[1] = 1, d[1] = 1;
for(i=1; i<=N; ++i)
{
cin >> D;
up = D / d[n];
if(D % d[n]) ++up;
if((ll) up * t[n] > lim || (ll) up * d[n] > lim) break;
if(up == 1) start[n] --;
else
{
++n;
start[n] = finish[n] = -i;
t[n] = t[n-1] * up;
d[n] = d[n-1] * up;
}
}
while(Q--)
{
cin >> tmp >> x >> y;
int ans = 0;
for(i=1; i<=n; ++i)
{
cnt = tmp / t[i];
S = start[i] + cnt * d[i];
F = finish[i] + cnt * d[i];
ans += max(0, min(y, F) - max(x, S) + 1);
}
cout << ans << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |