#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 2e9;
int n;
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)/2;
if (a[mid].second + (t - t%a[mid].first) >= x) l = mid;
else r = mid-1;
}
// cout << "test " << x << " " << t << " " << l << endl;
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() {
ios::sync_with_stdio(0); cin.tie(0);
int q;
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});
// for (auto [x, y]:a) cout << x << " " << y << endl;
while (q--) {
int t, l, r;
cin >> t >> l >> r;
cout << cnt(l, t) - cnt(r+1, t) << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
3220 KB |
Output is correct |
2 |
Correct |
165 ms |
3412 KB |
Output is correct |
3 |
Correct |
157 ms |
3252 KB |
Output is correct |
4 |
Correct |
138 ms |
3412 KB |
Output is correct |
5 |
Correct |
142 ms |
3408 KB |
Output is correct |
6 |
Correct |
141 ms |
3408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
3220 KB |
Output is correct |
2 |
Correct |
165 ms |
3412 KB |
Output is correct |
3 |
Correct |
157 ms |
3252 KB |
Output is correct |
4 |
Correct |
138 ms |
3412 KB |
Output is correct |
5 |
Correct |
142 ms |
3408 KB |
Output is correct |
6 |
Correct |
141 ms |
3408 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
151 ms |
1224 KB |
Output is correct |
14 |
Correct |
157 ms |
1360 KB |
Output is correct |
15 |
Correct |
137 ms |
1364 KB |
Output is correct |
16 |
Correct |
149 ms |
1364 KB |
Output is correct |
17 |
Correct |
176 ms |
2640 KB |
Output is correct |
18 |
Correct |
182 ms |
2644 KB |
Output is correct |
19 |
Correct |
179 ms |
2744 KB |
Output is correct |
20 |
Correct |
173 ms |
2848 KB |
Output is correct |
21 |
Correct |
181 ms |
2648 KB |
Output is correct |
22 |
Correct |
183 ms |
2640 KB |
Output is correct |
23 |
Correct |
182 ms |
2848 KB |
Output is correct |
24 |
Correct |
197 ms |
2896 KB |
Output is correct |
25 |
Correct |
145 ms |
3440 KB |
Output is correct |
26 |
Correct |
147 ms |
3412 KB |
Output is correct |
27 |
Correct |
176 ms |
3160 KB |
Output is correct |
28 |
Correct |
170 ms |
3104 KB |
Output is correct |
29 |
Correct |
176 ms |
3156 KB |
Output is correct |
30 |
Correct |
176 ms |
3160 KB |
Output is correct |
31 |
Correct |
179 ms |
3012 KB |
Output is correct |
32 |
Correct |
152 ms |
2900 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |