#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 |
1 |
Correct |
3 ms |
2260 KB |
Output is correct |
2 |
Correct |
3 ms |
2260 KB |
Output is correct |
3 |
Correct |
3 ms |
2260 KB |
Output is correct |
4 |
Correct |
3 ms |
2260 KB |
Output is correct |
5 |
Correct |
3 ms |
2260 KB |
Output is correct |
6 |
Correct |
3 ms |
2260 KB |
Output is correct |
7 |
Correct |
3 ms |
2260 KB |
Output is correct |
8 |
Correct |
3 ms |
2260 KB |
Output is correct |
9 |
Correct |
3 ms |
2260 KB |
Output is correct |
10 |
Correct |
3 ms |
2260 KB |
Output is correct |
11 |
Correct |
3 ms |
2260 KB |
Output is correct |
12 |
Correct |
3 ms |
2260 KB |
Output is correct |
13 |
Correct |
3 ms |
2260 KB |
Output is correct |
14 |
Correct |
4 ms |
2260 KB |
Output is correct |
15 |
Correct |
3 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2260 KB |
Output is correct |
2 |
Correct |
3 ms |
2260 KB |
Output is correct |
3 |
Correct |
3 ms |
2260 KB |
Output is correct |
4 |
Correct |
3 ms |
2260 KB |
Output is correct |
5 |
Correct |
3 ms |
2260 KB |
Output is correct |
6 |
Correct |
3 ms |
2260 KB |
Output is correct |
7 |
Correct |
3 ms |
2260 KB |
Output is correct |
8 |
Correct |
3 ms |
2260 KB |
Output is correct |
9 |
Correct |
3 ms |
2260 KB |
Output is correct |
10 |
Correct |
3 ms |
2260 KB |
Output is correct |
11 |
Correct |
3 ms |
2260 KB |
Output is correct |
12 |
Correct |
3 ms |
2260 KB |
Output is correct |
13 |
Correct |
3 ms |
2260 KB |
Output is correct |
14 |
Correct |
4 ms |
2260 KB |
Output is correct |
15 |
Correct |
3 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Incorrect |
5 ms |
3540 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2260 KB |
Output is correct |
2 |
Correct |
3 ms |
2260 KB |
Output is correct |
3 |
Correct |
3 ms |
2260 KB |
Output is correct |
4 |
Correct |
3 ms |
2260 KB |
Output is correct |
5 |
Correct |
3 ms |
2260 KB |
Output is correct |
6 |
Correct |
3 ms |
2260 KB |
Output is correct |
7 |
Correct |
3 ms |
2260 KB |
Output is correct |
8 |
Correct |
3 ms |
2260 KB |
Output is correct |
9 |
Correct |
3 ms |
2260 KB |
Output is correct |
10 |
Correct |
3 ms |
2260 KB |
Output is correct |
11 |
Correct |
3 ms |
2260 KB |
Output is correct |
12 |
Correct |
3 ms |
2260 KB |
Output is correct |
13 |
Correct |
3 ms |
2260 KB |
Output is correct |
14 |
Correct |
4 ms |
2260 KB |
Output is correct |
15 |
Correct |
3 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Incorrect |
5 ms |
3540 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |