#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5 + 5;
int d[N];
int n, q;
int get(int T,int P) {
int l = 0;
int r = n + 1;
for(; l < r ;) {
int m = (l + r) / 2;
if (T / d[m] * d[m] < P + m)
r = m;
else
l = m + 1;
}
return l;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
d[0] = 1;
for(int i = 1 ; i <= n ; ++i) {
int x; cin >> x;
int k = (d[i - 1] + x - 1) / d[i - 1];
d[i] = k * d[i - 1];
}
for(int i = 1 ; i <= q ; ++i) {
int T; cin >> T;
int l; cin >> l;
int r; cin >> r;
cout << get(T,l) - get(T,r + 1) << "\n";
}
}
/*
3 6
2
5
3
1 2 4
2 2 4
3 2 4
4 2 4
5 2 4
6 2 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
931 ms |
23220 KB |
Output is correct |
2 |
Correct |
883 ms |
22704 KB |
Output is correct |
3 |
Correct |
833 ms |
23004 KB |
Output is correct |
4 |
Correct |
872 ms |
22812 KB |
Output is correct |
5 |
Correct |
881 ms |
22820 KB |
Output is correct |
6 |
Correct |
858 ms |
22948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
931 ms |
23220 KB |
Output is correct |
2 |
Correct |
883 ms |
22704 KB |
Output is correct |
3 |
Correct |
833 ms |
23004 KB |
Output is correct |
4 |
Correct |
872 ms |
22812 KB |
Output is correct |
5 |
Correct |
881 ms |
22820 KB |
Output is correct |
6 |
Correct |
858 ms |
22948 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
565 ms |
21296 KB |
Output is correct |
14 |
Correct |
563 ms |
21980 KB |
Output is correct |
15 |
Correct |
541 ms |
20556 KB |
Output is correct |
16 |
Correct |
551 ms |
21112 KB |
Output is correct |
17 |
Correct |
729 ms |
25336 KB |
Output is correct |
18 |
Correct |
693 ms |
25432 KB |
Output is correct |
19 |
Correct |
683 ms |
25476 KB |
Output is correct |
20 |
Correct |
697 ms |
25308 KB |
Output is correct |
21 |
Correct |
698 ms |
25496 KB |
Output is correct |
22 |
Correct |
687 ms |
25464 KB |
Output is correct |
23 |
Correct |
708 ms |
25400 KB |
Output is correct |
24 |
Correct |
699 ms |
25480 KB |
Output is correct |
25 |
Correct |
858 ms |
22904 KB |
Output is correct |
26 |
Correct |
859 ms |
22904 KB |
Output is correct |
27 |
Correct |
778 ms |
25120 KB |
Output is correct |
28 |
Correct |
744 ms |
25080 KB |
Output is correct |
29 |
Correct |
707 ms |
24824 KB |
Output is correct |
30 |
Correct |
803 ms |
24952 KB |
Output is correct |
31 |
Correct |
721 ms |
25336 KB |
Output is correct |
32 |
Correct |
687 ms |
21368 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |