#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;
const int maxn = 5e5 + 5;
int n, q;
ll d[maxn], cnt[maxn];
// i-ty ucastnik sa kazdych cnt[i] sekund pohne o mv[i] dopredu
ll pos(int i, int t) // pozicia i v case t
{
return ((ll)-i) + (t / cnt[i]) * 1ll * cnt[i];
}
int last(int x, int t) // najdi index posledneho ktory stoji <= x v case t
{
int lo = 0, hi = n + 1;
while (lo < hi)
{
int mi = (lo + hi) >> 1;
if (pos(mi, t) <= x) hi = mi;
else lo = mi + 1;
}
return lo;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
cnt[0] = 1;
for (int i = 1; i <= n; i++)
{
cin >> d[i];
// ak sa i-1 pohne o d[i] krokov
cnt[i] = ((d[i] + cnt[i - 1] - 1) / cnt[i - 1]) * cnt[i - 1];
}
while (q--)
{
int t, l, r;
cin >> t >> l >> r;
int ans = last(l - 1, t) - last(r, t);
cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
679 ms |
26528 KB |
Output is correct |
2 |
Correct |
654 ms |
26508 KB |
Output is correct |
3 |
Correct |
665 ms |
26676 KB |
Output is correct |
4 |
Correct |
661 ms |
26620 KB |
Output is correct |
5 |
Correct |
684 ms |
26524 KB |
Output is correct |
6 |
Correct |
687 ms |
26536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
679 ms |
26528 KB |
Output is correct |
2 |
Correct |
654 ms |
26508 KB |
Output is correct |
3 |
Correct |
665 ms |
26676 KB |
Output is correct |
4 |
Correct |
661 ms |
26620 KB |
Output is correct |
5 |
Correct |
684 ms |
26524 KB |
Output is correct |
6 |
Correct |
687 ms |
26536 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
402 ms |
25156 KB |
Output is correct |
14 |
Correct |
425 ms |
25664 KB |
Output is correct |
15 |
Correct |
394 ms |
24316 KB |
Output is correct |
16 |
Correct |
431 ms |
24896 KB |
Output is correct |
17 |
Correct |
496 ms |
29100 KB |
Output is correct |
18 |
Correct |
508 ms |
29072 KB |
Output is correct |
19 |
Correct |
495 ms |
29148 KB |
Output is correct |
20 |
Correct |
504 ms |
29120 KB |
Output is correct |
21 |
Correct |
493 ms |
29160 KB |
Output is correct |
22 |
Correct |
502 ms |
29184 KB |
Output is correct |
23 |
Correct |
499 ms |
29024 KB |
Output is correct |
24 |
Correct |
483 ms |
29380 KB |
Output is correct |
25 |
Correct |
681 ms |
26564 KB |
Output is correct |
26 |
Correct |
690 ms |
26568 KB |
Output is correct |
27 |
Correct |
553 ms |
28700 KB |
Output is correct |
28 |
Correct |
544 ms |
28992 KB |
Output is correct |
29 |
Correct |
559 ms |
28704 KB |
Output is correct |
30 |
Correct |
567 ms |
28732 KB |
Output is correct |
31 |
Correct |
548 ms |
28876 KB |
Output is correct |
32 |
Correct |
527 ms |
25124 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |