This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
const int N = 2e5 + 5;
int n, q, d[N];
void solve() {
cin >> n >> q;
vector<pair<pair<int, int>, pair<int, int> > > vec;
vec.pb({{1, 1}, {0, 0}});
d[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> d[i];
if (d[i] <= vec.back().fi.se) {
vec.back().se.fi--;
}
int c = (d[i] + vec.back().fi.se - 1) / vec.back().fi.se;
if (d[i] > vec.back().fi.se && c <= 1e9 / vec.back().fi.fi) {
vec.pb({{vec.back().fi.fi * c, c * vec.back().fi.se}, {-i, -i}});
}
}
while (q--) {
ll t, l, r; cin >> t >> l >> r;
int ans = 0;
for (auto [a, b] : vec) {
t /= a.fi;
t *= a.se;
ll lt = b.fi + t, rt = b.se + t;
ans += max(0LL, min(rt, r) - max(lt, l) + 1);
}
cout << ans << '\n';
}
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
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... |