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 = 500005;
int n, m;
int d[N];
long long a[N];
vector< vector<int> > vec;
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
a[0] = 1;
for (int i = 1; i <= n; ++i) {
cin >> d[i];
int tmp = (d[i] + (a[i - 1] - 1)) / a[i - 1];
a[i] = tmp * a[i - 1];
}
vector<int> cur;
cur.push_back(0);
for (int i = 1; i <= n; ++i) {
if (a[i] != a[cur.back()]) {
vec.push_back(cur), cur.clear();
}
cur.push_back(i);
}
vec.push_back(cur);
for (int i = 1; i <= m; ++i) {
int t, l, r; cin >> t >> l >> r;
int res = 0;
for (int j = 0; j < vec.size(); ++j) {
int tmp = t / a[vec[j][0]] * a[vec[j][0]];
int l0 = -vec[j].back(), r0 = -vec[j][0];
int l1 = l - tmp, r1 = r - tmp;
l0 = max(l0, l1), r0 = min(r0, r1);
res += max(0, r0 - l0 + 1);
}
cout << res << '\n';
}
}
Compilation message (stderr)
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:33:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < vec.size(); ++j) {
~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |