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;
using ll = long long;
const int N = 505;
const ll MOD = 1e9 + 7;
int a[N], b[N];
ll qs[2 * N], dp[2 * N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
vector<int> c;
c.push_back(0);
for (int i = 1;i <= n;i++) {
cin >> a[i] >> b[i];
c.push_back(a[i] - 1);
c.push_back(b[i]);
}
sort(c.begin(), c.end());
c.resize(unique(c.begin(), c.end()) - c.begin());
int m = c.size();
for (int i = 0;i < m;i++) {
qs[i] = 1;
}
for (int i = 1;i <= n;i++) {
memset(dp, 0, sizeof dp);
int l = lower_bound(c.begin(), c.end(), a[i] - 1) - c.begin();
int r = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
for (int j = l + 1;j < m;j++) {
if (j <= r) dp[j] = (dp[j - 1] + (qs[j - 1]) * (c[j] - c[j - 1]) % MOD) % MOD;
else dp[j] = dp[j - 1];
}
for (int j = l + 1;j < m;j++) {
qs[j] = (qs[j] + dp[j]) % MOD;
}
}
cout << (qs[m - 1] - 1 + MOD) % MOD;
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... |