#include <bits/stdc++.h>
using namespace std;
int N;
pair<int,int> lst[510];
int a, b;
long long int mod = 1'000'000'007;
long long int p[510];
long long int fact[510];
vector<int> de;
vector<int> bat[1100];
map<int,int> mep;
long long int expo(long long int x, long long int b, long long int mul){
if(mul == 0) return x;
if(mul % 2 == 1){
return expo(x * b % mod, b * b % mod, mul / 2);
}
else{
return expo(x, b * b % mod, mul / 2);
}
}
int main(){
scanf(" %d",&N);
for(int i = 1; i <= N; i++){
scanf(" %d",&a);
scanf(" %d",&b);
lst[i] = {a,b};
de.push_back(a);
de.push_back(b + 1);
p[i] = 0;
}
p[N + 1] = 0;
p[0] = 1;
fact[0] = 1;
for(int i = 1; i <= N; i++){
fact[i] = fact[i - 1] * i % mod;
}
sort(de.begin(),de.end());
de.resize(unique(de.begin(),de.end()) - de.begin());
for(int i = 0; i < de.size(); i++){
mep[de[i]] = i;
}
for(int i = 1; i <= N; i++){
for(int j = 0; j < de.size(); j++){
if(lst[i].first <= de[j] && de[j] <= lst[i].second){
bat[j].push_back(i);
}
}
}
bat[de.size() - 1].push_back(N + 1);
de.push_back(1100100100);
for(int i = 0; i < de.size() - 1; i++){
long long int mul[510];
mul[0] = 1;
int c = de[i + 1] - de[i];
for(int i = 1; i < 510; i++){
mul[i] = mul[i - 1] * (i + c - 1) % mod;
}
for(int i = 0; i < 510; i++){
mul[i] = expo(mul[i], fact[i], mod - 2);
}
vector<int> v = {0};
long long int pst[510];
for(int i = 0; i <= 501; i++){
pst[i] = 0;
}
for(int j = 0; j < bat[i].size(); j++){
v.push_back(bat[i][j]);
long long int sum = 0;
for(int k = 0; k < v.size() - 1; k++){
int ni = v.size();
for(int i = v[ni - 2 - k]; i <= v[ni - 1 - k] - 1; i++){
sum = (sum + p[i] * mul[k]) % mod;
}
}
pst[bat[i][j]] = sum;
}
for(int i = 0; i <= 501; i++){
p[i] = (p[i] + pst[i]) % mod;
}
}
/*for(int i = 0; i <= N + 1; i++){
printf("%lld ",p[i]);
}*/
printf("%lld",(p[N + 1] - 1 + mod) % mod);
}
/*
3
1 2
2 4
2 4
2
1 2
2 4
*/
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0; i < de.size(); i++){
| ~~^~~~~~~~~~~
boat.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int j = 0; j < de.size(); j++){
| ~~^~~~~~~~~~~
boat.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0; i < de.size() - 1; i++){
| ~~^~~~~~~~~~~~~~~
boat.cpp:86:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int j = 0; j < bat[i].size(); j++){
| ~~^~~~~~~~~~~~~~~
boat.cpp:90:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(int k = 0; k < v.size() - 1; k++){
| ~~^~~~~~~~~~~~~~
boat.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf(" %d",&N);
| ~~~~~^~~~~~~~~~
boat.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf(" %d",&a);
| ~~~~~^~~~~~~~~~
boat.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf(" %d",&b);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
344 KB |
Output is correct |
2 |
Correct |
198 ms |
520 KB |
Output is correct |
3 |
Correct |
199 ms |
520 KB |
Output is correct |
4 |
Correct |
199 ms |
528 KB |
Output is correct |
5 |
Correct |
198 ms |
524 KB |
Output is correct |
6 |
Correct |
198 ms |
520 KB |
Output is correct |
7 |
Correct |
198 ms |
524 KB |
Output is correct |
8 |
Correct |
199 ms |
596 KB |
Output is correct |
9 |
Correct |
199 ms |
592 KB |
Output is correct |
10 |
Correct |
199 ms |
348 KB |
Output is correct |
11 |
Correct |
198 ms |
524 KB |
Output is correct |
12 |
Correct |
198 ms |
596 KB |
Output is correct |
13 |
Correct |
199 ms |
344 KB |
Output is correct |
14 |
Correct |
198 ms |
524 KB |
Output is correct |
15 |
Correct |
198 ms |
524 KB |
Output is correct |
16 |
Correct |
36 ms |
348 KB |
Output is correct |
17 |
Correct |
39 ms |
348 KB |
Output is correct |
18 |
Correct |
37 ms |
348 KB |
Output is correct |
19 |
Correct |
39 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
344 KB |
Output is correct |
2 |
Correct |
198 ms |
520 KB |
Output is correct |
3 |
Correct |
199 ms |
520 KB |
Output is correct |
4 |
Correct |
199 ms |
528 KB |
Output is correct |
5 |
Correct |
198 ms |
524 KB |
Output is correct |
6 |
Correct |
198 ms |
520 KB |
Output is correct |
7 |
Correct |
198 ms |
524 KB |
Output is correct |
8 |
Correct |
199 ms |
596 KB |
Output is correct |
9 |
Correct |
199 ms |
592 KB |
Output is correct |
10 |
Correct |
199 ms |
348 KB |
Output is correct |
11 |
Correct |
198 ms |
524 KB |
Output is correct |
12 |
Correct |
198 ms |
596 KB |
Output is correct |
13 |
Correct |
199 ms |
344 KB |
Output is correct |
14 |
Correct |
198 ms |
524 KB |
Output is correct |
15 |
Correct |
198 ms |
524 KB |
Output is correct |
16 |
Correct |
36 ms |
348 KB |
Output is correct |
17 |
Correct |
39 ms |
348 KB |
Output is correct |
18 |
Correct |
37 ms |
348 KB |
Output is correct |
19 |
Correct |
39 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
348 KB |
Output is correct |
21 |
Incorrect |
407 ms |
1600 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
344 KB |
Output is correct |
2 |
Correct |
198 ms |
520 KB |
Output is correct |
3 |
Correct |
199 ms |
520 KB |
Output is correct |
4 |
Correct |
199 ms |
528 KB |
Output is correct |
5 |
Correct |
198 ms |
524 KB |
Output is correct |
6 |
Correct |
198 ms |
520 KB |
Output is correct |
7 |
Correct |
198 ms |
524 KB |
Output is correct |
8 |
Correct |
199 ms |
596 KB |
Output is correct |
9 |
Correct |
199 ms |
592 KB |
Output is correct |
10 |
Correct |
199 ms |
348 KB |
Output is correct |
11 |
Correct |
198 ms |
524 KB |
Output is correct |
12 |
Correct |
198 ms |
596 KB |
Output is correct |
13 |
Correct |
199 ms |
344 KB |
Output is correct |
14 |
Correct |
198 ms |
524 KB |
Output is correct |
15 |
Correct |
198 ms |
524 KB |
Output is correct |
16 |
Correct |
36 ms |
348 KB |
Output is correct |
17 |
Correct |
39 ms |
348 KB |
Output is correct |
18 |
Correct |
37 ms |
348 KB |
Output is correct |
19 |
Correct |
39 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
348 KB |
Output is correct |
21 |
Incorrect |
407 ms |
1600 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |