#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10,
M = 1'000'000'007;
int n;
int a[N], b[N];
int f[2][1'000'010];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
vector<int> rrh;
for (int i = 1; i <= n; ++i) {
for (int j = a[i]; j <= b[i]; ++j) rrh.push_back(j);
}
sort(rrh.begin(), rrh.end());
rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin());
f[0][0] = 1;
for (int j = 1; j <= rrh.size(); ++j) f[0][j] = 1;
for (int i = 1; i <= n; ++i) {
bool id = i & 1, p = id ^ 1;
int it = lower_bound(rrh.begin(), rrh.end(), a[i]) - rrh.begin() + 1;
auto add = [&](auto& value, const auto& delta) {
value += delta;
if (value >= M) value -= M;
};
f[id][0] = f[p][0];
for (int j = 1; j <= rrh.size(); ++j) {
f[id][j] = f[id][j - 1];
if (j < it || j > b[i] - a[i] + it) {
add(f[id][j], f[p][j]);
add(f[id][j], M - f[p][j - 1]);
} else {
add(f[id][j], f[p][j]);
}
}
}
cout << f[n & 1][rrh.size()] - 1 << "\n";
cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
}
Compilation message
boat.cpp: In function 'int32_t main()':
boat.cpp:28:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int j = 1; j <= rrh.size(); ++j) f[0][j] = 1;
| ~~^~~~~~~~~~~~~
boat.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int j = 1; j <= rrh.size(); ++j) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
41 ms |
6100 KB |
Output is correct |
22 |
Correct |
41 ms |
6100 KB |
Output is correct |
23 |
Correct |
40 ms |
5840 KB |
Output is correct |
24 |
Correct |
43 ms |
6084 KB |
Output is correct |
25 |
Correct |
42 ms |
6096 KB |
Output is correct |
26 |
Correct |
39 ms |
6332 KB |
Output is correct |
27 |
Correct |
38 ms |
6336 KB |
Output is correct |
28 |
Correct |
38 ms |
6612 KB |
Output is correct |
29 |
Correct |
39 ms |
6332 KB |
Output is correct |
30 |
Correct |
1466 ms |
12252 KB |
Output is correct |
31 |
Correct |
1505 ms |
12116 KB |
Output is correct |
32 |
Correct |
1525 ms |
12252 KB |
Output is correct |
33 |
Correct |
1456 ms |
12048 KB |
Output is correct |
34 |
Correct |
1469 ms |
12384 KB |
Output is correct |
35 |
Correct |
1463 ms |
11964 KB |
Output is correct |
36 |
Correct |
1484 ms |
12024 KB |
Output is correct |
37 |
Correct |
1509 ms |
12100 KB |
Output is correct |
38 |
Correct |
1472 ms |
11848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
467 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
41 ms |
6100 KB |
Output is correct |
22 |
Correct |
41 ms |
6100 KB |
Output is correct |
23 |
Correct |
40 ms |
5840 KB |
Output is correct |
24 |
Correct |
43 ms |
6084 KB |
Output is correct |
25 |
Correct |
42 ms |
6096 KB |
Output is correct |
26 |
Correct |
39 ms |
6332 KB |
Output is correct |
27 |
Correct |
38 ms |
6336 KB |
Output is correct |
28 |
Correct |
38 ms |
6612 KB |
Output is correct |
29 |
Correct |
39 ms |
6332 KB |
Output is correct |
30 |
Correct |
1466 ms |
12252 KB |
Output is correct |
31 |
Correct |
1505 ms |
12116 KB |
Output is correct |
32 |
Correct |
1525 ms |
12252 KB |
Output is correct |
33 |
Correct |
1456 ms |
12048 KB |
Output is correct |
34 |
Correct |
1469 ms |
12384 KB |
Output is correct |
35 |
Correct |
1463 ms |
11964 KB |
Output is correct |
36 |
Correct |
1484 ms |
12024 KB |
Output is correct |
37 |
Correct |
1509 ms |
12100 KB |
Output is correct |
38 |
Correct |
1472 ms |
11848 KB |
Output is correct |
39 |
Runtime error |
467 ms |
524288 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |