#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
long long mod = 1000000007LL;
long long fastpow(long long base, int ex){
if(ex==0){
return 1LL;
}
if(ex%2==1){
return (base * fastpow(base,ex-1))%mod;
}
else{
return fastpow((base*base)%mod,ex/2);
}
}
long long modinv(long long x){
return fastpow(x,(int)mod-2);
}
long long choose(long long n, long long k){
if(k<0LL || k>n){
return 0LL;
}
long long ret = 1LL;
for(long long i = 0; i<k; i++){
ret *= (n-i);
ret %= mod;
ret *= modinv(i+1);
ret %= mod;
}
return ret;
}
int main(){
int n;
cin >> n;
int a[n+1];
int b[n+1];
a[0] = -10;
b[0] = -10;
for(int i = 1; i<=n; i++){
cin >> a[i] >> b[i];
}
vector<int> all;
for(int i = 1; i<=n; i++){
all.push_back(b[i]);
all.push_back(a[i]-1);
}
sort(all.begin(),all.end());
vector<int> extralist;
extralist.push_back(all[0]);
for(int i = 1; i<all.size(); i++){
if(all[i]!=all[i-1]){
extralist.push_back(all[i]);
}
}
all = extralist;
extralist.clear();
long long dp[n+1];
dp[0] = 1LL;
for(int i = 1; i<=n; i++){
dp[i] = 0LL;
}
for(int i = 1; i<all.size(); i++){
int curVal = all[i];
long long k = all[i]-all[i-1];
vector<long long> inds;
vector<long long> li;
vector<long long> li2;
long long sum = 0LL;
for(int j = 0; j<=n; j++){
if(a[j]<=curVal && curVal<=b[j]){
inds.push_back(j);
li.push_back(dp[j]);
li2.push_back(sum);
}
else{
sum += dp[j];
sum %= mod;
}
}
for(int j = 0; j<li2.size(); j++){
li.push_back(li2[j]);
}
int sz = inds.size();
long long next[sz];
for(int j = 0; j<sz; j++){
next[j] = 0LL;
}
long long cn = sz+k-2LL;
long long ck = sz;
long long cur = -1LL;
if(ck>=0 && ck<=cn){
cur = choose(cn,ck);
}
for(int h = 0; h<sz; h++){
next[sz-1-h] += k*li2[sz-1-h];
next[sz-1-h] %= mod;
}
for(int j = 0; j+1<sz; j++){
if(ck<0 || ck>cn){
break;
}
for(int h = 0; h<=j; h++){
next[sz-1-h] += li2[j-h]*cur;
next[sz-1-h] %= mod;
}
if(j+1<sz){
cn--;
ck--;
if(ck<0){
break;
}
cur *= modinv(cn+1LL);
cur %= mod;
cur *= ck+1LL;
cur %= mod;
}
}
cn = sz+k-2LL;
ck = sz-1LL;
cur = -1LL;
if(ck>=0 && ck<=cn){
cur = choose(cn,ck);
}
for(int h = 0; h<sz; h++){
next[sz-1-h] += li[sz-1-h];
next[sz-1-h] %= mod;
}
for(int j = 0; j+1<sz; j++){
if(ck<0 || ck>cn){
break;
}
for(int h = 0; h<=j; h++){
next[sz-1-h] += li[j-h]*cur;
next[sz-1-h] %= mod;
}
if(j+1<sz){
cn--;
ck--;
if(ck<0){
break;
}
cur *= modinv(cn+1LL);
cur %= mod;
cur *= ck+1LL;
cur %= mod;
}
}
for(int i = 0; i<sz; i++){
dp[inds[i]] = next[i]%mod;
}
//expo stuff
}
long long ans = 0LL;
for(int i = 1; i<=n; i++){
ans += dp[i];
ans %= mod;
}
cout << ans << endl;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:51:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i<all.size(); i++){
^
boat.cpp:63:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i<all.size(); i++){
^
boat.cpp:81:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j<li2.size(); j++){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
248 KB |
Output is correct |
2 |
Correct |
12 ms |
352 KB |
Output is correct |
3 |
Correct |
12 ms |
532 KB |
Output is correct |
4 |
Correct |
13 ms |
532 KB |
Output is correct |
5 |
Correct |
13 ms |
532 KB |
Output is correct |
6 |
Correct |
13 ms |
540 KB |
Output is correct |
7 |
Correct |
12 ms |
556 KB |
Output is correct |
8 |
Correct |
13 ms |
556 KB |
Output is correct |
9 |
Correct |
13 ms |
556 KB |
Output is correct |
10 |
Correct |
12 ms |
560 KB |
Output is correct |
11 |
Correct |
13 ms |
560 KB |
Output is correct |
12 |
Correct |
12 ms |
560 KB |
Output is correct |
13 |
Correct |
14 ms |
576 KB |
Output is correct |
14 |
Correct |
13 ms |
616 KB |
Output is correct |
15 |
Correct |
13 ms |
616 KB |
Output is correct |
16 |
Correct |
5 ms |
616 KB |
Output is correct |
17 |
Correct |
5 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
19 |
Correct |
5 ms |
620 KB |
Output is correct |
20 |
Correct |
5 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
248 KB |
Output is correct |
2 |
Correct |
12 ms |
352 KB |
Output is correct |
3 |
Correct |
12 ms |
532 KB |
Output is correct |
4 |
Correct |
13 ms |
532 KB |
Output is correct |
5 |
Correct |
13 ms |
532 KB |
Output is correct |
6 |
Correct |
13 ms |
540 KB |
Output is correct |
7 |
Correct |
12 ms |
556 KB |
Output is correct |
8 |
Correct |
13 ms |
556 KB |
Output is correct |
9 |
Correct |
13 ms |
556 KB |
Output is correct |
10 |
Correct |
12 ms |
560 KB |
Output is correct |
11 |
Correct |
13 ms |
560 KB |
Output is correct |
12 |
Correct |
12 ms |
560 KB |
Output is correct |
13 |
Correct |
14 ms |
576 KB |
Output is correct |
14 |
Correct |
13 ms |
616 KB |
Output is correct |
15 |
Correct |
13 ms |
616 KB |
Output is correct |
16 |
Correct |
5 ms |
616 KB |
Output is correct |
17 |
Correct |
5 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
19 |
Correct |
5 ms |
620 KB |
Output is correct |
20 |
Correct |
5 ms |
620 KB |
Output is correct |
21 |
Correct |
953 ms |
748 KB |
Output is correct |
22 |
Correct |
915 ms |
764 KB |
Output is correct |
23 |
Correct |
854 ms |
764 KB |
Output is correct |
24 |
Correct |
932 ms |
764 KB |
Output is correct |
25 |
Correct |
940 ms |
764 KB |
Output is correct |
26 |
Correct |
1608 ms |
768 KB |
Output is correct |
27 |
Correct |
1729 ms |
768 KB |
Output is correct |
28 |
Correct |
1640 ms |
872 KB |
Output is correct |
29 |
Correct |
1644 ms |
872 KB |
Output is correct |
30 |
Correct |
16 ms |
872 KB |
Output is correct |
31 |
Correct |
15 ms |
872 KB |
Output is correct |
32 |
Correct |
15 ms |
872 KB |
Output is correct |
33 |
Correct |
15 ms |
872 KB |
Output is correct |
34 |
Correct |
15 ms |
872 KB |
Output is correct |
35 |
Correct |
14 ms |
872 KB |
Output is correct |
36 |
Correct |
14 ms |
872 KB |
Output is correct |
37 |
Correct |
15 ms |
872 KB |
Output is correct |
38 |
Correct |
14 ms |
872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
872 KB |
Output is correct |
2 |
Correct |
25 ms |
872 KB |
Output is correct |
3 |
Correct |
31 ms |
872 KB |
Output is correct |
4 |
Correct |
31 ms |
872 KB |
Output is correct |
5 |
Correct |
33 ms |
872 KB |
Output is correct |
6 |
Correct |
50 ms |
872 KB |
Output is correct |
7 |
Correct |
48 ms |
872 KB |
Output is correct |
8 |
Correct |
48 ms |
872 KB |
Output is correct |
9 |
Correct |
48 ms |
872 KB |
Output is correct |
10 |
Correct |
53 ms |
872 KB |
Output is correct |
11 |
Correct |
33 ms |
872 KB |
Output is correct |
12 |
Correct |
27 ms |
872 KB |
Output is correct |
13 |
Correct |
31 ms |
872 KB |
Output is correct |
14 |
Correct |
31 ms |
872 KB |
Output is correct |
15 |
Correct |
32 ms |
872 KB |
Output is correct |
16 |
Correct |
18 ms |
872 KB |
Output is correct |
17 |
Correct |
16 ms |
872 KB |
Output is correct |
18 |
Correct |
18 ms |
872 KB |
Output is correct |
19 |
Correct |
16 ms |
872 KB |
Output is correct |
20 |
Correct |
18 ms |
872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
248 KB |
Output is correct |
2 |
Correct |
12 ms |
352 KB |
Output is correct |
3 |
Correct |
12 ms |
532 KB |
Output is correct |
4 |
Correct |
13 ms |
532 KB |
Output is correct |
5 |
Correct |
13 ms |
532 KB |
Output is correct |
6 |
Correct |
13 ms |
540 KB |
Output is correct |
7 |
Correct |
12 ms |
556 KB |
Output is correct |
8 |
Correct |
13 ms |
556 KB |
Output is correct |
9 |
Correct |
13 ms |
556 KB |
Output is correct |
10 |
Correct |
12 ms |
560 KB |
Output is correct |
11 |
Correct |
13 ms |
560 KB |
Output is correct |
12 |
Correct |
12 ms |
560 KB |
Output is correct |
13 |
Correct |
14 ms |
576 KB |
Output is correct |
14 |
Correct |
13 ms |
616 KB |
Output is correct |
15 |
Correct |
13 ms |
616 KB |
Output is correct |
16 |
Correct |
5 ms |
616 KB |
Output is correct |
17 |
Correct |
5 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
19 |
Correct |
5 ms |
620 KB |
Output is correct |
20 |
Correct |
5 ms |
620 KB |
Output is correct |
21 |
Correct |
953 ms |
748 KB |
Output is correct |
22 |
Correct |
915 ms |
764 KB |
Output is correct |
23 |
Correct |
854 ms |
764 KB |
Output is correct |
24 |
Correct |
932 ms |
764 KB |
Output is correct |
25 |
Correct |
940 ms |
764 KB |
Output is correct |
26 |
Correct |
1608 ms |
768 KB |
Output is correct |
27 |
Correct |
1729 ms |
768 KB |
Output is correct |
28 |
Correct |
1640 ms |
872 KB |
Output is correct |
29 |
Correct |
1644 ms |
872 KB |
Output is correct |
30 |
Correct |
16 ms |
872 KB |
Output is correct |
31 |
Correct |
15 ms |
872 KB |
Output is correct |
32 |
Correct |
15 ms |
872 KB |
Output is correct |
33 |
Correct |
15 ms |
872 KB |
Output is correct |
34 |
Correct |
15 ms |
872 KB |
Output is correct |
35 |
Correct |
14 ms |
872 KB |
Output is correct |
36 |
Correct |
14 ms |
872 KB |
Output is correct |
37 |
Correct |
15 ms |
872 KB |
Output is correct |
38 |
Correct |
14 ms |
872 KB |
Output is correct |
39 |
Correct |
31 ms |
872 KB |
Output is correct |
40 |
Correct |
25 ms |
872 KB |
Output is correct |
41 |
Correct |
31 ms |
872 KB |
Output is correct |
42 |
Correct |
31 ms |
872 KB |
Output is correct |
43 |
Correct |
33 ms |
872 KB |
Output is correct |
44 |
Correct |
50 ms |
872 KB |
Output is correct |
45 |
Correct |
48 ms |
872 KB |
Output is correct |
46 |
Correct |
48 ms |
872 KB |
Output is correct |
47 |
Correct |
48 ms |
872 KB |
Output is correct |
48 |
Correct |
53 ms |
872 KB |
Output is correct |
49 |
Correct |
33 ms |
872 KB |
Output is correct |
50 |
Correct |
27 ms |
872 KB |
Output is correct |
51 |
Correct |
31 ms |
872 KB |
Output is correct |
52 |
Correct |
31 ms |
872 KB |
Output is correct |
53 |
Correct |
32 ms |
872 KB |
Output is correct |
54 |
Correct |
18 ms |
872 KB |
Output is correct |
55 |
Correct |
16 ms |
872 KB |
Output is correct |
56 |
Correct |
18 ms |
872 KB |
Output is correct |
57 |
Correct |
16 ms |
872 KB |
Output is correct |
58 |
Correct |
18 ms |
872 KB |
Output is correct |
59 |
Correct |
1153 ms |
872 KB |
Output is correct |
60 |
Correct |
1053 ms |
872 KB |
Output is correct |
61 |
Correct |
1029 ms |
872 KB |
Output is correct |
62 |
Correct |
1153 ms |
880 KB |
Output is correct |
63 |
Correct |
1099 ms |
880 KB |
Output is correct |
64 |
Execution timed out |
2033 ms |
880 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |