# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47436 | mirbek01 | Worst Reporter 3 (JOI18_worst_reporter3) | C++17 | 358 ms | 19704 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];
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 ++;
}
if(cn == n){
for(int i = 1; i <= q; i ++){
int t, l, r;
scanf("%d %d %d", &t, &l, &r);
int L = t - n - 1, R = t;
if(l <= L && R <= r){
printf("%d\n", R - L + 1);
continue;
}
if(l <= L && L <= r){
printf("%d\n", r - L + 1);
continue;
}
if(l <= R && R <= r){
printf("%d\n", R - l + 1);
continue;
}
printf("0\n");
}
return 0;
}
for(int i = 2; i <= n; i ++){
int lo = 1, hi = 1e9;
while(hi - lo > 1){
int md = (lo + hi) >> 1;
if(d[i - 1] * md + (-(i - 1)) >= d[i])
hi = md;
else
lo = md;
}
if(d[i - 1] * lo + (-(i - 1)) >= d[i]) hi = lo;
d[i] = d[i - 1] * hi + (-(i - 1)) - 1 - (-i);
}
for(int i = 1; i <= q; i ++){
int t, l, r;
scanf("%d %d %d", &t, &l, &r);
p[0] = t;
for(int j = 1; j <= n; j ++){
p[j] = -j;
int lo = 0, hi = 1000;
while(hi - lo > 1){
int md = (lo + hi) >> 1;
if(md * d[j] + p[j] < p[j - 1])
lo = md;
else
hi = md;
}
if(hi * d[j] + p[j] < p[j - 1]) lo = hi;
p[j] = lo * d[j] + p[j];
}
int cn = 0;
for(int j = 0; j <= n; j ++)
if(l <= p[j] && p[j] <= r) cn ++;
printf("%d\n", cn);
}
}
/**
3 6
2
5
3
6 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... |