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 N = 1007;
const int T = 1007;
int pos[T][N];
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;
for (int i = 0; i < n; ++i) pos[0][i] = -i;
for (int t = 1; t < T; ++t) {
for (int i = 0; i < n; ++i) {
pos[t][i] = pos[t - 1][i];
}
++pos[t][0];
for (int i = 1; i < n; ++i) {
if (pos[t][i - 1] - pos[t][i] > d[i]) {
pos[t][i] = pos[t][i - 1] - 1;
}
}
}
while (q--) {
int t, l, r;
cin >> t >> l >> r;
int ans = 0;
for (int i = 0; i < n; ++i) if (l <= pos[t][i] && pos[t][i] <= r) ++ans;
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... |