#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define rep(a, b, c) for (int a = (b); (a) <= (c); ++a)
#define per(a, b, c) for (int a = (b); (a) >= (c); --a)
#define nl '\n'
#define ioi exit(0);
using namespace std;
const int MAX_N = (int)5e5 + 7;
int n, q;
int d[MAX_N], l[MAX_N], r[MAX_N], t[MAX_N], ans[MAX_N];
map <int, vector <int> > off;
void solve(int T, vector <int> &qr) {
vector <int> a;
a.pb(T);
rep(i, 1, n) {
int p = -i;
while (a.back() - p > d[i]) p += d[i];
if (i > 1 && a.back() + i > d[i]) p = a.back() - 1;
a.pb(p);
}
reverse(all(a));
/* for (auto it : a) cerr << it << ' ';
cerr << nl; */
for (auto it : qr) {
int L = l[it], R = r[it];
ans[it] = upper_bound(all(a), R) - lower_bound(all(a), L);
}
}
int main() {
#ifdef IOI
freopen ("in.txt", "r", stdin);
#endif
ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> q;
rep(i, 1, n) cin >> d[i];
rep(i, 1, q) {
cin >> t[i] >> l[i] >> r[i];
off[t[i]].pb(i);
}
for (auto it : off) {
solve(it.f, it.s);
}
rep(i, 1, q) {
cout << ans[i] << nl;
}
ioi
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2043 ms |
65268 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Incorrect |
8 ms |
504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2043 ms |
65268 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |