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;
constexpr int MOD = (int) 1e9 + 7;
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1);
vector<int> x;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
x.push_back(a[i]);
x.push_back(b[i]);
}
sort(x.begin(), x.end());
x.resize(unique(x.begin(), x.end()) - x.begin());
vector<pair<int, int>> segs;
segs.push_back({0, 0});
for (int i = 0; i < (int)x.size(); i++) {
segs.push_back({x[i], x[i]});
if (i + 1 < (int)x.size() && x[i] + 1 <= x[i + 1] - 1) {
segs.push_back({x[i] + 1, x[i + 1] - 1});
}
}
// for (auto itr : segs) {
// cerr << itr.first << " " << itr.second << " ";
// }
// cerr << "\n";
vector<vector<int>> dp(n + 1, vector<int>(segs.size()));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
int sum = 0;
for (int j = 0; j < (int)segs.size(); j++) {
dp[i][j] = dp[i - 1][j];
if (a[i] <= segs[j].first && segs[j].second <= b[i]) {
dp[i][j] = (dp[i][j] + 1LL * sum * (segs[j].second - segs[j].first + 1)) % MOD;
}
sum = (sum + dp[i - 1][j]) % MOD;
}
// for (int j = 0; j < segs.size(); j++) {
// cerr << dp[i][j] << " ";
// }
// cerr << "\n";
}
int answer = 0;
for (int i = 1; i < (int)segs.size(); i++) {
answer += dp[n][i];
if (answer >= MOD)
answer -= MOD;
}
cout << answer;
return 0;
}
# | 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... |