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;
#define int long long
const int N = 5e5 + 5;
int d[N], n, q;
int solveTestCase() {
cin >> n >> q;
d[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> d[i];
d[i] = d[i] / d[i - 1] * d[i - 1] + (d[i] % d[i - 1] ? d[i - 1] : 0);
}
while (q--) {
int t, l, r;
cin >> t >> l >> r;
int low = 0, high = n, ans1 = n + 1, ans2 = n + 1;
while (low <= high) {
int mid = (low + high) / 2;
int val = -mid + t / d[mid] * d[mid];
if (-mid + t / d[mid] * d[mid] <= r)
high = mid - 1, ans1 = mid;
else
low = mid + 1;
}
low = 0, high = n;
while (low <= high) {
int mid = (low + high) / 2;
int val = -mid + t / d[mid] * d[mid];
if (-mid + t / d[mid] * d[mid] < l)
high = mid - 1, ans2 = mid;
else
low = mid + 1;
}
cout << ans2 - ans1 << "\n";
}
return 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int test = 1;
// cin >> test;
while (test--)
solveTestCase();
}
Compilation message (stderr)
worst_reporter3.cpp: In function 'long long int solveTestCase()':
worst_reporter3.cpp:23:17: warning: unused variable 'val' [-Wunused-variable]
23 | int val = -mid + t / d[mid] * d[mid];
| ^~~
worst_reporter3.cpp:33:17: warning: unused variable 'val' [-Wunused-variable]
33 | int val = -mid + t / d[mid] * d[mid];
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |