#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];
template <int MOD=998'244'353>
struct Modular {
int value;
static const int MOD_value = MOD;
Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}
Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}
friend Modular mexp(Modular a, long long e) {
Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
return res;
}
friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
friend Modular operator+(Modular a, Modular const b) { return a += b; }
friend Modular operator-(Modular a, Modular const b) { return a -= b; }
friend Modular operator-(Modular const a) { return 0 - a; }
friend Modular operator*(Modular a, Modular const b) { return a *= b; }
friend Modular operator/(Modular a, Modular const b) { return a /= b; }
friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};
using modint = Modular<M>;
modint 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;
f[id][0] = f[p][0];
for (int j = 1; j <= rrh.size(); ++j) {
if (j < it || j > b[i] - a[i] + it) {
f[id][j] = f[id][j - 1] - f[p][j - 1] + f[p][j];
} else {
f[id][j] = f[id][j - 1] - f[p][j - 1] + f[p][j] + f[p][j - 1];
}
}
}
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:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int j = 1; j <= rrh.size(); ++j) f[0][j] = 1;
| ~~^~~~~~~~~~~~~
boat.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int j = 1; j <= rrh.size(); ++j) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8280 KB |
Output is correct |
2 |
Correct |
6 ms |
8280 KB |
Output is correct |
3 |
Correct |
6 ms |
8280 KB |
Output is correct |
4 |
Correct |
6 ms |
8284 KB |
Output is correct |
5 |
Correct |
6 ms |
8284 KB |
Output is correct |
6 |
Correct |
6 ms |
8284 KB |
Output is correct |
7 |
Correct |
6 ms |
8288 KB |
Output is correct |
8 |
Correct |
6 ms |
8280 KB |
Output is correct |
9 |
Correct |
6 ms |
8284 KB |
Output is correct |
10 |
Correct |
6 ms |
8284 KB |
Output is correct |
11 |
Correct |
6 ms |
8280 KB |
Output is correct |
12 |
Correct |
6 ms |
8284 KB |
Output is correct |
13 |
Correct |
6 ms |
8284 KB |
Output is correct |
14 |
Correct |
6 ms |
8284 KB |
Output is correct |
15 |
Correct |
6 ms |
8288 KB |
Output is correct |
16 |
Correct |
5 ms |
8284 KB |
Output is correct |
17 |
Correct |
5 ms |
8284 KB |
Output is correct |
18 |
Correct |
5 ms |
8280 KB |
Output is correct |
19 |
Correct |
5 ms |
8260 KB |
Output is correct |
20 |
Correct |
5 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8280 KB |
Output is correct |
2 |
Correct |
6 ms |
8280 KB |
Output is correct |
3 |
Correct |
6 ms |
8280 KB |
Output is correct |
4 |
Correct |
6 ms |
8284 KB |
Output is correct |
5 |
Correct |
6 ms |
8284 KB |
Output is correct |
6 |
Correct |
6 ms |
8284 KB |
Output is correct |
7 |
Correct |
6 ms |
8288 KB |
Output is correct |
8 |
Correct |
6 ms |
8280 KB |
Output is correct |
9 |
Correct |
6 ms |
8284 KB |
Output is correct |
10 |
Correct |
6 ms |
8284 KB |
Output is correct |
11 |
Correct |
6 ms |
8280 KB |
Output is correct |
12 |
Correct |
6 ms |
8284 KB |
Output is correct |
13 |
Correct |
6 ms |
8284 KB |
Output is correct |
14 |
Correct |
6 ms |
8284 KB |
Output is correct |
15 |
Correct |
6 ms |
8288 KB |
Output is correct |
16 |
Correct |
5 ms |
8284 KB |
Output is correct |
17 |
Correct |
5 ms |
8284 KB |
Output is correct |
18 |
Correct |
5 ms |
8280 KB |
Output is correct |
19 |
Correct |
5 ms |
8260 KB |
Output is correct |
20 |
Correct |
5 ms |
8280 KB |
Output is correct |
21 |
Correct |
48 ms |
13268 KB |
Output is correct |
22 |
Correct |
43 ms |
14036 KB |
Output is correct |
23 |
Correct |
40 ms |
12752 KB |
Output is correct |
24 |
Correct |
43 ms |
13268 KB |
Output is correct |
25 |
Correct |
43 ms |
12756 KB |
Output is correct |
26 |
Correct |
43 ms |
12500 KB |
Output is correct |
27 |
Correct |
44 ms |
12500 KB |
Output is correct |
28 |
Correct |
43 ms |
13264 KB |
Output is correct |
29 |
Correct |
44 ms |
13520 KB |
Output is correct |
30 |
Correct |
1525 ms |
13012 KB |
Output is correct |
31 |
Correct |
1506 ms |
12496 KB |
Output is correct |
32 |
Correct |
1522 ms |
12496 KB |
Output is correct |
33 |
Correct |
1479 ms |
13268 KB |
Output is correct |
34 |
Correct |
1492 ms |
14292 KB |
Output is correct |
35 |
Correct |
1439 ms |
12820 KB |
Output is correct |
36 |
Correct |
1490 ms |
12496 KB |
Output is correct |
37 |
Correct |
1503 ms |
14292 KB |
Output is correct |
38 |
Correct |
1461 ms |
12752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
489 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8280 KB |
Output is correct |
2 |
Correct |
6 ms |
8280 KB |
Output is correct |
3 |
Correct |
6 ms |
8280 KB |
Output is correct |
4 |
Correct |
6 ms |
8284 KB |
Output is correct |
5 |
Correct |
6 ms |
8284 KB |
Output is correct |
6 |
Correct |
6 ms |
8284 KB |
Output is correct |
7 |
Correct |
6 ms |
8288 KB |
Output is correct |
8 |
Correct |
6 ms |
8280 KB |
Output is correct |
9 |
Correct |
6 ms |
8284 KB |
Output is correct |
10 |
Correct |
6 ms |
8284 KB |
Output is correct |
11 |
Correct |
6 ms |
8280 KB |
Output is correct |
12 |
Correct |
6 ms |
8284 KB |
Output is correct |
13 |
Correct |
6 ms |
8284 KB |
Output is correct |
14 |
Correct |
6 ms |
8284 KB |
Output is correct |
15 |
Correct |
6 ms |
8288 KB |
Output is correct |
16 |
Correct |
5 ms |
8284 KB |
Output is correct |
17 |
Correct |
5 ms |
8284 KB |
Output is correct |
18 |
Correct |
5 ms |
8280 KB |
Output is correct |
19 |
Correct |
5 ms |
8260 KB |
Output is correct |
20 |
Correct |
5 ms |
8280 KB |
Output is correct |
21 |
Correct |
48 ms |
13268 KB |
Output is correct |
22 |
Correct |
43 ms |
14036 KB |
Output is correct |
23 |
Correct |
40 ms |
12752 KB |
Output is correct |
24 |
Correct |
43 ms |
13268 KB |
Output is correct |
25 |
Correct |
43 ms |
12756 KB |
Output is correct |
26 |
Correct |
43 ms |
12500 KB |
Output is correct |
27 |
Correct |
44 ms |
12500 KB |
Output is correct |
28 |
Correct |
43 ms |
13264 KB |
Output is correct |
29 |
Correct |
44 ms |
13520 KB |
Output is correct |
30 |
Correct |
1525 ms |
13012 KB |
Output is correct |
31 |
Correct |
1506 ms |
12496 KB |
Output is correct |
32 |
Correct |
1522 ms |
12496 KB |
Output is correct |
33 |
Correct |
1479 ms |
13268 KB |
Output is correct |
34 |
Correct |
1492 ms |
14292 KB |
Output is correct |
35 |
Correct |
1439 ms |
12820 KB |
Output is correct |
36 |
Correct |
1490 ms |
12496 KB |
Output is correct |
37 |
Correct |
1503 ms |
14292 KB |
Output is correct |
38 |
Correct |
1461 ms |
12752 KB |
Output is correct |
39 |
Runtime error |
489 ms |
524288 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |