#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int INF = 2e9;
inline int get(int pos, vector <ll> &prd, int t) {
return (t / prd[pos]) * prd[pos];
}
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, q;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> q;
vector <int> d(n + 1, 1);
for(i = 1; i <= n; i++) {
cin >> d[i];
}
vector <ll> prd(n + 1, 1);
for(i = 1; i <= n; i++) {
prd[i] = (d[i] + prd[i - 1] - 1) / prd[i - 1];
prd[i] *= prd[i - 1];
if(prd[i] > INF) {
prd[i] = INF;
}
//cerr << prd[i] << " ";
}
while(q > 0) {
q--;
int t, l, r;
cin >> t >> l >> r;
int a = 0, b = 0;
for(int step = 1 << 19; step; step >>= 1) {
if(a + step <= n && -(a + step) + get(a + step, prd, t) > r) {
a += step;
}
if(b + step <= n && -(b + step) + get(b + step, prd, t) >= l) {
b += step;
}
}
int ans = b - a;
if(l <= t && t <= r) {
ans++;
}
cout << ans << "\n";
}
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
677 ms |
24732 KB |
Output is correct |
2 |
Correct |
698 ms |
24824 KB |
Output is correct |
3 |
Correct |
732 ms |
24840 KB |
Output is correct |
4 |
Correct |
745 ms |
24824 KB |
Output is correct |
5 |
Correct |
790 ms |
24696 KB |
Output is correct |
6 |
Correct |
782 ms |
24772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
677 ms |
24732 KB |
Output is correct |
2 |
Correct |
698 ms |
24824 KB |
Output is correct |
3 |
Correct |
732 ms |
24840 KB |
Output is correct |
4 |
Correct |
745 ms |
24824 KB |
Output is correct |
5 |
Correct |
790 ms |
24696 KB |
Output is correct |
6 |
Correct |
782 ms |
24772 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
461 ms |
23168 KB |
Output is correct |
14 |
Correct |
463 ms |
23776 KB |
Output is correct |
15 |
Correct |
512 ms |
22520 KB |
Output is correct |
16 |
Correct |
515 ms |
23160 KB |
Output is correct |
17 |
Correct |
608 ms |
27384 KB |
Output is correct |
18 |
Correct |
628 ms |
27356 KB |
Output is correct |
19 |
Correct |
618 ms |
27352 KB |
Output is correct |
20 |
Correct |
587 ms |
27312 KB |
Output is correct |
21 |
Correct |
566 ms |
27256 KB |
Output is correct |
22 |
Correct |
571 ms |
27456 KB |
Output is correct |
23 |
Correct |
632 ms |
27256 KB |
Output is correct |
24 |
Correct |
613 ms |
27384 KB |
Output is correct |
25 |
Correct |
841 ms |
24748 KB |
Output is correct |
26 |
Correct |
673 ms |
24788 KB |
Output is correct |
27 |
Correct |
638 ms |
26848 KB |
Output is correct |
28 |
Correct |
687 ms |
27348 KB |
Output is correct |
29 |
Correct |
642 ms |
26684 KB |
Output is correct |
30 |
Correct |
678 ms |
26844 KB |
Output is correct |
31 |
Correct |
613 ms |
27200 KB |
Output is correct |
32 |
Correct |
643 ms |
23292 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |