#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
int const mod=1e9+7;
map<int,int> ind;
vector<int> val;
vector<int> fen(1010,0);
void upd(int idx,int val)
{
idx+=2;
for(int i=idx;i<1010;i+=i&-i)fen[i]+=val,fen[i]%=mod;
}
int qr(int idx)
{
idx+=2;
int ret=0;
for(int i=idx;i>0;i-=i&-i)ret+=fen[i],ret%=mod;
return ret;
}
int pow(int a,int b)
{
if(b==0)return 1;
if(b==1)return a;
int ret=pow(a,b/2);
if(b%2==0)return (ret*ret)%mod;
else return (((ret*ret)%mod)*a)%mod;
}
vector<int> inverse(510);
void inv(int a)
{
inverse[a]=pow(a,mod-2);
}
int invfac[1010];
int cycle=1;
vector<vector<int>> keep1(1010,vector<int>(510,0));
int choose1(int a,int b)
{
if(b>a)return 0;
if(a==b)return 1;
if(a-b>b)b=a-b;
int ret=1;
for(int i=b+1;i<=a;i++)
{
ret*=i;
ret%=mod;
}
ret*=invfac[a-b];
ret%=mod;
return ret;
}
int choose(int a,int b)
{
int ret=keep1[a][b];
ret*=invfac[b];
ret%=mod;
//cout<<a<<"-"<<b<<" "<<ret<<endl;
return ret;
}
signed main()
{
cin.tie(nullptr)->sync_with_stdio(false);
for(int i=2;i<510;i++)inv(i);
invfac[0]=1;
invfac[1]=1;
for(int i=2;i<510;i++)invfac[i]=invfac[i-1]*inverse[i],invfac[i]%=mod;
int n;
cin>>n;
vector<pii> info;
set<int> temp;
for(int i=0;i<n;i++)
{
int a,b;
cin>>a>>b;
temp.insert(a);
temp.insert(b+1);
info.push_back({a,b+1});
}
for(auto it:temp)
{
val.push_back(it);
ind[it]=val.size()-1;
}
for(int i=0;i<val.size()-1;i++)
{
int a=val[i+1]-val[i]-1;
keep1[i][0]=1;
for(int j=1;j<510;j++)
{
keep1[i][j]=(keep1[i][j-1]*a)%mod;
a++;
}
}
vector<vector<int>> pre(510,vector<int>(1010,-2));
vector<int> latest(1010,-1);
upd(-1,1);
vector<vector<int>> dp(510,vector<int>(1010,0));
for(int i=0;i<n;i++)
{
//cout<<endl<<i<<":";
for(int j=ind[info[i].se]-1;j>=ind[info[i].fi];j--)
{
//cout<<j<<" ";
int bef=latest[j];
pre[i][j]=latest[j];
latest[j]=i;
int a=qr(j),b=(val[j+1]-val[j]),c=0;
dp[i][j]=a;
int ans=a*b;
ans%=mod;
int k=2;
//cout<<i<<" "<<j<<" "<<ans<<" ";
while(bef!=-1)
{
ans+=dp[bef][j]*((b+k-2<k)?0:choose(j,k));
ans%=mod;
bef=pre[bef][j];
k++;
//cout<<endl<<bef<<" "<<ans<<" ";
}
// cout<<endl;
upd(j+1,ans);
}
}
cout<<(qr(1007)+mod-1)%mod;
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:87:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int i=0;i<val.size()-1;i++)
| ~^~~~~~~~~~~~~
boat.cpp:111:45: warning: unused variable 'c' [-Wunused-variable]
111 | int a=qr(j),b=(val[j+1]-val[j]),c=0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12636 KB |
Output is correct |
2 |
Correct |
9 ms |
12636 KB |
Output is correct |
3 |
Correct |
9 ms |
12616 KB |
Output is correct |
4 |
Correct |
9 ms |
12632 KB |
Output is correct |
5 |
Correct |
9 ms |
12636 KB |
Output is correct |
6 |
Correct |
9 ms |
12636 KB |
Output is correct |
7 |
Correct |
9 ms |
12644 KB |
Output is correct |
8 |
Correct |
9 ms |
12636 KB |
Output is correct |
9 |
Correct |
9 ms |
12612 KB |
Output is correct |
10 |
Correct |
9 ms |
12636 KB |
Output is correct |
11 |
Correct |
9 ms |
12636 KB |
Output is correct |
12 |
Correct |
9 ms |
12636 KB |
Output is correct |
13 |
Correct |
9 ms |
12612 KB |
Output is correct |
14 |
Correct |
9 ms |
12636 KB |
Output is correct |
15 |
Correct |
9 ms |
12636 KB |
Output is correct |
16 |
Correct |
6 ms |
12636 KB |
Output is correct |
17 |
Correct |
6 ms |
12632 KB |
Output is correct |
18 |
Correct |
6 ms |
12636 KB |
Output is correct |
19 |
Correct |
6 ms |
12632 KB |
Output is correct |
20 |
Correct |
6 ms |
12636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12636 KB |
Output is correct |
2 |
Correct |
9 ms |
12636 KB |
Output is correct |
3 |
Correct |
9 ms |
12616 KB |
Output is correct |
4 |
Correct |
9 ms |
12632 KB |
Output is correct |
5 |
Correct |
9 ms |
12636 KB |
Output is correct |
6 |
Correct |
9 ms |
12636 KB |
Output is correct |
7 |
Correct |
9 ms |
12644 KB |
Output is correct |
8 |
Correct |
9 ms |
12636 KB |
Output is correct |
9 |
Correct |
9 ms |
12612 KB |
Output is correct |
10 |
Correct |
9 ms |
12636 KB |
Output is correct |
11 |
Correct |
9 ms |
12636 KB |
Output is correct |
12 |
Correct |
9 ms |
12636 KB |
Output is correct |
13 |
Correct |
9 ms |
12612 KB |
Output is correct |
14 |
Correct |
9 ms |
12636 KB |
Output is correct |
15 |
Correct |
9 ms |
12636 KB |
Output is correct |
16 |
Correct |
6 ms |
12636 KB |
Output is correct |
17 |
Correct |
6 ms |
12632 KB |
Output is correct |
18 |
Correct |
6 ms |
12636 KB |
Output is correct |
19 |
Correct |
6 ms |
12632 KB |
Output is correct |
20 |
Correct |
6 ms |
12636 KB |
Output is correct |
21 |
Correct |
147 ms |
12884 KB |
Output is correct |
22 |
Correct |
144 ms |
12768 KB |
Output is correct |
23 |
Correct |
126 ms |
12636 KB |
Output is correct |
24 |
Correct |
140 ms |
12884 KB |
Output is correct |
25 |
Correct |
150 ms |
12636 KB |
Output is correct |
26 |
Correct |
176 ms |
12636 KB |
Output is correct |
27 |
Correct |
188 ms |
12764 KB |
Output is correct |
28 |
Correct |
188 ms |
12636 KB |
Output is correct |
29 |
Correct |
179 ms |
12776 KB |
Output is correct |
30 |
Correct |
9 ms |
12636 KB |
Output is correct |
31 |
Correct |
10 ms |
12636 KB |
Output is correct |
32 |
Correct |
10 ms |
12636 KB |
Output is correct |
33 |
Correct |
9 ms |
12636 KB |
Output is correct |
34 |
Correct |
10 ms |
12636 KB |
Output is correct |
35 |
Correct |
10 ms |
12788 KB |
Output is correct |
36 |
Correct |
9 ms |
12800 KB |
Output is correct |
37 |
Correct |
9 ms |
12636 KB |
Output is correct |
38 |
Correct |
10 ms |
12636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12636 KB |
Output is correct |
2 |
Correct |
7 ms |
12596 KB |
Output is correct |
3 |
Correct |
8 ms |
12636 KB |
Output is correct |
4 |
Correct |
7 ms |
12636 KB |
Output is correct |
5 |
Correct |
8 ms |
12560 KB |
Output is correct |
6 |
Correct |
8 ms |
12636 KB |
Output is correct |
7 |
Correct |
8 ms |
12636 KB |
Output is correct |
8 |
Correct |
8 ms |
12632 KB |
Output is correct |
9 |
Correct |
8 ms |
12888 KB |
Output is correct |
10 |
Correct |
10 ms |
12636 KB |
Output is correct |
11 |
Correct |
7 ms |
12636 KB |
Output is correct |
12 |
Correct |
7 ms |
12636 KB |
Output is correct |
13 |
Correct |
7 ms |
12636 KB |
Output is correct |
14 |
Correct |
7 ms |
12636 KB |
Output is correct |
15 |
Correct |
7 ms |
12636 KB |
Output is correct |
16 |
Correct |
6 ms |
12636 KB |
Output is correct |
17 |
Correct |
6 ms |
12636 KB |
Output is correct |
18 |
Correct |
6 ms |
12636 KB |
Output is correct |
19 |
Correct |
7 ms |
12636 KB |
Output is correct |
20 |
Correct |
7 ms |
12636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12636 KB |
Output is correct |
2 |
Correct |
9 ms |
12636 KB |
Output is correct |
3 |
Correct |
9 ms |
12616 KB |
Output is correct |
4 |
Correct |
9 ms |
12632 KB |
Output is correct |
5 |
Correct |
9 ms |
12636 KB |
Output is correct |
6 |
Correct |
9 ms |
12636 KB |
Output is correct |
7 |
Correct |
9 ms |
12644 KB |
Output is correct |
8 |
Correct |
9 ms |
12636 KB |
Output is correct |
9 |
Correct |
9 ms |
12612 KB |
Output is correct |
10 |
Correct |
9 ms |
12636 KB |
Output is correct |
11 |
Correct |
9 ms |
12636 KB |
Output is correct |
12 |
Correct |
9 ms |
12636 KB |
Output is correct |
13 |
Correct |
9 ms |
12612 KB |
Output is correct |
14 |
Correct |
9 ms |
12636 KB |
Output is correct |
15 |
Correct |
9 ms |
12636 KB |
Output is correct |
16 |
Correct |
6 ms |
12636 KB |
Output is correct |
17 |
Correct |
6 ms |
12632 KB |
Output is correct |
18 |
Correct |
6 ms |
12636 KB |
Output is correct |
19 |
Correct |
6 ms |
12632 KB |
Output is correct |
20 |
Correct |
6 ms |
12636 KB |
Output is correct |
21 |
Correct |
147 ms |
12884 KB |
Output is correct |
22 |
Correct |
144 ms |
12768 KB |
Output is correct |
23 |
Correct |
126 ms |
12636 KB |
Output is correct |
24 |
Correct |
140 ms |
12884 KB |
Output is correct |
25 |
Correct |
150 ms |
12636 KB |
Output is correct |
26 |
Correct |
176 ms |
12636 KB |
Output is correct |
27 |
Correct |
188 ms |
12764 KB |
Output is correct |
28 |
Correct |
188 ms |
12636 KB |
Output is correct |
29 |
Correct |
179 ms |
12776 KB |
Output is correct |
30 |
Correct |
9 ms |
12636 KB |
Output is correct |
31 |
Correct |
10 ms |
12636 KB |
Output is correct |
32 |
Correct |
10 ms |
12636 KB |
Output is correct |
33 |
Correct |
9 ms |
12636 KB |
Output is correct |
34 |
Correct |
10 ms |
12636 KB |
Output is correct |
35 |
Correct |
10 ms |
12788 KB |
Output is correct |
36 |
Correct |
9 ms |
12800 KB |
Output is correct |
37 |
Correct |
9 ms |
12636 KB |
Output is correct |
38 |
Correct |
10 ms |
12636 KB |
Output is correct |
39 |
Correct |
7 ms |
12636 KB |
Output is correct |
40 |
Correct |
7 ms |
12596 KB |
Output is correct |
41 |
Correct |
8 ms |
12636 KB |
Output is correct |
42 |
Correct |
7 ms |
12636 KB |
Output is correct |
43 |
Correct |
8 ms |
12560 KB |
Output is correct |
44 |
Correct |
8 ms |
12636 KB |
Output is correct |
45 |
Correct |
8 ms |
12636 KB |
Output is correct |
46 |
Correct |
8 ms |
12632 KB |
Output is correct |
47 |
Correct |
8 ms |
12888 KB |
Output is correct |
48 |
Correct |
10 ms |
12636 KB |
Output is correct |
49 |
Correct |
7 ms |
12636 KB |
Output is correct |
50 |
Correct |
7 ms |
12636 KB |
Output is correct |
51 |
Correct |
7 ms |
12636 KB |
Output is correct |
52 |
Correct |
7 ms |
12636 KB |
Output is correct |
53 |
Correct |
7 ms |
12636 KB |
Output is correct |
54 |
Correct |
6 ms |
12636 KB |
Output is correct |
55 |
Correct |
6 ms |
12636 KB |
Output is correct |
56 |
Correct |
6 ms |
12636 KB |
Output is correct |
57 |
Correct |
7 ms |
12636 KB |
Output is correct |
58 |
Correct |
7 ms |
12636 KB |
Output is correct |
59 |
Correct |
165 ms |
12780 KB |
Output is correct |
60 |
Correct |
150 ms |
12636 KB |
Output is correct |
61 |
Correct |
142 ms |
12636 KB |
Output is correct |
62 |
Correct |
167 ms |
12784 KB |
Output is correct |
63 |
Correct |
162 ms |
12788 KB |
Output is correct |
64 |
Correct |
227 ms |
12884 KB |
Output is correct |
65 |
Correct |
214 ms |
12784 KB |
Output is correct |
66 |
Correct |
216 ms |
12888 KB |
Output is correct |
67 |
Correct |
211 ms |
12880 KB |
Output is correct |
68 |
Correct |
209 ms |
12632 KB |
Output is correct |
69 |
Correct |
123 ms |
12784 KB |
Output is correct |
70 |
Correct |
127 ms |
12784 KB |
Output is correct |
71 |
Correct |
137 ms |
12784 KB |
Output is correct |
72 |
Correct |
134 ms |
12632 KB |
Output is correct |
73 |
Correct |
132 ms |
12636 KB |
Output is correct |
74 |
Correct |
36 ms |
12632 KB |
Output is correct |
75 |
Correct |
33 ms |
12632 KB |
Output is correct |
76 |
Correct |
33 ms |
12636 KB |
Output is correct |
77 |
Correct |
35 ms |
12692 KB |
Output is correct |
78 |
Correct |
34 ms |
12636 KB |
Output is correct |