#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define gcd __gcd
#define endl '\n'
const int N=500050,M=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll n, q, d[N], u[N], t, l, r;
ll pos(ll i, ll t){return t/u[i]*u[i]-i;}
ll lower(ll t, ll x){
ll l=-1, r=n+1;
while(r-l>1){
ll m=l+r>>1;
if(pos(m, t)<=x) r=m;
else l=m;
}
return r;
}
ll upper(ll t, ll x){
ll l=-1, r=n+1;
while(r-l>1){
ll m=l+r>>1;
if(pos(m, t)>=x) l=m;
else r=m;
}
return l;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n>>q;
for(ll i=1; i<=n; ++i) cin>>d[i];
u[0]=1;
for(ll i=1; i<=n; ++i){
ll need=(d[i]+u[i-1]-1)/u[i-1];
u[i]=need*u[i-1];
// cout<<u[i]<<endl;
}
while(q--){
cin>>t>>l>>r;
ll up=upper(t, l);
ll lo=lower(t, r);
cout<<up-lo+1<<endl;
// cout<<lo<<" "<<up<<endl;
}
return 0;
}
Compilation message
worst_reporter3.cpp: In function 'll lower(ll, ll)':
worst_reporter3.cpp:20:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | ll m=l+r>>1;
| ~^~
worst_reporter3.cpp: In function 'll upper(ll, ll)':
worst_reporter3.cpp:30:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | ll m=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
459 ms |
16956 KB |
Output is correct |
2 |
Correct |
449 ms |
18004 KB |
Output is correct |
3 |
Correct |
458 ms |
17916 KB |
Output is correct |
4 |
Correct |
447 ms |
18096 KB |
Output is correct |
5 |
Correct |
448 ms |
18008 KB |
Output is correct |
6 |
Correct |
453 ms |
17932 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 |
459 ms |
16956 KB |
Output is correct |
2 |
Correct |
449 ms |
18004 KB |
Output is correct |
3 |
Correct |
458 ms |
17916 KB |
Output is correct |
4 |
Correct |
447 ms |
18096 KB |
Output is correct |
5 |
Correct |
448 ms |
18008 KB |
Output is correct |
6 |
Correct |
453 ms |
17932 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 |
319 ms |
16424 KB |
Output is correct |
14 |
Correct |
297 ms |
21124 KB |
Output is correct |
15 |
Correct |
294 ms |
15760 KB |
Output is correct |
16 |
Correct |
309 ms |
16192 KB |
Output is correct |
17 |
Correct |
344 ms |
14404 KB |
Output is correct |
18 |
Correct |
342 ms |
14392 KB |
Output is correct |
19 |
Correct |
374 ms |
12684 KB |
Output is correct |
20 |
Correct |
337 ms |
14428 KB |
Output is correct |
21 |
Correct |
346 ms |
14536 KB |
Output is correct |
22 |
Correct |
344 ms |
13148 KB |
Output is correct |
23 |
Correct |
344 ms |
14360 KB |
Output is correct |
24 |
Correct |
339 ms |
13240 KB |
Output is correct |
25 |
Correct |
478 ms |
17976 KB |
Output is correct |
26 |
Correct |
457 ms |
18120 KB |
Output is correct |
27 |
Correct |
387 ms |
28640 KB |
Output is correct |
28 |
Correct |
370 ms |
25152 KB |
Output is correct |
29 |
Correct |
365 ms |
28544 KB |
Output is correct |
30 |
Correct |
369 ms |
28696 KB |
Output is correct |
31 |
Correct |
376 ms |
28896 KB |
Output is correct |
32 |
Correct |
367 ms |
16464 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |