// PHK
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define bigint __int128
#define emb emplace_back
#define pb push_back
#define pii pair <int, int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define Task ""
#define MASK(k) (1ull << k)
#define bitcnt(k) __builtin_popcount(k)
#define testBit(n, k) ((n >> k) & 1)
#define flipBit(n, k) (n ^ (1ll << k))
#define offBit(n, k) (n & ~MASK(k))
#define onBit(n, k) (n | (1ll << k))
template <class T> bool minimize(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool maximize(T &a, T b) {if (a < b) {a = b; return true;} return false;}
const int N = 5e2 + 5, lim = 60, mod = 1e9 + 7;
const ll INF = 1e18;
int n, l[N], r[N];
int dp[N][N << 1], pref[N][N << 1];
void add(int &a, int b) {
if ((a += b) >= mod) a -= mod;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
if (fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n; vector <int> points;
for (int i = 1; i <= n; i++) {
cin >> l[i] >> r[i];
points.emb(l[i]); points.emb(r[i] + 1);
}
sort (all(points)); points.resize(unique(all(points)) - points.begin());
// range[i] = points[i] -> points[i + 1] - 1
for (int i = 1; i <= n; i++) {
int u = lower_bound(all(points), l[i]) - points.begin();
int v = lower_bound(all(points), r[i] + 1) - points.begin() - 1;
for (int j = u; j <= v; j++) {
dp[i][j] = 1;
for (int k = 1; k < i; k++)
add(dp[i][j], pref[k][j - 1]);
}
for (int j = 0; j + 1 < points.size(); j++) {
if (j > 0) pref[i][j] = pref[i][j - 1];
add(pref[i][j], 1ll * dp[i][j] * (points[j + 1] - points[j]) % mod);
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
add(ans, 1ll * pref[i][points.size() - 2]);
cout << ans;
}
Compilation message (stderr)
boat.cpp: In function 'int main()':
boat.cpp:41:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:42:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen(Task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |