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;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int64_t(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
#define int long long
const int MAXN = 5e2+1;
int n;
int l[MAXN], r[MAXN];
vector<int> uncc;
UM<int,int> cc;
US<int> vis;
int dp[MAXN][MAXN*3];
void add(int x) {
if (!vis.count(x)) {
vis.insert(x);
uncc.PB(x);
}
}
signed main() {
OPTM;
cin >> n;
FOR(i,1,n+1) {
cin >> l[i] >> r[i];
add(l[i]); add(r[i]);
}
uncc.PB(0);
sort(ALL(uncc));
int vn = uncc.size();
FOR(i,0,vn) cc[uncc[i]] = i;
FOR(i,1,n+1) {
int cl = cc[l[i]], cr = cc[r[i]];
FOR(j,cl,cr+1) {
dp[i][j] = 1;
FOR(k,1,i) dp[i][j] = (dp[i][j]+dp[k][j-1])%INF;
}
FOR(j,1,vn) dp[i][j] = (dp[i][j]+dp[i][j-1])%INF;
}
// FOR(i,0,n+1) {
// FOR(j,0,vn) cout << dp[i][j] << ' ';
// cout << ln;
// }
int res = dp[n][vn-1];
if (n >= 2) res = (res+dp[n-1][vn-1])%INF;
cout << res;
}
# | 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... |