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>
#define endl '\n'
#define a first
#define b second
using namespace std;
typedef long long ll;
const int MAXN = 512;
const int MAXA = 1e6 + 10;
const int MOD = 1e9 + 7;
int n,cnt;
pair<int,int> s[MAXN];
int dp[MAXN];
int pref[MAXN];
unordered_map <int,int> pos;
void read()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> s[i].a >> s[i].b;
}
s[0].a = s[0].b = -1;
}
void fill_pos()
{
set <int> st;
for(int i = 1; i <= n; i++)
{
int from = s[i].a;
int to = s[i].b;
for(int j = from; j <= to; j++)
{
st.insert(j);
}
}
int last = -1;
for(int cur : st)
{
if(cur == last)
continue;
pos[cur] = ++cnt;
last = cur;
}
/**
for(auto x : pos)
{
cout << x.first << " " << x.second << endl;
}
*/
}
void fill_dp()
{
for(int i = 1; i <= n; i++)
{
int from = pos[s[i].a];
int to = pos[s[i].b];
for(int j = to; j >= from; j--)
{
dp[j] = (dp[j] + pref[j - 1] + 1 /** za nulata **/) % MOD;
}
for(int j = from; j <= cnt; j++)
{
pref[j] = (pref[j - 1] + dp[j]) % MOD;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
fill_pos();
fill_dp();
cout << pref[cnt] << endl;
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... |