# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110140 | IOrtroiii | Worst Reporter 3 (JOI18_worst_reporter3) | C++14 | 687 ms | 27504 KiB |
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;
const int N = 500500;
int d[N];
long long a[N];
int main() {
int n, q; scanf("%d %d", &n, &q);
a[0] = 1;
for (int i = 1; i <= n; ++i) {
scanf("%d", d + i);
a[i] = (a[i - 1] - 1 + d[i]) / a[i - 1] * a[i - 1];
}
int l = 0;
vector< pair<int, int> > segs;
while (l <= n) {
int r = l;
while (r < n && a[l] == a[r + 1]) r++;
segs.push_back({l, r});
l = r + 1;
}
while (q--) {
int t, l, r; scanf("%d %d %d", &t, &l, &r);
int ans = 0;
for (auto p : segs) {
int l0 = p.second, r0 = p.first;
int nw = t / a[l0] * a[l0];
l0 = max(-l0, l - nw), r0 = min(-r0, r - nw);
ans += max(0, r0 - l0 + 1);
}
printf("%d\n", ans);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |