#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1069 ms |
18748 KB |
Output is correct |
2 |
Correct |
1176 ms |
34352 KB |
Output is correct |
3 |
Correct |
1106 ms |
49984 KB |
Output is correct |
4 |
Correct |
1113 ms |
65532 KB |
Output is correct |
5 |
Correct |
1094 ms |
80912 KB |
Output is correct |
6 |
Correct |
1081 ms |
96392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
96392 KB |
Output is correct |
2 |
Correct |
4 ms |
96392 KB |
Output is correct |
3 |
Correct |
4 ms |
96392 KB |
Output is correct |
4 |
Correct |
4 ms |
96392 KB |
Output is correct |
5 |
Correct |
4 ms |
96392 KB |
Output is correct |
6 |
Correct |
4 ms |
96392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1069 ms |
18748 KB |
Output is correct |
2 |
Correct |
1176 ms |
34352 KB |
Output is correct |
3 |
Correct |
1106 ms |
49984 KB |
Output is correct |
4 |
Correct |
1113 ms |
65532 KB |
Output is correct |
5 |
Correct |
1094 ms |
80912 KB |
Output is correct |
6 |
Correct |
1081 ms |
96392 KB |
Output is correct |
7 |
Correct |
5 ms |
96392 KB |
Output is correct |
8 |
Correct |
4 ms |
96392 KB |
Output is correct |
9 |
Correct |
4 ms |
96392 KB |
Output is correct |
10 |
Correct |
4 ms |
96392 KB |
Output is correct |
11 |
Correct |
4 ms |
96392 KB |
Output is correct |
12 |
Correct |
4 ms |
96392 KB |
Output is correct |
13 |
Incorrect |
983 ms |
106992 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |