#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
cin.tie(0); ios_base::sync_with_stdio(0);
int n, q;
cin >> n >> q;
int d[n];
for(int i=0; i<n; i++){
cin >> d[i];
}
int cyc[n+1];
int running=1;
for(int i=0; i<=n; i++){
if(running <= 1000000000){
cyc[i] = running;
running *= d[i]/running + (d[i]%running != 0);
}
else{
cyc[i] = 2000000000;
}
}
while(q--){
int t, l, r;
cin >> t >> l >> r;
int lo=0, hi=n, m1;
while(lo<hi){
m1 = (lo+hi)/2;
if(hi-lo == 1) m1++;
int ccyc = cyc[m1];
int tra = (t/ccyc) * ccyc;
tra -= m1;
if(tra < l){
hi = m1-1;
}
else if(tra > l){
lo = m1;
}
else{
lo = m1;
hi = m1;
}
}
m1 = lo;
if(m1 == 0 && t<l){
m1--;
}
lo = 0;
hi = n;
int m2 = lo;
while(lo<hi){
m2 = (lo+hi)/2;
if(hi-lo == 1) m2++;
int ccyc = cyc[m2];
int tra = (t/ccyc) * ccyc;
tra -= m2;
if(tra <= r){
hi = m2-1;
}
else{
lo = m2;
}
}
m2 = lo;
if(m2 == 0 && t<=r){
m2--;
}
cout << m1-m2 << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
19844 KB |
Output is correct |
2 |
Correct |
434 ms |
19060 KB |
Output is correct |
3 |
Correct |
430 ms |
19024 KB |
Output is correct |
4 |
Correct |
436 ms |
19348 KB |
Output is correct |
5 |
Correct |
458 ms |
19316 KB |
Output is correct |
6 |
Correct |
441 ms |
19108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
19844 KB |
Output is correct |
2 |
Correct |
434 ms |
19060 KB |
Output is correct |
3 |
Correct |
430 ms |
19024 KB |
Output is correct |
4 |
Correct |
436 ms |
19348 KB |
Output is correct |
5 |
Correct |
458 ms |
19316 KB |
Output is correct |
6 |
Correct |
441 ms |
19108 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 |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
253 ms |
23016 KB |
Output is correct |
14 |
Correct |
252 ms |
25912 KB |
Output is correct |
15 |
Correct |
234 ms |
24400 KB |
Output is correct |
16 |
Correct |
242 ms |
24916 KB |
Output is correct |
17 |
Correct |
317 ms |
29040 KB |
Output is correct |
18 |
Correct |
321 ms |
29432 KB |
Output is correct |
19 |
Correct |
318 ms |
29092 KB |
Output is correct |
20 |
Correct |
325 ms |
29472 KB |
Output is correct |
21 |
Correct |
325 ms |
29032 KB |
Output is correct |
22 |
Correct |
324 ms |
29264 KB |
Output is correct |
23 |
Correct |
324 ms |
29344 KB |
Output is correct |
24 |
Correct |
323 ms |
29172 KB |
Output is correct |
25 |
Correct |
441 ms |
26964 KB |
Output is correct |
26 |
Correct |
441 ms |
26804 KB |
Output is correct |
27 |
Correct |
362 ms |
28820 KB |
Output is correct |
28 |
Correct |
352 ms |
29264 KB |
Output is correct |
29 |
Correct |
350 ms |
28500 KB |
Output is correct |
30 |
Correct |
353 ms |
28752 KB |
Output is correct |
31 |
Correct |
362 ms |
29044 KB |
Output is correct |
32 |
Correct |
339 ms |
25172 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |