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;
#define int long long
int n , q;
int d[1000000];
int x[1000000];
int read(){
char c;
int a = 0;
while(!(c >= '0' && c <= '9')) c = getchar();
while(c >= '0' && c<='9'){
a = 10*a + (c - '0');
c =getchar();
}
return a;
}
int cima(int i , int j){
if(i%j) return i/j + 1;
else return i/j;
}
int32_t main(){
n = read() , q =read();
for(int i = 1 ; i <= n; i++) d[i] = read();
x[1] = d[1];
for(int i = 2 ; i <= n; i++){
x[i] = (x[i-1]) * (cima(d[i] , x[i-1]));
}
while(q--){
int l , r ,t;
t = read();
int def = 0;
l = read() , r = read();
int ll = 1 , rr = n;
int ansj = n+1;
if(l <= t && t <= r) def++;
while(ll<=rr) {
int mid = (ll+rr)/2;
int p = t / x[mid];
if(p*x[mid] - mid < l){
ansj = mid;
rr = mid - 1;
}
else ll = mid + 1;
}
int ansj2 =0;
ll = 1 , rr = n;
while(ll<=rr){
int mid = (ll+rr)/2;
int p = t/x[mid];
if(p*x[mid] - mid > r){
ansj2 = mid ;
ll = mid + 1;
}
else rr = mid - 1;
}
def += n;
if(ansj2) def -= ansj2;
if(ansj != (n + 1)){
def -= (n - ansj + 1);
}
cout<<def<<endl;
}
}
Compilation message (stderr)
worst_reporter3.cpp: In function 'long long int read()':
worst_reporter3.cpp:10:8: warning: 'c' is used uninitialized in this function [-Wuninitialized]
while(!(c >= '0' && c <= '9')) c = getchar();
^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |