#include "bits/stdc++.h"
using namespace std;
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
using ll = long long;
ll d[500005];
ll movedist[500005];
ll period[500005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
int n, q; cin >> n >> q;
movedist[0] = 1;
period[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> d[i];
// how many the prev one moes
if (movedist[i - 1] >= d[i]) {
movedist[i] = movedist[i - 1];
period[i] = period[i - 1];
} else {
ll towait = (d[i] + movedist[i - 1] - 1) / movedist[i - 1];
movedist[i] = towait * movedist[ i- 1];
period[i] = towait * period [i - 1];
}
}
for (int i = 1; i <= q; i++) {
ll l, r, t; cin >> t >> l >> r;
ll L = 0, R = n;
ll ans = -1;
while (L <= R) {
ll mid = ( L + R) >> 1;
if (-mid + (t / period[mid]) * movedist[mid] >= l) {
ans = max(ans, mid);
L = mid + 1;
} else R = mid - 1;
}
if (ans == -1) {
cout << "0\n";
continue;
}
ll ans2 = LLONG_MAX;
L = 0, R = n;
while (L <= R) {
ll mid = ( L + R) >> 1;
if (-mid + (t / period[mid]) * movedist[mid] <= r) {
ans2 = min(ans2, mid);
R = mid - 1;
} else L = mid + 1;
}
if (ans2 == LLONG_MAX) {
cout << "0\n";
continue;
}
cout << ans - ans2 + 1 << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
545 ms |
14968 KB |
Output is correct |
2 |
Correct |
581 ms |
30420 KB |
Output is correct |
3 |
Correct |
582 ms |
30604 KB |
Output is correct |
4 |
Correct |
551 ms |
30528 KB |
Output is correct |
5 |
Correct |
533 ms |
30516 KB |
Output is correct |
6 |
Correct |
594 ms |
30596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
545 ms |
14968 KB |
Output is correct |
2 |
Correct |
581 ms |
30420 KB |
Output is correct |
3 |
Correct |
582 ms |
30604 KB |
Output is correct |
4 |
Correct |
551 ms |
30528 KB |
Output is correct |
5 |
Correct |
533 ms |
30516 KB |
Output is correct |
6 |
Correct |
594 ms |
30596 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
297 ms |
29152 KB |
Output is correct |
14 |
Correct |
325 ms |
29644 KB |
Output is correct |
15 |
Correct |
284 ms |
28276 KB |
Output is correct |
16 |
Correct |
310 ms |
28788 KB |
Output is correct |
17 |
Correct |
396 ms |
33068 KB |
Output is correct |
18 |
Correct |
370 ms |
32984 KB |
Output is correct |
19 |
Correct |
405 ms |
33116 KB |
Output is correct |
20 |
Correct |
404 ms |
33012 KB |
Output is correct |
21 |
Correct |
417 ms |
33188 KB |
Output is correct |
22 |
Correct |
397 ms |
33120 KB |
Output is correct |
23 |
Correct |
378 ms |
32976 KB |
Output is correct |
24 |
Correct |
374 ms |
33192 KB |
Output is correct |
25 |
Correct |
541 ms |
30476 KB |
Output is correct |
26 |
Correct |
537 ms |
30528 KB |
Output is correct |
27 |
Correct |
417 ms |
32576 KB |
Output is correct |
28 |
Correct |
418 ms |
32980 KB |
Output is correct |
29 |
Correct |
408 ms |
32480 KB |
Output is correct |
30 |
Correct |
419 ms |
32664 KB |
Output is correct |
31 |
Correct |
421 ms |
32928 KB |
Output is correct |
32 |
Correct |
410 ms |
29068 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |