#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 2e5 + 1;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int q; cin >> q;
ll t[n + 1], d[n + 1], x[n + 1];
t[0] = 1, x[0] = 1;
for(int i = 1; i <= n; i++)
cin >> d[i];
for(int i = 1; i <= n; i++){
if(d[i] < x[i - 1]) x[i] = x[i - 1], t[i] = t[i - 1];
else{
ll v = (d[i] + x[i - 1] - 1) / x[i - 1];
t[i] = t[i - 1] * v;
x[i] = v * x[i - 1];
}
}
/*for(int i= 1; i <= n; i++){
cout << x[i] << ' ' << t[i] << "\n";
}*/
while(q--){
ll T, L, R; cin >> T >> L >> R;
ll l = -1, r = n + 1;
while(l + 1 < r){
ll mid = (l + r) / 2;
ll u = T / t[mid];
if(-mid + x[mid] * u >=L) l = mid;
else r = mid;
}
int X = l;
l = -1, r = n + 1;
while(l + 1 < r){
ll mid = (l + r) / 2;
ll u = T / t[mid];
if(-mid + x[mid] * u <= R) r = mid;
else l = mid;
}
cout << max((int)X - (int)r + 1, 0) << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
515 ms |
15132 KB |
Output is correct |
2 |
Correct |
541 ms |
30468 KB |
Output is correct |
3 |
Correct |
541 ms |
30444 KB |
Output is correct |
4 |
Correct |
577 ms |
30656 KB |
Output is correct |
5 |
Correct |
557 ms |
30468 KB |
Output is correct |
6 |
Correct |
550 ms |
30656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
515 ms |
15132 KB |
Output is correct |
2 |
Correct |
541 ms |
30468 KB |
Output is correct |
3 |
Correct |
541 ms |
30444 KB |
Output is correct |
4 |
Correct |
577 ms |
30656 KB |
Output is correct |
5 |
Correct |
557 ms |
30468 KB |
Output is correct |
6 |
Correct |
550 ms |
30656 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
307 ms |
29112 KB |
Output is correct |
14 |
Correct |
316 ms |
29624 KB |
Output is correct |
15 |
Correct |
293 ms |
28472 KB |
Output is correct |
16 |
Correct |
306 ms |
28788 KB |
Output is correct |
17 |
Correct |
375 ms |
33176 KB |
Output is correct |
18 |
Correct |
379 ms |
33036 KB |
Output is correct |
19 |
Correct |
391 ms |
33356 KB |
Output is correct |
20 |
Correct |
385 ms |
33000 KB |
Output is correct |
21 |
Correct |
379 ms |
33100 KB |
Output is correct |
22 |
Correct |
369 ms |
33028 KB |
Output is correct |
23 |
Correct |
387 ms |
33132 KB |
Output is correct |
24 |
Correct |
376 ms |
33064 KB |
Output is correct |
25 |
Correct |
549 ms |
30412 KB |
Output is correct |
26 |
Correct |
552 ms |
30644 KB |
Output is correct |
27 |
Correct |
428 ms |
32696 KB |
Output is correct |
28 |
Correct |
433 ms |
32888 KB |
Output is correct |
29 |
Correct |
411 ms |
32524 KB |
Output is correct |
30 |
Correct |
425 ms |
32756 KB |
Output is correct |
31 |
Correct |
428 ms |
32924 KB |
Output is correct |
32 |
Correct |
402 ms |
29040 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |