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 I inline void
using ll = long long ;
using ld = long double ;
using namespace std ;
const int N = 2000 + 7 , mod = 1e9 + 7 ;
// how interesting!
int n;
ll ans ;
map<int , int > used ;
set<pair<int , int> > st ;
vector<pair<int , int> > v ;
I add(int u , int v){
while(u <=v && used[u])u++ ;
while(v>=u&&used[v])v-- ;
if(u <=v){
used[u] = used[v] = 1;
st.insert({u , v}) ;
}
}
vector<int> onepiece[N * 10] ;
std::vector<int> szs[N * 10];
ll dp[N][N] ;
ll mul(ll a , ll b){
return (1ll * a * b) %mod ;
}
ll solve(int i , int j){
if(dp[i][j]!=-1)
return dp[i][j] ;
if(i == (int) st.size())
return 1;
ll ret = solve(i+1 , j ) ;
int pos = 0 ;
for(auto u : onepiece[i]){
if(u > j){
ll add = mul( szs[i][pos] , solve(i+1, u) ) ;
ret = (ret + add) %mod ;
}
pos ++ ;
}
return dp[i][j] = ret ;
}
ll conts[N] ;
int main(){
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
memset(dp , -1 , sizeof dp) ;
srand(time(0)) ;
//freopen("in.in" , "r" , stdin) ;
cin >> n;
set<int> ev ;
for(int i = 0 ;i < n;i++){
int x , y ;
cin >> x >> y ;
ev.insert(x) ;
ev.insert(y) ;
used[x] = used[y] = 1;
st.insert({x , x}) ;
st.insert({y , y}) ;
//for(int j =x ;j <= y ;j ++)
// st.push_back({j , j}) ;
v.push_back({x , y}) ;
}
int l = 0 ;
for(auto u : ev){
if(l){
add(l+1 , u - 1) ;
}
l = u ;
}
int pos = 0 ;
for(auto u : st){
for(int j = 0 ;j < n; j++){
if( u.first>= v[j].first && u.second <= v[j].second ){
onepiece[pos].push_back(j + 1) ;
szs[pos].push_back( u.second - u.first +1 ) ;
conts[j] += u.second - u.first + 1 ;
}
}
pos ++ ;
}
for(int i = 0 ;i < n;i++){
assert((conts[i] == v[i].second - v[i].first + 1)) ;
}
cout<< (mod + solve(0 , 0 ) -1 ) %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... |