# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47466 | mirbek01 | Worst Reporter 3 (JOI18_worst_reporter3) | C++17 | 1519 ms | 15500 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# 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(){
scanf("%lld %lld", &n, &q);
int cn = 0;
for(int i = 1; i <= n; i ++){
scanf("%lld", &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;
scanf("%d %d %d", &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) {
puts("0");
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) {
puts("0");
continue;
}
L = hi;
printf("%d\n", R - L + 1);
}
}
/**
3 1
2
5
3
2 2 4
**/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |