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>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll
const int N = 5e5 + 10;
int a[N];
pair<int, int> par[N];
inline int get(int id, int t) {
return -id + (t / par[id].F) * par[id].S;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
par[0] = {1, 1};
for (int i = 1; i <= n; i++) {
int cnt = (a[i] + par[i - 1].S - 1) / par[i - 1].S;
par[i] = {par[i - 1].F * cnt, par[i - 1].S * cnt};
//cout << par[i].F << ' ' << par[i].S << '\n';
}
for (int i = 0; i < q; i++) {
int l, r, t;
cin >> t >> l >> r;
if (get(0, t) < l || get(n, t) > r) {
cout << 0 << '\n';
continue;
}
int lo1 = 0, hi1 = n + 1;
while (hi1 - lo1 > 1) {
int mid = (lo1 + hi1) / 2;
if (get(mid, t) >= l) {
lo1 = mid;
}
else {
hi1 = mid;
}
}
int lo2 = -1, hi2 = n;
while (hi2 - lo2 > 1) {
int mid = (lo2 + hi2) / 2;
if (get(mid, t) <= r) {
hi2 = mid;
}
else {
lo2 = mid;
}
}
//cout << lo1 << ' ' << hi2 << '\n';
cout << lo1 - hi2 + 1 << '\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... |