#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n;
vector<int> vect;
int calc(int t, int k){
int low=-1, high=n;
while (low+1<high){
int mid=(low+high)/2;
if (t/vect[mid]*vect[mid]-mid-1>=k)low=mid;
else high=mid;
}
return low;
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q, a, b, c;
cin>>n>>q;
vect.resize(n);
for (int i=0; i<n; ++i)cin>>vect[i];
for (int i=1; i<n; ++i)vect[i]=((vect[i]+vect[i-1]-1)/vect[i-1])*vect[i-1];
while (q--){
cin>>a>>b>>c;
cout<<calc(a, b)-calc(a, c+1)+(b<=a&&a<=c)<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |