#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
int d[n+1];
for (int i = 1; i <= n; ++i) {
cin >> d[i];
}
ll a[n+1], mn[60], mx[60], c = 0; a[0] = 1;
fill(mn, mn + 60, 1e18);
fill(mx, mx + 60, 1e18); mx[0 ] = mn[0] = 0;
for (int i = 1; i <= n; ++i) {
a[i] = ((d[i] + a[i-1] - 1) / a[i-1]) * a[i-1];
if (a[i] != a[i-1]) {
mn[++c] = i;
}
mx[c] = i;
}
auto calc = [&](int t, int r) {
int x = 0;
for (int i = 0; i <= c; ++i) x += max(0LL, mx[i] - max(mn[i], (t / a[mn[i]]) * a[mn[i]] - r) + 1);
return x;
};
while (q--) {
int t, l, r;
cin >> t >> l >> r;
cout << calc(t, r) - calc(t, l-1) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
24660 KB |
Output is correct |
2 |
Correct |
150 ms |
24912 KB |
Output is correct |
3 |
Correct |
153 ms |
24656 KB |
Output is correct |
4 |
Correct |
146 ms |
24656 KB |
Output is correct |
5 |
Correct |
151 ms |
24712 KB |
Output is correct |
6 |
Correct |
146 ms |
24732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
24660 KB |
Output is correct |
2 |
Correct |
150 ms |
24912 KB |
Output is correct |
3 |
Correct |
153 ms |
24656 KB |
Output is correct |
4 |
Correct |
146 ms |
24656 KB |
Output is correct |
5 |
Correct |
151 ms |
24712 KB |
Output is correct |
6 |
Correct |
146 ms |
24732 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
162 ms |
23164 KB |
Output is correct |
14 |
Correct |
171 ms |
23632 KB |
Output is correct |
15 |
Correct |
168 ms |
22360 KB |
Output is correct |
16 |
Correct |
159 ms |
23000 KB |
Output is correct |
17 |
Correct |
228 ms |
27216 KB |
Output is correct |
18 |
Correct |
222 ms |
27216 KB |
Output is correct |
19 |
Correct |
227 ms |
27216 KB |
Output is correct |
20 |
Correct |
225 ms |
27272 KB |
Output is correct |
21 |
Correct |
206 ms |
27216 KB |
Output is correct |
22 |
Correct |
206 ms |
27152 KB |
Output is correct |
23 |
Correct |
200 ms |
27216 KB |
Output is correct |
24 |
Correct |
204 ms |
27476 KB |
Output is correct |
25 |
Correct |
151 ms |
24660 KB |
Output is correct |
26 |
Correct |
143 ms |
24660 KB |
Output is correct |
27 |
Correct |
201 ms |
26768 KB |
Output is correct |
28 |
Correct |
213 ms |
26960 KB |
Output is correct |
29 |
Correct |
237 ms |
26712 KB |
Output is correct |
30 |
Correct |
238 ms |
26704 KB |
Output is correct |
31 |
Correct |
234 ms |
26960 KB |
Output is correct |
32 |
Correct |
157 ms |
23128 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |