// In the name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 5e5 + 4;
int n, q;
ll D[maxn], valx[maxn];
ll get_pos(int j, ll tx) {
ll Rx = (tx / valx[j]);
return (Rx * valx[j]) - j;
}
bool okx(int x, ll dx, ll tx) {
int j = (n - x);
return (get_pos(j, tx) <= dx);
}
int getx(ll dx, ll tx) {
int l = 0, r = n + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
if (okx(mid, dx, tx)) l = mid;
else r = mid;
}
return l;
}
void solve() {
cin >> n >> q; n++; valx[0] = 1;
for (int i = 1; i < n; i++) cin >> D[i];
for (int i = 1; i < n; i++) {
valx[i] = D[i];
if (valx[i] % valx[i - 1] != 0) {
valx[i] += (valx[i - 1] - (valx[i] % valx[i - 1]));
}
}
while (q--) {
ll tx, lx, rx;
cin >> tx >> lx >> rx;
cout << getx(rx, tx) - getx(lx - 1, tx) << endl;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
while (T--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |