#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n,q,a,b,t;
cin >> n >> q;
vector<long long> haha(n+1,1);
for(long long i = 1; i <= n; i++) {
cin >> haha[i];
haha[i] = haha[i-1]*((haha[i]+haha[i-1]-1)/haha[i-1]);
haha[i] = min(haha[i],(long long)INT_MAX);
}
for(long long i = 0; i < q; i++) {
cin >> t >> a >> b;
long long c = a,ans = 0;
if(t >= c) {
long long l = 0,r = haha.size()-1;
while(l < r) {
long long mid = (l+r+1)/2;
if(-mid+haha[mid]*(t/haha[mid]) >= c) {
l = mid;
}
else {
r = mid-1;
}
}
ans+=l+1;
}
c = b+1;
if(t >= c) {
long long l = 0,r = haha.size()-1;
while(l < r) {
long long mid = (l+r+1)/2;
if(-mid+haha[mid]*(t/haha[mid]) >= c) {
l = mid;
}
else {
r = mid-1;
}
}
ans-=l+1;
}
cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
309 ms |
7252 KB |
Output is correct |
2 |
Correct |
319 ms |
7248 KB |
Output is correct |
3 |
Correct |
339 ms |
7472 KB |
Output is correct |
4 |
Correct |
308 ms |
7192 KB |
Output is correct |
5 |
Correct |
313 ms |
7368 KB |
Output is correct |
6 |
Correct |
303 ms |
7508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
309 ms |
7252 KB |
Output is correct |
2 |
Correct |
319 ms |
7248 KB |
Output is correct |
3 |
Correct |
339 ms |
7472 KB |
Output is correct |
4 |
Correct |
308 ms |
7192 KB |
Output is correct |
5 |
Correct |
313 ms |
7368 KB |
Output is correct |
6 |
Correct |
303 ms |
7508 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
185 ms |
21284 KB |
Output is correct |
14 |
Correct |
173 ms |
21820 KB |
Output is correct |
15 |
Correct |
164 ms |
20560 KB |
Output is correct |
16 |
Correct |
171 ms |
21072 KB |
Output is correct |
17 |
Correct |
246 ms |
25168 KB |
Output is correct |
18 |
Correct |
250 ms |
25172 KB |
Output is correct |
19 |
Correct |
260 ms |
25224 KB |
Output is correct |
20 |
Correct |
280 ms |
25272 KB |
Output is correct |
21 |
Correct |
272 ms |
25364 KB |
Output is correct |
22 |
Correct |
241 ms |
25428 KB |
Output is correct |
23 |
Correct |
238 ms |
25172 KB |
Output is correct |
24 |
Correct |
254 ms |
25424 KB |
Output is correct |
25 |
Correct |
307 ms |
22792 KB |
Output is correct |
26 |
Correct |
312 ms |
22712 KB |
Output is correct |
27 |
Correct |
308 ms |
24780 KB |
Output is correct |
28 |
Correct |
284 ms |
25168 KB |
Output is correct |
29 |
Correct |
245 ms |
24656 KB |
Output is correct |
30 |
Correct |
257 ms |
24832 KB |
Output is correct |
31 |
Correct |
255 ms |
25104 KB |
Output is correct |
32 |
Correct |
236 ms |
21632 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |