# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
405838 |
2021-05-16T23:39:20 Z |
LucaDantas |
Boat (APIO16_boat) |
C++17 |
|
1770 ms |
408636 KB |
#include <cstdio>
#include <vector>
#include <algorithm>
constexpr int maxn = 510, maxSZ = 2e5, mod = 1000000007;
int fat[maxSZ+maxn], inv_fat[maxSZ+maxn], inv[maxSZ+maxn], botar[maxSZ+maxn+1][maxn];
void add(int& a, int b) { a += b; if(a >= mod) a -= mod; }
int am(int a, int b) { add(a, b); return a; }
int choose(int a, int b) { return (int)(1ll * fat[a] * inv_fat[b] % mod * inv_fat[a-b] % mod); }
void calc() {
fat[0] = fat[1] = inv_fat[1] = inv_fat[0] = inv[1] = 1;
for(int i = 2; i < maxSZ+maxn; i++) {
fat[i] = (int)(1ll * fat[i-1] * i % mod);
inv[i] = mod - (int)(1ll * (mod/i) * inv[mod%i] % mod);
inv_fat[i] = (int)(1ll * inv_fat[i-1] * inv[i] % mod);
}
for(int i = 1; i < maxn; i++)
botar[0][i] = 1;
for(int i = 0; i < maxSZ; i++)
botar[i][0] = i+1;
for(int i = 1; i < maxSZ; i++)
for(int j = 1; j < maxn; j++)
botar[i][j] = am(botar[i-1][j], choose(i+j, j));
}
struct Par
{
int l, r;
} itv[maxn];
struct Grp
{
int l, r, val; std::vector<int> p;
void calc() {
int qtd = (int)(p.size());
val = 0;
for(int i = 0; i < qtd; i++)
add(val, (int)(1ll * botar[r-l][qtd-i-1] * p[i] % mod));
}
} blocks[1<<13];
std::vector<int> divisoes;
int main() {
calc();
for(int i = 1; i <= 5000; i++)
divisoes.push_back(i * maxSZ);
int n; scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d %d", &itv[i].l, &itv[i].r), ++itv[i].r, divisoes.push_back(itv[i].l), divisoes.push_back(itv[i].r);
int mx = 0;
for(int i = 0; i < n; i++)
if(itv[i].r > mx) mx = itv[i].r;
std::sort(divisoes.begin(), divisoes.end());
divisoes.resize(std::unique(divisoes.begin(), divisoes.end()) - divisoes.begin());
int inicio = divisoes.front(), t = (int)(divisoes.size());
for(int i = 1; i < t; i++)
blocks[i].l = inicio, blocks[i].r = divisoes[i]-1, inicio = divisoes[i];
for(int qr = 0; qr < n; qr++) {
int soma = 1;
auto [l, r] = itv[qr]; --r;
for(int i = 0; i < t; i++) {
int val = blocks[i].val;
if(blocks[i].l >= l && blocks[i].r <= r)
blocks[i].p.push_back(soma), blocks[i].calc();
add(soma, val);
}
}
int ans = 0;
for(int i = 0; i < t; i++)
add(ans, blocks[i].val);
printf("%d\n", ans);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
boat.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%d %d", &itv[i].l, &itv[i].r), ++itv[i].r, divisoes.push_back(itv[i].l), divisoes.push_back(itv[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
756 ms |
402144 KB |
Output is correct |
2 |
Correct |
738 ms |
402204 KB |
Output is correct |
3 |
Correct |
750 ms |
402196 KB |
Output is correct |
4 |
Correct |
756 ms |
402084 KB |
Output is correct |
5 |
Correct |
750 ms |
402148 KB |
Output is correct |
6 |
Correct |
742 ms |
402148 KB |
Output is correct |
7 |
Correct |
743 ms |
402148 KB |
Output is correct |
8 |
Correct |
771 ms |
402144 KB |
Output is correct |
9 |
Correct |
732 ms |
402244 KB |
Output is correct |
10 |
Correct |
739 ms |
402148 KB |
Output is correct |
11 |
Correct |
754 ms |
402208 KB |
Output is correct |
12 |
Correct |
840 ms |
402216 KB |
Output is correct |
13 |
Correct |
785 ms |
402116 KB |
Output is correct |
14 |
Correct |
737 ms |
402152 KB |
Output is correct |
15 |
Correct |
748 ms |
402152 KB |
Output is correct |
16 |
Correct |
737 ms |
402148 KB |
Output is correct |
17 |
Correct |
772 ms |
402116 KB |
Output is correct |
18 |
Correct |
734 ms |
402148 KB |
Output is correct |
19 |
Correct |
766 ms |
402148 KB |
Output is correct |
20 |
Correct |
798 ms |
402244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
756 ms |
402144 KB |
Output is correct |
2 |
Correct |
738 ms |
402204 KB |
Output is correct |
3 |
Correct |
750 ms |
402196 KB |
Output is correct |
4 |
Correct |
756 ms |
402084 KB |
Output is correct |
5 |
Correct |
750 ms |
402148 KB |
Output is correct |
6 |
Correct |
742 ms |
402148 KB |
Output is correct |
7 |
Correct |
743 ms |
402148 KB |
Output is correct |
8 |
Correct |
771 ms |
402144 KB |
Output is correct |
9 |
Correct |
732 ms |
402244 KB |
Output is correct |
10 |
Correct |
739 ms |
402148 KB |
Output is correct |
11 |
Correct |
754 ms |
402208 KB |
Output is correct |
12 |
Correct |
840 ms |
402216 KB |
Output is correct |
13 |
Correct |
785 ms |
402116 KB |
Output is correct |
14 |
Correct |
737 ms |
402152 KB |
Output is correct |
15 |
Correct |
748 ms |
402152 KB |
Output is correct |
16 |
Correct |
737 ms |
402148 KB |
Output is correct |
17 |
Correct |
772 ms |
402116 KB |
Output is correct |
18 |
Correct |
734 ms |
402148 KB |
Output is correct |
19 |
Correct |
766 ms |
402148 KB |
Output is correct |
20 |
Correct |
798 ms |
402244 KB |
Output is correct |
21 |
Correct |
827 ms |
403040 KB |
Output is correct |
22 |
Correct |
813 ms |
403140 KB |
Output is correct |
23 |
Correct |
807 ms |
402912 KB |
Output is correct |
24 |
Correct |
806 ms |
403060 KB |
Output is correct |
25 |
Correct |
816 ms |
403096 KB |
Output is correct |
26 |
Correct |
912 ms |
403364 KB |
Output is correct |
27 |
Correct |
930 ms |
403424 KB |
Output is correct |
28 |
Correct |
907 ms |
403368 KB |
Output is correct |
29 |
Correct |
922 ms |
403312 KB |
Output is correct |
30 |
Correct |
755 ms |
402144 KB |
Output is correct |
31 |
Correct |
735 ms |
402152 KB |
Output is correct |
32 |
Correct |
778 ms |
402276 KB |
Output is correct |
33 |
Correct |
742 ms |
402148 KB |
Output is correct |
34 |
Correct |
739 ms |
402156 KB |
Output is correct |
35 |
Correct |
736 ms |
402152 KB |
Output is correct |
36 |
Correct |
745 ms |
402148 KB |
Output is correct |
37 |
Correct |
757 ms |
402176 KB |
Output is correct |
38 |
Correct |
743 ms |
402236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
760 ms |
403144 KB |
Output is correct |
2 |
Correct |
776 ms |
403040 KB |
Output is correct |
3 |
Correct |
756 ms |
403176 KB |
Output is correct |
4 |
Correct |
752 ms |
403168 KB |
Output is correct |
5 |
Correct |
749 ms |
403300 KB |
Output is correct |
6 |
Correct |
756 ms |
403300 KB |
Output is correct |
7 |
Correct |
752 ms |
403364 KB |
Output is correct |
8 |
Correct |
753 ms |
403392 KB |
Output is correct |
9 |
Correct |
770 ms |
403260 KB |
Output is correct |
10 |
Correct |
843 ms |
403296 KB |
Output is correct |
11 |
Correct |
755 ms |
403308 KB |
Output is correct |
12 |
Correct |
745 ms |
403168 KB |
Output is correct |
13 |
Correct |
755 ms |
403172 KB |
Output is correct |
14 |
Correct |
748 ms |
403176 KB |
Output is correct |
15 |
Correct |
752 ms |
403176 KB |
Output is correct |
16 |
Correct |
745 ms |
403136 KB |
Output is correct |
17 |
Correct |
734 ms |
403040 KB |
Output is correct |
18 |
Correct |
764 ms |
403176 KB |
Output is correct |
19 |
Correct |
737 ms |
403068 KB |
Output is correct |
20 |
Correct |
767 ms |
403172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
756 ms |
402144 KB |
Output is correct |
2 |
Correct |
738 ms |
402204 KB |
Output is correct |
3 |
Correct |
750 ms |
402196 KB |
Output is correct |
4 |
Correct |
756 ms |
402084 KB |
Output is correct |
5 |
Correct |
750 ms |
402148 KB |
Output is correct |
6 |
Correct |
742 ms |
402148 KB |
Output is correct |
7 |
Correct |
743 ms |
402148 KB |
Output is correct |
8 |
Correct |
771 ms |
402144 KB |
Output is correct |
9 |
Correct |
732 ms |
402244 KB |
Output is correct |
10 |
Correct |
739 ms |
402148 KB |
Output is correct |
11 |
Correct |
754 ms |
402208 KB |
Output is correct |
12 |
Correct |
840 ms |
402216 KB |
Output is correct |
13 |
Correct |
785 ms |
402116 KB |
Output is correct |
14 |
Correct |
737 ms |
402152 KB |
Output is correct |
15 |
Correct |
748 ms |
402152 KB |
Output is correct |
16 |
Correct |
737 ms |
402148 KB |
Output is correct |
17 |
Correct |
772 ms |
402116 KB |
Output is correct |
18 |
Correct |
734 ms |
402148 KB |
Output is correct |
19 |
Correct |
766 ms |
402148 KB |
Output is correct |
20 |
Correct |
798 ms |
402244 KB |
Output is correct |
21 |
Correct |
827 ms |
403040 KB |
Output is correct |
22 |
Correct |
813 ms |
403140 KB |
Output is correct |
23 |
Correct |
807 ms |
402912 KB |
Output is correct |
24 |
Correct |
806 ms |
403060 KB |
Output is correct |
25 |
Correct |
816 ms |
403096 KB |
Output is correct |
26 |
Correct |
912 ms |
403364 KB |
Output is correct |
27 |
Correct |
930 ms |
403424 KB |
Output is correct |
28 |
Correct |
907 ms |
403368 KB |
Output is correct |
29 |
Correct |
922 ms |
403312 KB |
Output is correct |
30 |
Correct |
755 ms |
402144 KB |
Output is correct |
31 |
Correct |
735 ms |
402152 KB |
Output is correct |
32 |
Correct |
778 ms |
402276 KB |
Output is correct |
33 |
Correct |
742 ms |
402148 KB |
Output is correct |
34 |
Correct |
739 ms |
402156 KB |
Output is correct |
35 |
Correct |
736 ms |
402152 KB |
Output is correct |
36 |
Correct |
745 ms |
402148 KB |
Output is correct |
37 |
Correct |
757 ms |
402176 KB |
Output is correct |
38 |
Correct |
743 ms |
402236 KB |
Output is correct |
39 |
Correct |
760 ms |
403144 KB |
Output is correct |
40 |
Correct |
776 ms |
403040 KB |
Output is correct |
41 |
Correct |
756 ms |
403176 KB |
Output is correct |
42 |
Correct |
752 ms |
403168 KB |
Output is correct |
43 |
Correct |
749 ms |
403300 KB |
Output is correct |
44 |
Correct |
756 ms |
403300 KB |
Output is correct |
45 |
Correct |
752 ms |
403364 KB |
Output is correct |
46 |
Correct |
753 ms |
403392 KB |
Output is correct |
47 |
Correct |
770 ms |
403260 KB |
Output is correct |
48 |
Correct |
843 ms |
403296 KB |
Output is correct |
49 |
Correct |
755 ms |
403308 KB |
Output is correct |
50 |
Correct |
745 ms |
403168 KB |
Output is correct |
51 |
Correct |
755 ms |
403172 KB |
Output is correct |
52 |
Correct |
748 ms |
403176 KB |
Output is correct |
53 |
Correct |
752 ms |
403176 KB |
Output is correct |
54 |
Correct |
745 ms |
403136 KB |
Output is correct |
55 |
Correct |
734 ms |
403040 KB |
Output is correct |
56 |
Correct |
764 ms |
403176 KB |
Output is correct |
57 |
Correct |
737 ms |
403068 KB |
Output is correct |
58 |
Correct |
767 ms |
403172 KB |
Output is correct |
59 |
Correct |
1293 ms |
407524 KB |
Output is correct |
60 |
Correct |
1226 ms |
407152 KB |
Output is correct |
61 |
Correct |
1259 ms |
407264 KB |
Output is correct |
62 |
Correct |
1347 ms |
408460 KB |
Output is correct |
63 |
Correct |
1280 ms |
407284 KB |
Output is correct |
64 |
Correct |
1687 ms |
408544 KB |
Output is correct |
65 |
Correct |
1706 ms |
408556 KB |
Output is correct |
66 |
Correct |
1765 ms |
408636 KB |
Output is correct |
67 |
Correct |
1770 ms |
408508 KB |
Output is correct |
68 |
Correct |
1742 ms |
408552 KB |
Output is correct |
69 |
Correct |
1204 ms |
407056 KB |
Output is correct |
70 |
Correct |
1188 ms |
407124 KB |
Output is correct |
71 |
Correct |
1182 ms |
407108 KB |
Output is correct |
72 |
Correct |
1239 ms |
407116 KB |
Output is correct |
73 |
Correct |
1250 ms |
407140 KB |
Output is correct |
74 |
Correct |
1205 ms |
406472 KB |
Output is correct |
75 |
Correct |
1142 ms |
406496 KB |
Output is correct |
76 |
Correct |
1194 ms |
406648 KB |
Output is correct |
77 |
Correct |
1165 ms |
406700 KB |
Output is correct |
78 |
Correct |
1189 ms |
407652 KB |
Output is correct |