#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int md = 1e9 + 7;
void add(int &a, int b) {
a += b;
if (a >= md) a -= md;
}
int sub(int a, int b) {
a -= b;
if (a < 0) a += md;
return a;
}
int mul(int a, int b) {
return ((ll)a * b) % md;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector <int> a(n), b(n);
for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
vector <int> c;
for (int i = 0; i < n; ++i) {
c.push_back(a[i]);
c.push_back(b[i]);
c.push_back(a[i] - 1);
c.push_back(b[i] - 1);
}
sort(c.begin(), c.end());
c.resize(unique(c.begin(), c.end()) - c.begin());
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
}
int m = c.size();
vector <vector <int>> dp(n + 1, vector <int> (m + 1));
for (int j = 0; j <= m; ++j) dp[0][j] = 1;
for (int i = 1; i <= n; ++i) {
int l = a[i - 1];
int r = b[i - 1];
dp[i][0] = dp[i - 1][0];
for (int j = 1; j <= m; ++j) {
add(dp[i][j], dp[i][j - 1]);
add(dp[i][j], sub(dp[i - 1][j], dp[i - 1][j - 1]));
if (l <= j && j <= r) {
add(dp[i][j], mul(sub(c[j], c[j - 1]), dp[i - 1][j - 1]));
}
}
}
cout << sub(dp[n][m], 1) << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2304 KB |
Output is correct |
2 |
Correct |
6 ms |
2304 KB |
Output is correct |
3 |
Correct |
6 ms |
2304 KB |
Output is correct |
4 |
Correct |
5 ms |
2304 KB |
Output is correct |
5 |
Correct |
6 ms |
2304 KB |
Output is correct |
6 |
Correct |
6 ms |
2304 KB |
Output is correct |
7 |
Correct |
6 ms |
2304 KB |
Output is correct |
8 |
Correct |
6 ms |
2176 KB |
Output is correct |
9 |
Correct |
7 ms |
2304 KB |
Output is correct |
10 |
Correct |
5 ms |
2304 KB |
Output is correct |
11 |
Correct |
6 ms |
2304 KB |
Output is correct |
12 |
Correct |
7 ms |
2304 KB |
Output is correct |
13 |
Correct |
7 ms |
2304 KB |
Output is correct |
14 |
Correct |
6 ms |
2304 KB |
Output is correct |
15 |
Correct |
5 ms |
2304 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
18 |
Correct |
3 ms |
768 KB |
Output is correct |
19 |
Correct |
3 ms |
768 KB |
Output is correct |
20 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2304 KB |
Output is correct |
2 |
Correct |
6 ms |
2304 KB |
Output is correct |
3 |
Correct |
6 ms |
2304 KB |
Output is correct |
4 |
Correct |
5 ms |
2304 KB |
Output is correct |
5 |
Correct |
6 ms |
2304 KB |
Output is correct |
6 |
Correct |
6 ms |
2304 KB |
Output is correct |
7 |
Correct |
6 ms |
2304 KB |
Output is correct |
8 |
Correct |
6 ms |
2176 KB |
Output is correct |
9 |
Correct |
7 ms |
2304 KB |
Output is correct |
10 |
Correct |
5 ms |
2304 KB |
Output is correct |
11 |
Correct |
6 ms |
2304 KB |
Output is correct |
12 |
Correct |
7 ms |
2304 KB |
Output is correct |
13 |
Correct |
7 ms |
2304 KB |
Output is correct |
14 |
Correct |
6 ms |
2304 KB |
Output is correct |
15 |
Correct |
5 ms |
2304 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
18 |
Correct |
3 ms |
768 KB |
Output is correct |
19 |
Correct |
3 ms |
768 KB |
Output is correct |
20 |
Correct |
3 ms |
768 KB |
Output is correct |
21 |
Incorrect |
9 ms |
3584 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2304 KB |
Output is correct |
2 |
Correct |
6 ms |
2304 KB |
Output is correct |
3 |
Correct |
6 ms |
2304 KB |
Output is correct |
4 |
Correct |
5 ms |
2304 KB |
Output is correct |
5 |
Correct |
6 ms |
2304 KB |
Output is correct |
6 |
Correct |
6 ms |
2304 KB |
Output is correct |
7 |
Correct |
6 ms |
2304 KB |
Output is correct |
8 |
Correct |
6 ms |
2176 KB |
Output is correct |
9 |
Correct |
7 ms |
2304 KB |
Output is correct |
10 |
Correct |
5 ms |
2304 KB |
Output is correct |
11 |
Correct |
6 ms |
2304 KB |
Output is correct |
12 |
Correct |
7 ms |
2304 KB |
Output is correct |
13 |
Correct |
7 ms |
2304 KB |
Output is correct |
14 |
Correct |
6 ms |
2304 KB |
Output is correct |
15 |
Correct |
5 ms |
2304 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
18 |
Correct |
3 ms |
768 KB |
Output is correct |
19 |
Correct |
3 ms |
768 KB |
Output is correct |
20 |
Correct |
3 ms |
768 KB |
Output is correct |
21 |
Incorrect |
9 ms |
3584 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |