#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[500005], n, q;
int f(int t, int x)
{
int l=0, r=n+1;
while (l<r)
{
int m=(l+r)/2;
if (t/a[m]*a[m]-m<=x)
r=m;
else
l=m+1;
}
return n-r+2;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
a[0]=1;
for (int i=1; i<=n; i++)
{
cin >> a[i];
a[i]=((a[i]-1)/a[i-1]+1)*a[i-1];
}
for (int i=1; i<=q; i++)
{
int t, l, r;
cin >> t >> l >> r;
cout << f(t, r)-f(t, l-1) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
555 ms |
22396 KB |
Output is correct |
2 |
Correct |
573 ms |
22700 KB |
Output is correct |
3 |
Correct |
528 ms |
22648 KB |
Output is correct |
4 |
Correct |
522 ms |
22604 KB |
Output is correct |
5 |
Correct |
519 ms |
22684 KB |
Output is correct |
6 |
Correct |
531 ms |
22600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
555 ms |
22396 KB |
Output is correct |
2 |
Correct |
573 ms |
22700 KB |
Output is correct |
3 |
Correct |
528 ms |
22648 KB |
Output is correct |
4 |
Correct |
522 ms |
22604 KB |
Output is correct |
5 |
Correct |
519 ms |
22684 KB |
Output is correct |
6 |
Correct |
531 ms |
22600 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
359 ms |
21204 KB |
Output is correct |
14 |
Correct |
307 ms |
21800 KB |
Output is correct |
15 |
Correct |
323 ms |
20428 KB |
Output is correct |
16 |
Correct |
318 ms |
20968 KB |
Output is correct |
17 |
Correct |
428 ms |
25160 KB |
Output is correct |
18 |
Correct |
428 ms |
25192 KB |
Output is correct |
19 |
Correct |
381 ms |
25300 KB |
Output is correct |
20 |
Correct |
395 ms |
25232 KB |
Output is correct |
21 |
Correct |
387 ms |
25224 KB |
Output is correct |
22 |
Correct |
408 ms |
25216 KB |
Output is correct |
23 |
Correct |
401 ms |
25164 KB |
Output is correct |
24 |
Correct |
400 ms |
25280 KB |
Output is correct |
25 |
Correct |
559 ms |
22696 KB |
Output is correct |
26 |
Correct |
653 ms |
22600 KB |
Output is correct |
27 |
Correct |
469 ms |
24728 KB |
Output is correct |
28 |
Correct |
434 ms |
25104 KB |
Output is correct |
29 |
Correct |
447 ms |
24968 KB |
Output is correct |
30 |
Correct |
519 ms |
24812 KB |
Output is correct |
31 |
Correct |
439 ms |
25100 KB |
Output is correct |
32 |
Correct |
399 ms |
21344 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |