#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
vector<pair<int,int>> a;
int cnt(int x, int t) {
int l = 0, r = a.size() - 2;
while (l < r) {
int mid = l + r + 1 >> 1;
if (a[mid].second + (t - t % a[mid].first) >= x) l = mid;
else r = mid - 1;
}
int pos = a[l].second + (t - t % a[l].first);
if (pos < x) return 0;
return min(pos - x, a[l].second - a[l+1].second-1) + (-a[l].second + 1);
}
signed main() {
int q, n;
cin >> n >> q;
int cur = 0;
a.push_back({1, 0});
for (int i = 1;i <= n; i++) {
int x;
cin >> x;
if (x > cur && cur <= INF) {
if (cur == 0) cur = x;
else cur = ((x + cur - 1) / cur) * cur;
if (cur <= INF) a.push_back({cur, -i});
}
}
a.push_back({1e18, -n - 1});
while (q--) {
int t, l, r;
cin >> t >> l >> r;
cout << cnt(l, t) - cnt(r + 1, t) << "\n";
}
}
Compilation message
worst_reporter3.cpp: In function 'int cnt(int, int)':
worst_reporter3.cpp:8:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
8 | int mid = l + r + 1 >> 1;
| ~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
948 ms |
18772 KB |
Output is correct |
2 |
Correct |
968 ms |
18852 KB |
Output is correct |
3 |
Correct |
985 ms |
18820 KB |
Output is correct |
4 |
Correct |
956 ms |
18772 KB |
Output is correct |
5 |
Correct |
1027 ms |
18832 KB |
Output is correct |
6 |
Correct |
965 ms |
18772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
948 ms |
18772 KB |
Output is correct |
2 |
Correct |
968 ms |
18852 KB |
Output is correct |
3 |
Correct |
985 ms |
18820 KB |
Output is correct |
4 |
Correct |
956 ms |
18772 KB |
Output is correct |
5 |
Correct |
1027 ms |
18832 KB |
Output is correct |
6 |
Correct |
965 ms |
18772 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1004 ms |
17328 KB |
Output is correct |
14 |
Correct |
991 ms |
17748 KB |
Output is correct |
15 |
Correct |
954 ms |
16492 KB |
Output is correct |
16 |
Correct |
966 ms |
17160 KB |
Output is correct |
17 |
Correct |
1123 ms |
21332 KB |
Output is correct |
18 |
Correct |
1086 ms |
21404 KB |
Output is correct |
19 |
Correct |
1049 ms |
21332 KB |
Output is correct |
20 |
Correct |
1041 ms |
21332 KB |
Output is correct |
21 |
Correct |
1049 ms |
21328 KB |
Output is correct |
22 |
Correct |
1151 ms |
21588 KB |
Output is correct |
23 |
Correct |
1051 ms |
21364 KB |
Output is correct |
24 |
Correct |
1141 ms |
21420 KB |
Output is correct |
25 |
Correct |
966 ms |
18768 KB |
Output is correct |
26 |
Correct |
1006 ms |
18772 KB |
Output is correct |
27 |
Correct |
1027 ms |
20816 KB |
Output is correct |
28 |
Correct |
1052 ms |
21264 KB |
Output is correct |
29 |
Correct |
1034 ms |
20760 KB |
Output is correct |
30 |
Correct |
1018 ms |
20820 KB |
Output is correct |
31 |
Correct |
1044 ms |
21160 KB |
Output is correct |
32 |
Correct |
921 ms |
17492 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |