#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 5e5 +50, LG = 36;
int n, q, m;
ll d[N];
pll P[LG];
int get(int x, ll t) {
int out = 0;
for (int i = 1; i <= m; i++) {
ll v = t-t%P[i].F;
if (P[i].S + v < x) break;
out += min(P[i].S+v-x+1, P[i].S-P[i+1].S);
}
return out;
}
void solve() {
cin >> n >> q;
d[0] = 1;
P[++m] = {1, 0};
for (int i = 1; i <= n; i++) {
cin >> d[i];
d[i] = ((d[i]+d[i-1]-1)/d[i-1])*d[i-1];
if (d[i] != d[i-1]) {
P[++m] = {d[i], -i};
}
}
P[m+1].S = -(n+1);
for (int i = 1; i <= q; i++) {
ll t, l, r;
cin >> t >> l >> r;
cout << get(l, t) - get(r+1, t) << endl;
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
7140 KB |
Output is correct |
2 |
Correct |
176 ms |
7148 KB |
Output is correct |
3 |
Correct |
184 ms |
7200 KB |
Output is correct |
4 |
Correct |
211 ms |
7212 KB |
Output is correct |
5 |
Correct |
200 ms |
7224 KB |
Output is correct |
6 |
Correct |
195 ms |
7124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
7140 KB |
Output is correct |
2 |
Correct |
176 ms |
7148 KB |
Output is correct |
3 |
Correct |
184 ms |
7200 KB |
Output is correct |
4 |
Correct |
211 ms |
7212 KB |
Output is correct |
5 |
Correct |
200 ms |
7224 KB |
Output is correct |
6 |
Correct |
195 ms |
7124 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 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 |
201 ms |
21044 KB |
Output is correct |
14 |
Correct |
212 ms |
21780 KB |
Output is correct |
15 |
Correct |
198 ms |
20440 KB |
Output is correct |
16 |
Correct |
182 ms |
20916 KB |
Output is correct |
17 |
Correct |
278 ms |
25260 KB |
Output is correct |
18 |
Correct |
261 ms |
25164 KB |
Output is correct |
19 |
Correct |
291 ms |
25224 KB |
Output is correct |
20 |
Correct |
278 ms |
25212 KB |
Output is correct |
21 |
Correct |
283 ms |
25260 KB |
Output is correct |
22 |
Correct |
279 ms |
25352 KB |
Output is correct |
23 |
Correct |
276 ms |
25164 KB |
Output is correct |
24 |
Correct |
272 ms |
25256 KB |
Output is correct |
25 |
Correct |
191 ms |
22812 KB |
Output is correct |
26 |
Correct |
217 ms |
22608 KB |
Output is correct |
27 |
Correct |
276 ms |
24748 KB |
Output is correct |
28 |
Correct |
287 ms |
25060 KB |
Output is correct |
29 |
Correct |
291 ms |
24572 KB |
Output is correct |
30 |
Correct |
290 ms |
24732 KB |
Output is correct |
31 |
Correct |
328 ms |
25036 KB |
Output is correct |
32 |
Correct |
175 ms |
21324 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |