#include<bits/stdc++.h>
using namespace std;
const int mod = 1'000'000'007;
const int SQ = 300, N = 100'000 + 5;
vector<int> chains[SQ][SQ];
int n, d[N], x[N], cnt[N], tnt[N][SQ];
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++)
cin >> d[i] >> x[i];
for(int i = n; i >= 1; i --)
for(int j = 1; j < SQ; j++)
chains[j][i % j].push_back(i);
cnt[1] = 1;
int ans = 0;
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j < SQ; j++)
cnt[i] = (cnt[i] + tnt[i][j]) % mod;
ans = (ans + cnt[i]) % mod;
for(int j = 1; j < SQ; j++)
{
chains[j][i % j].pop_back();
if(chains[j][i % j].size())
tnt[i + j][j] = (tnt[i + j][j] + tnt[i][j]) % mod;
}
if(d[i] == 0) continue;
if(d[i] >= SQ)
{
for(int k = i + d[i], m = 1; k <= n && m <= x[i]; k += d[i], m++)
cnt[k] = (cnt[i] + cnt[k]) % mod;
}
else
{
x[i] = min(x[i], (n - i) / d[i]) + 1;
if(chains[d[i]][i % d[i]].size())
tnt[i + d[i]][d[i]] = (tnt[i + d[i]][d[i]] + cnt[i]) % mod;
if(x[i] * d[i] + i <= n)
tnt[x[i] * d[i] + i][d[i]] = (tnt[x[i] * d[i] + i][d[i]] + (mod - cnt[i]) % mod) % mod;
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3932 KB |
Output is correct |
2 |
Correct |
1 ms |
3932 KB |
Output is correct |
3 |
Correct |
1 ms |
3932 KB |
Output is correct |
4 |
Correct |
1 ms |
3932 KB |
Output is correct |
5 |
Correct |
1 ms |
4184 KB |
Output is correct |
6 |
Correct |
1 ms |
3932 KB |
Output is correct |
7 |
Correct |
1 ms |
3932 KB |
Output is correct |
8 |
Correct |
1 ms |
3932 KB |
Output is correct |
9 |
Correct |
1 ms |
3928 KB |
Output is correct |
10 |
Correct |
1 ms |
3932 KB |
Output is correct |
11 |
Correct |
1 ms |
4184 KB |
Output is correct |
12 |
Correct |
1 ms |
3932 KB |
Output is correct |
13 |
Correct |
1 ms |
3932 KB |
Output is correct |
14 |
Correct |
1 ms |
3932 KB |
Output is correct |
15 |
Correct |
1 ms |
3932 KB |
Output is correct |
16 |
Correct |
1 ms |
3932 KB |
Output is correct |
17 |
Correct |
1 ms |
3932 KB |
Output is correct |
18 |
Correct |
1 ms |
3932 KB |
Output is correct |
19 |
Correct |
1 ms |
3932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3932 KB |
Output is correct |
2 |
Correct |
1 ms |
3932 KB |
Output is correct |
3 |
Correct |
1 ms |
3932 KB |
Output is correct |
4 |
Correct |
1 ms |
3932 KB |
Output is correct |
5 |
Correct |
1 ms |
4184 KB |
Output is correct |
6 |
Correct |
1 ms |
3932 KB |
Output is correct |
7 |
Correct |
1 ms |
3932 KB |
Output is correct |
8 |
Correct |
1 ms |
3932 KB |
Output is correct |
9 |
Correct |
1 ms |
3928 KB |
Output is correct |
10 |
Correct |
1 ms |
3932 KB |
Output is correct |
11 |
Correct |
1 ms |
4184 KB |
Output is correct |
12 |
Correct |
1 ms |
3932 KB |
Output is correct |
13 |
Correct |
1 ms |
3932 KB |
Output is correct |
14 |
Correct |
1 ms |
3932 KB |
Output is correct |
15 |
Correct |
1 ms |
3932 KB |
Output is correct |
16 |
Correct |
1 ms |
3932 KB |
Output is correct |
17 |
Correct |
1 ms |
3932 KB |
Output is correct |
18 |
Correct |
1 ms |
3932 KB |
Output is correct |
19 |
Correct |
1 ms |
3932 KB |
Output is correct |
20 |
Correct |
52 ms |
29048 KB |
Output is correct |
21 |
Correct |
19 ms |
13148 KB |
Output is correct |
22 |
Correct |
55 ms |
34436 KB |
Output is correct |
23 |
Correct |
37 ms |
23356 KB |
Output is correct |
24 |
Correct |
25 ms |
16604 KB |
Output is correct |
25 |
Correct |
49 ms |
30992 KB |
Output is correct |
26 |
Correct |
27 ms |
17748 KB |
Output is correct |
27 |
Correct |
46 ms |
29728 KB |
Output is correct |
28 |
Correct |
55 ms |
34392 KB |
Output is correct |
29 |
Correct |
54 ms |
34460 KB |
Output is correct |
30 |
Correct |
55 ms |
34520 KB |
Output is correct |
31 |
Correct |
55 ms |
34416 KB |
Output is correct |
32 |
Correct |
60 ms |
34368 KB |
Output is correct |
33 |
Correct |
56 ms |
34496 KB |
Output is correct |
34 |
Correct |
51 ms |
34388 KB |
Output is correct |
35 |
Correct |
54 ms |
34388 KB |
Output is correct |
36 |
Correct |
55 ms |
34384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3928 KB |
Output is correct |
2 |
Correct |
40 ms |
23316 KB |
Output is correct |
3 |
Correct |
28 ms |
17748 KB |
Output is correct |
4 |
Correct |
47 ms |
29780 KB |
Output is correct |
5 |
Correct |
360 ms |
231368 KB |
Output is correct |
6 |
Correct |
448 ms |
288028 KB |
Output is correct |
7 |
Correct |
472 ms |
287948 KB |
Output is correct |
8 |
Correct |
1 ms |
3928 KB |
Output is correct |
9 |
Correct |
1 ms |
3932 KB |
Output is correct |
10 |
Correct |
1 ms |
3932 KB |
Output is correct |
11 |
Correct |
55 ms |
34400 KB |
Output is correct |
12 |
Correct |
455 ms |
287944 KB |
Output is correct |
13 |
Correct |
1 ms |
4184 KB |
Output is correct |
14 |
Correct |
56 ms |
34436 KB |
Output is correct |
15 |
Correct |
446 ms |
288012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
250 ms |
144608 KB |
Output is correct |
2 |
Correct |
195 ms |
124732 KB |
Output is correct |
3 |
Correct |
453 ms |
287888 KB |
Output is correct |
4 |
Correct |
335 ms |
212932 KB |
Output is correct |
5 |
Correct |
1 ms |
3928 KB |
Output is correct |
6 |
Correct |
1 ms |
3996 KB |
Output is correct |
7 |
Correct |
55 ms |
34384 KB |
Output is correct |
8 |
Correct |
458 ms |
287944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3932 KB |
Output is correct |
2 |
Correct |
1 ms |
3932 KB |
Output is correct |
3 |
Correct |
1 ms |
3932 KB |
Output is correct |
4 |
Correct |
1 ms |
3932 KB |
Output is correct |
5 |
Correct |
1 ms |
4184 KB |
Output is correct |
6 |
Correct |
1 ms |
3932 KB |
Output is correct |
7 |
Correct |
1 ms |
3932 KB |
Output is correct |
8 |
Correct |
1 ms |
3932 KB |
Output is correct |
9 |
Correct |
1 ms |
3928 KB |
Output is correct |
10 |
Correct |
1 ms |
3932 KB |
Output is correct |
11 |
Correct |
1 ms |
4184 KB |
Output is correct |
12 |
Correct |
1 ms |
3932 KB |
Output is correct |
13 |
Correct |
1 ms |
3932 KB |
Output is correct |
14 |
Correct |
1 ms |
3932 KB |
Output is correct |
15 |
Correct |
1 ms |
3932 KB |
Output is correct |
16 |
Correct |
1 ms |
3932 KB |
Output is correct |
17 |
Correct |
1 ms |
3932 KB |
Output is correct |
18 |
Correct |
1 ms |
3932 KB |
Output is correct |
19 |
Correct |
1 ms |
3932 KB |
Output is correct |
20 |
Correct |
52 ms |
29048 KB |
Output is correct |
21 |
Correct |
19 ms |
13148 KB |
Output is correct |
22 |
Correct |
55 ms |
34436 KB |
Output is correct |
23 |
Correct |
37 ms |
23356 KB |
Output is correct |
24 |
Correct |
25 ms |
16604 KB |
Output is correct |
25 |
Correct |
49 ms |
30992 KB |
Output is correct |
26 |
Correct |
27 ms |
17748 KB |
Output is correct |
27 |
Correct |
46 ms |
29728 KB |
Output is correct |
28 |
Correct |
55 ms |
34392 KB |
Output is correct |
29 |
Correct |
54 ms |
34460 KB |
Output is correct |
30 |
Correct |
55 ms |
34520 KB |
Output is correct |
31 |
Correct |
55 ms |
34416 KB |
Output is correct |
32 |
Correct |
60 ms |
34368 KB |
Output is correct |
33 |
Correct |
56 ms |
34496 KB |
Output is correct |
34 |
Correct |
51 ms |
34388 KB |
Output is correct |
35 |
Correct |
54 ms |
34388 KB |
Output is correct |
36 |
Correct |
55 ms |
34384 KB |
Output is correct |
37 |
Correct |
1 ms |
3928 KB |
Output is correct |
38 |
Correct |
40 ms |
23316 KB |
Output is correct |
39 |
Correct |
28 ms |
17748 KB |
Output is correct |
40 |
Correct |
47 ms |
29780 KB |
Output is correct |
41 |
Correct |
360 ms |
231368 KB |
Output is correct |
42 |
Correct |
448 ms |
288028 KB |
Output is correct |
43 |
Correct |
472 ms |
287948 KB |
Output is correct |
44 |
Correct |
1 ms |
3928 KB |
Output is correct |
45 |
Correct |
1 ms |
3932 KB |
Output is correct |
46 |
Correct |
1 ms |
3932 KB |
Output is correct |
47 |
Correct |
55 ms |
34400 KB |
Output is correct |
48 |
Correct |
455 ms |
287944 KB |
Output is correct |
49 |
Correct |
1 ms |
4184 KB |
Output is correct |
50 |
Correct |
56 ms |
34436 KB |
Output is correct |
51 |
Correct |
446 ms |
288012 KB |
Output is correct |
52 |
Correct |
250 ms |
144608 KB |
Output is correct |
53 |
Correct |
195 ms |
124732 KB |
Output is correct |
54 |
Correct |
453 ms |
287888 KB |
Output is correct |
55 |
Correct |
335 ms |
212932 KB |
Output is correct |
56 |
Correct |
1 ms |
3928 KB |
Output is correct |
57 |
Correct |
1 ms |
3996 KB |
Output is correct |
58 |
Correct |
55 ms |
34384 KB |
Output is correct |
59 |
Correct |
458 ms |
287944 KB |
Output is correct |
60 |
Correct |
384 ms |
245960 KB |
Output is correct |
61 |
Correct |
461 ms |
288052 KB |
Output is correct |
62 |
Correct |
469 ms |
288080 KB |
Output is correct |
63 |
Correct |
447 ms |
287944 KB |
Output is correct |
64 |
Correct |
464 ms |
287944 KB |
Output is correct |
65 |
Correct |
461 ms |
287932 KB |
Output is correct |
66 |
Correct |
473 ms |
287948 KB |
Output is correct |
67 |
Correct |
459 ms |
288016 KB |
Output is correct |
68 |
Correct |
444 ms |
287948 KB |
Output is correct |
69 |
Correct |
517 ms |
288000 KB |
Output is correct |
70 |
Correct |
456 ms |
288204 KB |
Output is correct |
71 |
Correct |
454 ms |
287952 KB |
Output is correct |
72 |
Correct |
445 ms |
287944 KB |
Output is correct |