#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> d(n + 1, 1);
for (int i = 1; i <= n; i++) cin >> d[i];
for (int i = 1; i <= n; i++) {
if (d[i] < d[i - 1]) d[i] = d[i - 1];
else d[i] = ((d[i] + d[i - 1] - 1) / d[i - 1]) * d[i - 1];
}
while (q--) {
int T, L, R, l = 1, r = n, idL = 0, idR = 0;
cin >> T >> L >> R;
// min index s.t.
while (l < r) {
int mid = (l + r) >> 1;
int pos = (-mid + (T / d[mid]) * d[mid]);
if (pos <= R) r = mid;
else l = mid + 1;
}
if (-l + (T / d[l]) * d[l] <= R) idL = l;
l = 1, r = n;
while (l < r) {
int mid = (l + r + 1) >> 1;
int pos = (-mid + (T / d[mid]) * d[mid]);
if (pos >= L) l = mid;
else r = mid - 1;
}
if (-l + (T / d[l]) * d[l] >= L) idR = l;
int add = 0;
if (L <= T && T <= R) add++;
// cout << idL << ' ' << idR << '\n';
if (idL != 0 && idR != 0) cout << (idR - idL + 1) + add << '\n';
else cout << add << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
435 ms |
22840 KB |
Output is correct |
2 |
Correct |
430 ms |
22800 KB |
Output is correct |
3 |
Correct |
429 ms |
22612 KB |
Output is correct |
4 |
Correct |
437 ms |
22852 KB |
Output is correct |
5 |
Correct |
433 ms |
22860 KB |
Output is correct |
6 |
Correct |
436 ms |
22688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
435 ms |
22840 KB |
Output is correct |
2 |
Correct |
430 ms |
22800 KB |
Output is correct |
3 |
Correct |
429 ms |
22612 KB |
Output is correct |
4 |
Correct |
437 ms |
22852 KB |
Output is correct |
5 |
Correct |
433 ms |
22860 KB |
Output is correct |
6 |
Correct |
436 ms |
22688 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
13 |
Correct |
247 ms |
21172 KB |
Output is correct |
14 |
Correct |
274 ms |
21844 KB |
Output is correct |
15 |
Correct |
238 ms |
20384 KB |
Output is correct |
16 |
Correct |
251 ms |
21124 KB |
Output is correct |
17 |
Correct |
317 ms |
25168 KB |
Output is correct |
18 |
Correct |
321 ms |
25820 KB |
Output is correct |
19 |
Correct |
319 ms |
25276 KB |
Output is correct |
20 |
Correct |
314 ms |
25244 KB |
Output is correct |
21 |
Correct |
341 ms |
25212 KB |
Output is correct |
22 |
Correct |
360 ms |
25276 KB |
Output is correct |
23 |
Correct |
328 ms |
25232 KB |
Output is correct |
24 |
Correct |
326 ms |
25428 KB |
Output is correct |
25 |
Correct |
434 ms |
22612 KB |
Output is correct |
26 |
Correct |
477 ms |
22696 KB |
Output is correct |
27 |
Correct |
380 ms |
24832 KB |
Output is correct |
28 |
Correct |
383 ms |
25252 KB |
Output is correct |
29 |
Correct |
351 ms |
24604 KB |
Output is correct |
30 |
Correct |
349 ms |
24768 KB |
Output is correct |
31 |
Correct |
353 ms |
25168 KB |
Output is correct |
32 |
Correct |
370 ms |
21488 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |