#include <iostream>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
ll M=1000000007;
int N;
ll X[505],Y[505];
map<ll,ll> S;
map<pll,ll> DP;
ll ans;
map<ll,ll> R;
ll query(ll k, ll l, ll r, ll a, ll b){
if(b<l or r<a) return 0;
if(a<=l and r<=b) return R[k];
ll m=(l+r)/2;
return (query(2*k,l,m,a,b)+query(2*k+1,m+1,r,a,b))%M;
}
void insert(ll k, ll l, ll r, ll a, ll b){
if(l==r) R[k]=(R[k]+b)%M;
else{
ll m=(l+r)/2;
if(a<=m)
insert(2*k,l,m,a,b);
else
insert(2*k+1,m+1,r,a,b);
R[k]=(R[2*k]+R[2*k+1])%M;
}
}
ll somma(ll a){
return query(1,0,M,a,M-1);
}
void aggiungi(ll a, ll b){
insert(1,0,M,a,b);
}
int main(){
cin>>N;
for(int i=0;i<N;i++)
cin>>X[i]>>Y[i];
for(int i=N-1;i>=0;i--)
for(ll j=X[i];j<=Y[i];j++){
DP[{i,j}]=(somma(j+1)+1)%M;
aggiungi(j,DP[{i,j}]);
ans=(ans+DP[{i,j}])%M;
//cout<<i<<" "<<j<<" "<<DP[{i,j}]<<endl;
}
//for(int i=0;i<10;i++)cout<<i<<" "<<S[i]<<endl;
cout<<ans;
}
/*
3
1 1
2 2
3 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1656 KB |
Output is correct |
2 |
Correct |
15 ms |
1656 KB |
Output is correct |
3 |
Correct |
15 ms |
1828 KB |
Output is correct |
4 |
Correct |
17 ms |
1948 KB |
Output is correct |
5 |
Correct |
17 ms |
1948 KB |
Output is correct |
6 |
Correct |
15 ms |
1972 KB |
Output is correct |
7 |
Correct |
15 ms |
1996 KB |
Output is correct |
8 |
Correct |
13 ms |
2128 KB |
Output is correct |
9 |
Correct |
14 ms |
2144 KB |
Output is correct |
10 |
Correct |
14 ms |
2372 KB |
Output is correct |
11 |
Correct |
15 ms |
2372 KB |
Output is correct |
12 |
Correct |
14 ms |
2372 KB |
Output is correct |
13 |
Correct |
17 ms |
2372 KB |
Output is correct |
14 |
Correct |
18 ms |
2372 KB |
Output is correct |
15 |
Correct |
15 ms |
2372 KB |
Output is correct |
16 |
Correct |
12 ms |
2372 KB |
Output is correct |
17 |
Correct |
13 ms |
2372 KB |
Output is correct |
18 |
Correct |
10 ms |
2372 KB |
Output is correct |
19 |
Correct |
21 ms |
2372 KB |
Output is correct |
20 |
Correct |
11 ms |
2372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1656 KB |
Output is correct |
2 |
Correct |
15 ms |
1656 KB |
Output is correct |
3 |
Correct |
15 ms |
1828 KB |
Output is correct |
4 |
Correct |
17 ms |
1948 KB |
Output is correct |
5 |
Correct |
17 ms |
1948 KB |
Output is correct |
6 |
Correct |
15 ms |
1972 KB |
Output is correct |
7 |
Correct |
15 ms |
1996 KB |
Output is correct |
8 |
Correct |
13 ms |
2128 KB |
Output is correct |
9 |
Correct |
14 ms |
2144 KB |
Output is correct |
10 |
Correct |
14 ms |
2372 KB |
Output is correct |
11 |
Correct |
15 ms |
2372 KB |
Output is correct |
12 |
Correct |
14 ms |
2372 KB |
Output is correct |
13 |
Correct |
17 ms |
2372 KB |
Output is correct |
14 |
Correct |
18 ms |
2372 KB |
Output is correct |
15 |
Correct |
15 ms |
2372 KB |
Output is correct |
16 |
Correct |
12 ms |
2372 KB |
Output is correct |
17 |
Correct |
13 ms |
2372 KB |
Output is correct |
18 |
Correct |
10 ms |
2372 KB |
Output is correct |
19 |
Correct |
21 ms |
2372 KB |
Output is correct |
20 |
Correct |
11 ms |
2372 KB |
Output is correct |
21 |
Execution timed out |
2059 ms |
20076 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
34576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1656 KB |
Output is correct |
2 |
Correct |
15 ms |
1656 KB |
Output is correct |
3 |
Correct |
15 ms |
1828 KB |
Output is correct |
4 |
Correct |
17 ms |
1948 KB |
Output is correct |
5 |
Correct |
17 ms |
1948 KB |
Output is correct |
6 |
Correct |
15 ms |
1972 KB |
Output is correct |
7 |
Correct |
15 ms |
1996 KB |
Output is correct |
8 |
Correct |
13 ms |
2128 KB |
Output is correct |
9 |
Correct |
14 ms |
2144 KB |
Output is correct |
10 |
Correct |
14 ms |
2372 KB |
Output is correct |
11 |
Correct |
15 ms |
2372 KB |
Output is correct |
12 |
Correct |
14 ms |
2372 KB |
Output is correct |
13 |
Correct |
17 ms |
2372 KB |
Output is correct |
14 |
Correct |
18 ms |
2372 KB |
Output is correct |
15 |
Correct |
15 ms |
2372 KB |
Output is correct |
16 |
Correct |
12 ms |
2372 KB |
Output is correct |
17 |
Correct |
13 ms |
2372 KB |
Output is correct |
18 |
Correct |
10 ms |
2372 KB |
Output is correct |
19 |
Correct |
21 ms |
2372 KB |
Output is correct |
20 |
Correct |
11 ms |
2372 KB |
Output is correct |
21 |
Execution timed out |
2059 ms |
20076 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |