This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10,
M = 1'000'000'007;
int n;
int a[N], b[N];
struct modint {
int value;
modint(int value = 0) : value(value) {}
modint operator + (modint rhs) { return (rhs.value + value) % M; }
modint operator - (modint rhs) { return (value - rhs.value + M) % M; }
modint operator * (modint rhs) { return 1ll * value * rhs.value % M; }
modint operator += (modint rhs) { value = (value + rhs.value) % M; return *this; }
modint operator -= (modint rhs) { value = (value - rhs.value + M) % M; return *this; }
modint operator *= (modint rhs) { value = 1ll * value * rhs.value % M; return *this; }
friend ostream& operator << (ostream& os, modint rhs) {
return os << rhs.value;
}
};
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 i = 1; i <= n; ++i) {
int id = i & 1, p = id ^ 1;
for (int j = 0; j <= rrh.size(); ++j) f[id][j] = 0;
int it = lower_bound(rrh.begin(), rrh.end(), a[i]) - rrh.begin() + 1;
for (int j = 0; j <= rrh.size(); ++j) f[id][j] = f[p][j];
for (int j = it; j <= b[i] - a[i] + it; ++j) {
for (int t = 0; t < j; ++t) f[id][j] += f[p][t];
}
}
modint answer = 0;
for (int i = 1; i <= rrh.size(); ++i) answer += f[n & 1][i];
cout << answer << "\n";
}
Compilation message (stderr)
boat.cpp: In function 'int32_t main()':
boat.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int j = 0; j <= rrh.size(); ++j) f[id][j] = 0;
| ~~^~~~~~~~~~~~~
boat.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int j = 0; j <= rrh.size(); ++j) f[id][j] = f[p][j];
| ~~^~~~~~~~~~~~~
boat.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 1; i <= rrh.size(); ++i) answer += f[n & 1][i];
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |