# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242206 | tqbfjotld | Worst Reporter 3 (JOI18_worst_reporter3) | C++14 | 734 ms | 6136 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;
int n,q;
int arr[500005];
int func(int t, int person){
if (person==-1) return t;
if (person==-2) return 1000000005;
return (t/arr[person])*arr[person]-person-1;
}
int main(){
scanf("%d%d",&n,&q);
for (int x = 0; x<n; x++){
scanf("%d",&arr[x]);
}
for (int x = 1; x<n; x++){
arr[x] = ((arr[x]-1)/arr[x-1])*arr[x-1]+arr[x-1];
}
for (int x = 0; x<q; x++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
int lb,rb;
if (func(a,-1)<b){
printf("0\n");
continue;
}
if (func(a,n-1)>c){
printf("0\n");
continue;
}
int l = -1;
int r = n;
while (l+1<r){
int mid = (l+r)/2;
if (func(a,mid)>=b){
l = mid;
}
else r = mid;
}
lb = l;
l = -2;
r = n-1;
while (l+1<r){
int mid = (l+r)/2;
//printf("func mid %d\n",func(a,mid));
if (func(a,mid)<=c){
r = mid;
}
else{
l = mid;
}
}
rb = r;
//printf("func(rb): %d\n",func(a,rb));
printf("%d\n",lb-rb+1);
//printf("%d %d\n",lb,rb);
}
}
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... |