# include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 2;
long long n, q, d[N], p[N], ti[N], inf = 2e9;
int main(){
cin >> n >> q;
int cn = 0;
for(int i = 1; i <= n; i ++){
cin >> d[i];
if(d[i] == 1) cn ++;
}
for(int i = 1; i <= n; i ++){
p[i] = -i;
}
ti[0] = 1;
d[0] = 1;
ti[1] = d[1];
for(int i = 2; i <= n; i ++){
int lo = 0, hi = 1e9;
while(hi - lo > 1){
int md = (lo + hi) >> 1;
if((p[i - 1] + d[i - 1] * md - p[i]) > d[i])
hi = md;
else
lo = md;
}
if((p[i - 1] + d[i - 1] * lo - p[i]) > d[i]) hi = lo;
d[i] = p[i - 1] + d[i - 1] * hi - 1 - p[i];
ti[i] = min(hi * ti[i - 1], inf);
}
for(int i = 1; i <= q; i ++){
int t, l, r;
cin >> t >> l >> r;
int L, R;
int lo = 0, hi = n;
while(hi - lo > 1){
int md = (lo + hi) >> 1;
if(t / ti[md] * d[md] + p[md] >= l)
lo = md;
else
hi = md;
}
if(t / ti[hi] * d[hi] + p[hi] >= l) lo = hi;
if(t / ti[lo] * d[lo] + p[lo] < l) {
cout << 0 << endl;
continue;
}
R = lo;
lo = 0, hi = n;
while(hi - lo > 1){
int md = (lo + hi) >> 1;
if(t / ti[md] * d[md] + p[md] <= r)
hi = md;
else
lo = md;
}
if(t / ti[lo] * d[lo] + p[lo] <= r) hi = lo;
if(t / ti[hi] * d[hi] + p[hi] > r) {
cout << 0 << endl;
continue;
}
L = hi;
cout << R - L + 1 << endl;
}
}
/**
3 1
2
5
3
2 2 4
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2073 ms |
14296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
14296 KB |
Output is correct |
2 |
Correct |
7 ms |
14296 KB |
Output is correct |
3 |
Correct |
6 ms |
14296 KB |
Output is correct |
4 |
Correct |
5 ms |
14296 KB |
Output is correct |
5 |
Correct |
6 ms |
14296 KB |
Output is correct |
6 |
Correct |
5 ms |
14296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2073 ms |
14296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |