#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1;
int n, q;
long long d[N], t[N], l[N];
int f(int x, int ti)
{
int le = 0, ri = n;
int res = n + 1;
while (le <= ri)
{
int mid = (le + ri)/2;
int k = floor((double)ti/(double)t[mid]);
long long y = -mid + k*l[mid];
if (y <= x)
{
res = mid;
ri = mid - 1;
}
else le = mid + 1;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> d[i];
t[0] = 1;
l[0] = 1;
t[1] = d[1];
l[1] = d[1];
for (int i = 2; i <= n; ++i)
if (d[i] < d[i - 1])
t[i] = t[i - 1], l[i] = l[i - 1];
else
{
int k = trunc(ceil((double)d[i]/(double)l[i - 1]));
// cout << ceil(5/2) << endl;
//cout << k <<' ' << t[i - 1] <<' ' << l[i - 1] << endl;
t[i] = k*t[i - 1];
l[i] = k*l[i - 1];
}
//for (int i = 1; i <= n; ++i) cout << t[i] <<' ' << l[i] << endl;
int ti, le, ri;
for (int i = 1; i <= q; ++i)
{
cin >> ti >> le >> ri;
//cout << f(le - 1, ti) <<' ' << f(ri, ti) << '\n';
cout << f(le - 1, ti) - f(ri, ti) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
974 ms |
15232 KB |
Output is correct |
2 |
Correct |
1049 ms |
30628 KB |
Output is correct |
3 |
Correct |
953 ms |
46116 KB |
Output is correct |
4 |
Correct |
790 ms |
61712 KB |
Output is correct |
5 |
Correct |
806 ms |
77052 KB |
Output is correct |
6 |
Correct |
812 ms |
92440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
92440 KB |
Output is correct |
2 |
Correct |
3 ms |
92440 KB |
Output is correct |
3 |
Correct |
2 ms |
92440 KB |
Output is correct |
4 |
Correct |
3 ms |
92440 KB |
Output is correct |
5 |
Correct |
3 ms |
92440 KB |
Output is correct |
6 |
Correct |
4 ms |
92440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
974 ms |
15232 KB |
Output is correct |
2 |
Correct |
1049 ms |
30628 KB |
Output is correct |
3 |
Correct |
953 ms |
46116 KB |
Output is correct |
4 |
Correct |
790 ms |
61712 KB |
Output is correct |
5 |
Correct |
806 ms |
77052 KB |
Output is correct |
6 |
Correct |
812 ms |
92440 KB |
Output is correct |
7 |
Correct |
3 ms |
92440 KB |
Output is correct |
8 |
Correct |
3 ms |
92440 KB |
Output is correct |
9 |
Correct |
2 ms |
92440 KB |
Output is correct |
10 |
Correct |
3 ms |
92440 KB |
Output is correct |
11 |
Correct |
3 ms |
92440 KB |
Output is correct |
12 |
Correct |
4 ms |
92440 KB |
Output is correct |
13 |
Correct |
466 ms |
106936 KB |
Output is correct |
14 |
Correct |
587 ms |
123432 KB |
Output is correct |
15 |
Correct |
457 ms |
138616 KB |
Output is correct |
16 |
Correct |
444 ms |
154488 KB |
Output is correct |
17 |
Correct |
629 ms |
174540 KB |
Output is correct |
18 |
Correct |
631 ms |
193228 KB |
Output is correct |
19 |
Correct |
594 ms |
211880 KB |
Output is correct |
20 |
Correct |
753 ms |
230644 KB |
Output is correct |
21 |
Correct |
628 ms |
249108 KB |
Output is correct |
22 |
Correct |
666 ms |
262144 KB |
Output is correct |
23 |
Correct |
637 ms |
262144 KB |
Output is correct |
24 |
Correct |
598 ms |
262144 KB |
Output is correct |
25 |
Correct |
807 ms |
262144 KB |
Output is correct |
26 |
Correct |
757 ms |
262144 KB |
Output is correct |
27 |
Correct |
681 ms |
262144 KB |
Output is correct |
28 |
Correct |
895 ms |
262144 KB |
Output is correct |
29 |
Correct |
624 ms |
262144 KB |
Output is correct |
30 |
Correct |
678 ms |
262144 KB |
Output is correct |
31 |
Correct |
652 ms |
262144 KB |
Output is correct |
32 |
Correct |
682 ms |
262144 KB |
Output is correct |
33 |
Correct |
3 ms |
262144 KB |
Output is correct |