#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// My bug list :
// integer overflow
// 0based, 1based forgotten
// index out of bound
// n, m, i, j typo
// some cases are missing
const int MAX_N = 500010;
int n, q;
// per[i] means how many step last one move, then I move
int D[MAX_N], v[MAX_N], per[MAX_N], len[MAX_N];
void init() {
v[0] = 1;
for (int i = 1;i <= n;++i) {
//per[i] = cdiv(D[i] - 1, v[i-1]);
per[i] = (D[i]-1) / v[i-1] + 1;
v[i] = per[i] * v[i-1];
}
for (int i = n;i >= 0;--i) {
len[i] = 1;
if (per[i+1] == 1) {
len[i] = len[i+1] + 1;
}
}
per[n+1] = 1;
}
int inter(int l1, int r1, int l2, int r2) {
chmax(l1, l2);
chmin(r1, r2);
return max(0, r1 - l1 + 1);
}
int qry(int t, int l, int r) {
int res = 0;
for (int i = 0;i <= n && t > 0;) {
int at = -i + t * v[i];
res += inter(at - len[i] + 1, at, l, r);
i += len[i];
if (i > n) break;
t /= per[i];
}
return res;
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> q;
for (int i = 1;i <= n;++i)
cin >> D[i];
init();
while (q--) {
int t, l, r;
cin >> t >> l >> r;
cout << qry(t, l, r) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
278 ms |
11028 KB |
Output is correct |
2 |
Correct |
291 ms |
11280 KB |
Output is correct |
3 |
Correct |
277 ms |
11200 KB |
Output is correct |
4 |
Correct |
289 ms |
11088 KB |
Output is correct |
5 |
Correct |
289 ms |
11084 KB |
Output is correct |
6 |
Correct |
308 ms |
11076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
278 ms |
11028 KB |
Output is correct |
2 |
Correct |
291 ms |
11280 KB |
Output is correct |
3 |
Correct |
277 ms |
11200 KB |
Output is correct |
4 |
Correct |
289 ms |
11088 KB |
Output is correct |
5 |
Correct |
289 ms |
11084 KB |
Output is correct |
6 |
Correct |
308 ms |
11076 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
357 ms |
9028 KB |
Output is correct |
14 |
Correct |
290 ms |
9072 KB |
Output is correct |
15 |
Correct |
287 ms |
9108 KB |
Output is correct |
16 |
Correct |
292 ms |
9156 KB |
Output is correct |
17 |
Correct |
396 ms |
10464 KB |
Output is correct |
18 |
Correct |
365 ms |
10536 KB |
Output is correct |
19 |
Correct |
404 ms |
10428 KB |
Output is correct |
20 |
Correct |
370 ms |
10440 KB |
Output is correct |
21 |
Correct |
449 ms |
10668 KB |
Output is correct |
22 |
Correct |
374 ms |
10444 KB |
Output is correct |
23 |
Correct |
386 ms |
10472 KB |
Output is correct |
24 |
Correct |
456 ms |
10572 KB |
Output is correct |
25 |
Correct |
286 ms |
11136 KB |
Output is correct |
26 |
Correct |
296 ms |
11072 KB |
Output is correct |
27 |
Correct |
377 ms |
10948 KB |
Output is correct |
28 |
Correct |
392 ms |
10764 KB |
Output is correct |
29 |
Correct |
405 ms |
11012 KB |
Output is correct |
30 |
Correct |
404 ms |
10948 KB |
Output is correct |
31 |
Correct |
396 ms |
10900 KB |
Output is correct |
32 |
Correct |
276 ms |
10616 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |