#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = (int) 1e9 + 7;
constexpr int INF = (int) 2e9;
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()) {
if (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++) {
for (int j = 0; j < (int)segs.size(); j++) {
dp[i][j] = dp[i - 1][j];
}
int low = 0, sum = 0;
while (!(a[i] <= segs[low].first && segs[low].second <= b[i])) {
if (low > 0) {
sum += dp[i - 1][low - 1];
if (sum >= MOD)
sum -= MOD;
}
low++;
}
while (low < (int)segs.size() && a[i] <= segs[low].first && segs[low].second <= b[i]) {
if (low > 0) {
sum += dp[i - 1][low - 1];
if (sum >= MOD)
sum -= MOD;
}
dp[i][low] = (dp[i][low] + 1LL * (segs[low].second - segs[low].first + 1) * sum) % MOD;
low++;
}
// 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
3 ms |
2388 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
11 |
Correct |
2 ms |
2260 KB |
Output is correct |
12 |
Correct |
2 ms |
2260 KB |
Output is correct |
13 |
Correct |
2 ms |
2260 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
2 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 |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
3 ms |
2388 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
11 |
Correct |
2 ms |
2260 KB |
Output is correct |
12 |
Correct |
2 ms |
2260 KB |
Output is correct |
13 |
Correct |
2 ms |
2260 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
2 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 |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Incorrect |
3 ms |
3540 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
3 ms |
2388 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
11 |
Correct |
2 ms |
2260 KB |
Output is correct |
12 |
Correct |
2 ms |
2260 KB |
Output is correct |
13 |
Correct |
2 ms |
2260 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
2 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 |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Incorrect |
3 ms |
3540 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |