#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;) {
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];
// if (at <= r && at >= l) ++res;
// t /= per[i+1];
}
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';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
294 ms |
11200 KB |
Output is correct |
2 |
Correct |
289 ms |
11088 KB |
Output is correct |
3 |
Correct |
289 ms |
11036 KB |
Output is correct |
4 |
Correct |
290 ms |
11204 KB |
Output is correct |
5 |
Correct |
286 ms |
11132 KB |
Output is correct |
6 |
Correct |
296 ms |
11140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
294 ms |
11200 KB |
Output is correct |
2 |
Correct |
289 ms |
11088 KB |
Output is correct |
3 |
Correct |
289 ms |
11036 KB |
Output is correct |
4 |
Correct |
290 ms |
11204 KB |
Output is correct |
5 |
Correct |
286 ms |
11132 KB |
Output is correct |
6 |
Correct |
296 ms |
11140 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
354 ms |
9064 KB |
Output is correct |
14 |
Correct |
304 ms |
9136 KB |
Output is correct |
15 |
Correct |
330 ms |
9076 KB |
Output is correct |
16 |
Correct |
306 ms |
9012 KB |
Output is correct |
17 |
Correct |
410 ms |
10524 KB |
Output is correct |
18 |
Correct |
413 ms |
10500 KB |
Output is correct |
19 |
Correct |
377 ms |
10380 KB |
Output is correct |
20 |
Correct |
410 ms |
10452 KB |
Output is correct |
21 |
Correct |
380 ms |
10656 KB |
Output is correct |
22 |
Correct |
366 ms |
10432 KB |
Output is correct |
23 |
Correct |
367 ms |
10520 KB |
Output is correct |
24 |
Correct |
365 ms |
10476 KB |
Output is correct |
25 |
Correct |
301 ms |
11108 KB |
Output is correct |
26 |
Correct |
293 ms |
11188 KB |
Output is correct |
27 |
Correct |
437 ms |
11004 KB |
Output is correct |
28 |
Correct |
418 ms |
10796 KB |
Output is correct |
29 |
Correct |
396 ms |
10868 KB |
Output is correct |
30 |
Correct |
392 ms |
10976 KB |
Output is correct |
31 |
Correct |
405 ms |
10884 KB |
Output is correct |
32 |
Correct |
282 ms |
10620 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |