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;
typedef long long ll;
typedef long double ld;
const int K = 37;
int L[K], R[K];
const int N = 5e5 + 7;
int _time[N];
int _move[N];
const ll Inf = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, q;
cin >> n >> q;
vector <int> d(n + 1);
for (int i = 1; i <= n; ++i) cin >> d[i];
d[0] = 1;
++n;
int m;
{
vector <pair <int, int>> seg;
ll mv = 1;
int lst = 0;
ll ct = 1;
for (int i = 1; i < n; ++i) {
if (mv < d[i]) {
seg.push_back({lst, i - 1});
_time[(int)seg.size() - 1] = ct;
_move[(int)seg.size() - 1] = mv;
ct *= (d[i] + mv - 1) / mv;
ct = min(ct, Inf);
mv *= (d[i] + mv - 1) / mv;
mv = min(mv, Inf);
lst = i;
}
}
seg.push_back({lst, n - 1});
_time[(int)seg.size() - 1] = ct;
_move[(int)seg.size() - 1] = mv;
for (int i = 0; i < (int)seg.size(); ++i) L[i] = seg[i].first, R[i] = seg[i].second;
m = seg.size();
}
while (q--) {
int t, l, r;
cin >> t >> l >> r;
int ans = 0;
for (int i = 0; i < m; ++i) {
int ps = t / _time[i];
ll pl = -L[i] + (ll)ps * _move[i];
ll pr = -R[i] + (ll)ps * _move[i];
swap(pl, pr);
pl = max(pl, (ll)l);
pr = min(pr, (ll)r);
ans += max(0LL, pr - pl + 1);
}
cout << ans << '\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... |