#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;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
901 ms |
11084 KB |
Output is correct |
2 |
Correct |
909 ms |
13060 KB |
Output is correct |
3 |
Correct |
901 ms |
13076 KB |
Output is correct |
4 |
Correct |
1029 ms |
12980 KB |
Output is correct |
5 |
Correct |
960 ms |
12992 KB |
Output is correct |
6 |
Correct |
959 ms |
13040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
901 ms |
11084 KB |
Output is correct |
2 |
Correct |
909 ms |
13060 KB |
Output is correct |
3 |
Correct |
901 ms |
13076 KB |
Output is correct |
4 |
Correct |
1029 ms |
12980 KB |
Output is correct |
5 |
Correct |
960 ms |
12992 KB |
Output is correct |
6 |
Correct |
959 ms |
13040 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 |
719 ms |
10952 KB |
Output is correct |
14 |
Correct |
713 ms |
11036 KB |
Output is correct |
15 |
Correct |
752 ms |
10956 KB |
Output is correct |
16 |
Correct |
743 ms |
11028 KB |
Output is correct |
17 |
Correct |
782 ms |
12516 KB |
Output is correct |
18 |
Correct |
825 ms |
12516 KB |
Output is correct |
19 |
Correct |
778 ms |
11504 KB |
Output is correct |
20 |
Correct |
801 ms |
12480 KB |
Output is correct |
21 |
Correct |
879 ms |
12424 KB |
Output is correct |
22 |
Correct |
830 ms |
12580 KB |
Output is correct |
23 |
Correct |
805 ms |
12564 KB |
Output is correct |
24 |
Correct |
793 ms |
12476 KB |
Output is correct |
25 |
Correct |
922 ms |
13072 KB |
Output is correct |
26 |
Correct |
918 ms |
13024 KB |
Output is correct |
27 |
Correct |
823 ms |
10996 KB |
Output is correct |
28 |
Correct |
843 ms |
12712 KB |
Output is correct |
29 |
Correct |
817 ms |
10924 KB |
Output is correct |
30 |
Correct |
828 ms |
10988 KB |
Output is correct |
31 |
Correct |
849 ms |
10832 KB |
Output is correct |
32 |
Correct |
847 ms |
12556 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |