#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef stack<ll> sll;
typedef queue<ll> qll;
typedef deque<ll> dll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
// #define endl '\n'
#define pb push_back
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define BACK(i,a,b) for(int i = a; i >= b; i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define bp __builtin_popcountll
#define gcd __gcd
#define bit(i,n) ((n>>i)&1)
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
const int MAXN = (5e5)+5;
// const ll SQRT = 4;
const long long inf = 1e18;
const long long MOD = 1e9+7;
ll n,q,s[MAXN],d[MAXN],f[MAXN];
signed main()
{
fastIO
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>n>>q;
FOR(i,1,n) cin>>d[i];
f[0]=1;
FOR(i,1,n) f[i]=int((d[i]+f[i-1]-1)/f[i-1])*f[i-1];
while(q--)
{
int t,l,r,up,m;
cin>>t>>l>>r;
if(t<l) {cout<<0<<endl; continue;}
int lx=-1,rx=n+1;
while(lx<rx-1)
{
m=lx+rx>>1;
if(-m+(t/f[m])*f[m]<l) rx=m;
else lx=m;
}
up=lx;
lx=-1,rx=n+1;
while(lx<rx-1)
{
m=lx+rx>>1;
if(-m+(t/f[m])*f[m]>r) lx=m;
else rx=m;
}
cout<<up-rx+1<<endl;
}
}
Compilation message
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:53:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
53 | m=lx+rx>>1;
| ~~^~~
worst_reporter3.cpp:61:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | m=lx+rx>>1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
922 ms |
11092 KB |
Output is correct |
2 |
Correct |
903 ms |
11096 KB |
Output is correct |
3 |
Correct |
899 ms |
11160 KB |
Output is correct |
4 |
Correct |
887 ms |
11080 KB |
Output is correct |
5 |
Correct |
900 ms |
11124 KB |
Output is correct |
6 |
Correct |
964 ms |
11072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
922 ms |
11092 KB |
Output is correct |
2 |
Correct |
903 ms |
11096 KB |
Output is correct |
3 |
Correct |
899 ms |
11160 KB |
Output is correct |
4 |
Correct |
887 ms |
11080 KB |
Output is correct |
5 |
Correct |
900 ms |
11124 KB |
Output is correct |
6 |
Correct |
964 ms |
11072 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
757 ms |
9060 KB |
Output is correct |
14 |
Correct |
708 ms |
9088 KB |
Output is correct |
15 |
Correct |
737 ms |
9100 KB |
Output is correct |
16 |
Correct |
720 ms |
9064 KB |
Output is correct |
17 |
Correct |
793 ms |
10536 KB |
Output is correct |
18 |
Correct |
843 ms |
10472 KB |
Output is correct |
19 |
Correct |
783 ms |
10468 KB |
Output is correct |
20 |
Correct |
788 ms |
10664 KB |
Output is correct |
21 |
Correct |
788 ms |
10532 KB |
Output is correct |
22 |
Correct |
787 ms |
10564 KB |
Output is correct |
23 |
Correct |
838 ms |
10484 KB |
Output is correct |
24 |
Correct |
781 ms |
10548 KB |
Output is correct |
25 |
Correct |
943 ms |
11156 KB |
Output is correct |
26 |
Correct |
950 ms |
11044 KB |
Output is correct |
27 |
Correct |
836 ms |
10972 KB |
Output is correct |
28 |
Correct |
870 ms |
10872 KB |
Output is correct |
29 |
Correct |
838 ms |
10852 KB |
Output is correct |
30 |
Correct |
851 ms |
10988 KB |
Output is correct |
31 |
Correct |
844 ms |
10884 KB |
Output is correct |
32 |
Correct |
834 ms |
10560 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |