#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) >> 1 ;
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) >> 1, 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) >> 1, 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' ;
}
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
434 ms |
26944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
434 ms |
26944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |