#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const ll N = 5e5 ;
ll n, q, tn, d[N + 1], ans[N + 1], pref[N + 1] ;
struct query
{
ll t, l, r, ind ;
};
vector<query> qr ;
signed main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
cin >> n >> q ;
for(ll i = 1 ; i <= n ; i++)
cin >> d[i] ;
for(ll i = 1 ; i <= q ; i++)
{
query q ;
cin >> q.t >> q.l >> q.r ;
q.ind = i ;
qr.push_back(q) ;
}
pref[1] = d[1] ;
for(ll i = 2 ; i <= n ; i++)
{
ll l = 0, r = 1e9 + 1 ;
while(l + 1 < r)
{
ll mid = (l + r) >> 1ll ;
if(mid * pref[i - 1] >= d[i])r = mid ;
else l = mid ;
}
pref[i] = pref[i - 1] * r ;
}
for(query i : qr)
{
ll l1 = 0, r1 = n + 1, l2 = 0, r2 = n + 1 ;
while(l1 + 1 < r1)
{
ll mid = (l1 + r1) >> 1ll, posmd = (i.t / pref[mid]) * pref[mid] - mid ;
if(posmd <= i.r)r1 = mid ;
else l1 = mid ;
}
while(l2 + 1 < r2)
{
ll mid = (l2 + r2) >> 1ll, posmd = (i.t / pref[mid]) * pref[mid] - mid ;
if(posmd >= i.l)l2 = mid ;
else r2 = mid ;
}
cout << l2 - r1 + 1 + (i.l <= i.t && i.t <= i.r) << '\n' ;
// cout << "\n" ;
}
return 0 ;
}
//4 5
//1
//1
//1
//1
//2 1 4
//1 3 6
//20 17 19
//20 17 18
//20 0 20
//1 0 -1 -2 -3
//2 1 0 -1 -2
//3 2 1 0 -1
//4 3 2 1 0
//5 4 3 2 1
//6 5 4 3 2
//7 6 5 4 3
//8 7 6 5 4
//9 8 7 6 5
//10 9 8 7 6
//11 10 9 8 7
//12 11 10 9 8
//13 12 11 10 9
//14 13 12 11 10
//15 14 13 12 11
//16 15 14 13 12
//17 16 15 14 13
//18 17 16 15 14
//19 18 17 16 15
//20 19 18 17 16
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
434 ms |
26908 KB |
Output is correct |
2 |
Correct |
444 ms |
26852 KB |
Output is correct |
3 |
Correct |
439 ms |
26940 KB |
Output is correct |
4 |
Correct |
435 ms |
26840 KB |
Output is correct |
5 |
Correct |
436 ms |
26956 KB |
Output is correct |
6 |
Correct |
430 ms |
26904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
434 ms |
26908 KB |
Output is correct |
2 |
Correct |
444 ms |
26852 KB |
Output is correct |
3 |
Correct |
439 ms |
26940 KB |
Output is correct |
4 |
Correct |
435 ms |
26840 KB |
Output is correct |
5 |
Correct |
436 ms |
26956 KB |
Output is correct |
6 |
Correct |
430 ms |
26904 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 |
256 ms |
24884 KB |
Output is correct |
14 |
Correct |
258 ms |
24876 KB |
Output is correct |
15 |
Correct |
246 ms |
24852 KB |
Output is correct |
16 |
Correct |
256 ms |
24824 KB |
Output is correct |
17 |
Correct |
324 ms |
26468 KB |
Output is correct |
18 |
Correct |
325 ms |
26284 KB |
Output is correct |
19 |
Correct |
325 ms |
26364 KB |
Output is correct |
20 |
Correct |
325 ms |
26264 KB |
Output is correct |
21 |
Correct |
327 ms |
26332 KB |
Output is correct |
22 |
Correct |
320 ms |
26264 KB |
Output is correct |
23 |
Correct |
336 ms |
26452 KB |
Output is correct |
24 |
Correct |
320 ms |
26320 KB |
Output is correct |
25 |
Correct |
432 ms |
26952 KB |
Output is correct |
26 |
Correct |
438 ms |
26980 KB |
Output is correct |
27 |
Correct |
356 ms |
26776 KB |
Output is correct |
28 |
Correct |
346 ms |
26624 KB |
Output is correct |
29 |
Correct |
348 ms |
26644 KB |
Output is correct |
30 |
Correct |
355 ms |
26708 KB |
Output is correct |
31 |
Correct |
358 ms |
26748 KB |
Output is correct |
32 |
Correct |
334 ms |
26328 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |