#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
const int maxn = 5e2 + 20;
const long long mod = 1e9 + 7;
bool flag[maxn];
long long inv[maxn];
long long fact_inv[maxn];
long long cur[maxn];
long long nxt[maxn];
pair<int, int> events[maxn * 2];
int n;
void trans() {
for (int i = 1; i <= n; i++) {
if (flag[i]) {
nxt[i] = cur[i] + 1;
if (nxt[i] >= mod) {
nxt[i] -= mod;
}
}
else {
nxt[i] = cur[i];
}
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (flag[j]) {
nxt[j] += cur[i];
if (nxt[j] >= mod) {
nxt[j] -= mod;
}
}
}
}
swap(cur, nxt);
}
void shift(int len) {
for (int i = 1; i <= n; i++) {
if (flag[i]) {
nxt[i] = (cur[i] + len) % mod;
}
else {
nxt[i] = cur[i];
}
}
for (int i = 1; i <= n; i++) {
int cnt = 0;
long long num = 1;
for (int j = i + 1; j <= n; j++) {
if (flag[j]) {
cnt++;
num = num * (len + cnt - 1) % mod;
if (flag[i]) {
nxt[j] = (nxt[j] + cur[i] * num % mod * fact_inv[cnt] % mod + num * (len - 1) % mod * fact_inv[cnt + 1] % mod) % mod;
}
else {
nxt[j] = (nxt[j] + cur[i] * num % mod * fact_inv[cnt] % mod) % mod;
}
}
}
}
swap(cur, nxt);
}
void just_do_it() {
inv[1] = 1;
fact_inv[0] = 1;
fact_inv[1] = 1;
for (int i = 2; i < maxn; i++) {
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
}
cin >> n;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
events[i * 2 - 1] = make_pair(a, i);
events[i * 2] = make_pair(b + 1, -i);
}
sort(events + 1, events + n * 2 + 1);
int cur_t = 0;
for (int i = 1; i <= n * 2; i++) {
int nxt_t = events[i].first;
int id = events[i].second;
bool begin_t = (i == 1 || events[i].first != events[i - 1].first);
bool end_t = (i == n * 2 || events[i].first != events[i + 1].first);
if (begin_t) {
if (cur_t < nxt_t - 1) {
shift(nxt_t - 1 - cur_t);
cur_t = nxt_t - 1;
}
}
if (id > 0) {
flag[id] = true;
}
else {
flag[-id] = false;
}
if (end_t && cur_t == nxt_t - 1) {
trans();
cur_t = nxt_t;
}
}
long long res = 0;
for (int i = 1; i <= n; i++) {
res += cur[i];
res %= mod;
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
340 KB |
Output is correct |
2 |
Correct |
148 ms |
320 KB |
Output is correct |
3 |
Correct |
150 ms |
340 KB |
Output is correct |
4 |
Correct |
149 ms |
320 KB |
Output is correct |
5 |
Correct |
141 ms |
340 KB |
Output is correct |
6 |
Correct |
151 ms |
340 KB |
Output is correct |
7 |
Correct |
145 ms |
340 KB |
Output is correct |
8 |
Correct |
144 ms |
320 KB |
Output is correct |
9 |
Correct |
142 ms |
340 KB |
Output is correct |
10 |
Correct |
147 ms |
340 KB |
Output is correct |
11 |
Correct |
163 ms |
324 KB |
Output is correct |
12 |
Correct |
138 ms |
320 KB |
Output is correct |
13 |
Correct |
138 ms |
212 KB |
Output is correct |
14 |
Correct |
138 ms |
340 KB |
Output is correct |
15 |
Correct |
160 ms |
340 KB |
Output is correct |
16 |
Correct |
26 ms |
340 KB |
Output is correct |
17 |
Correct |
30 ms |
348 KB |
Output is correct |
18 |
Correct |
27 ms |
340 KB |
Output is correct |
19 |
Correct |
28 ms |
340 KB |
Output is correct |
20 |
Correct |
29 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
340 KB |
Output is correct |
2 |
Correct |
148 ms |
320 KB |
Output is correct |
3 |
Correct |
150 ms |
340 KB |
Output is correct |
4 |
Correct |
149 ms |
320 KB |
Output is correct |
5 |
Correct |
141 ms |
340 KB |
Output is correct |
6 |
Correct |
151 ms |
340 KB |
Output is correct |
7 |
Correct |
145 ms |
340 KB |
Output is correct |
8 |
Correct |
144 ms |
320 KB |
Output is correct |
9 |
Correct |
142 ms |
340 KB |
Output is correct |
10 |
Correct |
147 ms |
340 KB |
Output is correct |
11 |
Correct |
163 ms |
324 KB |
Output is correct |
12 |
Correct |
138 ms |
320 KB |
Output is correct |
13 |
Correct |
138 ms |
212 KB |
Output is correct |
14 |
Correct |
138 ms |
340 KB |
Output is correct |
15 |
Correct |
160 ms |
340 KB |
Output is correct |
16 |
Correct |
26 ms |
340 KB |
Output is correct |
17 |
Correct |
30 ms |
348 KB |
Output is correct |
18 |
Correct |
27 ms |
340 KB |
Output is correct |
19 |
Correct |
28 ms |
340 KB |
Output is correct |
20 |
Correct |
29 ms |
340 KB |
Output is correct |
21 |
Correct |
724 ms |
340 KB |
Output is correct |
22 |
Correct |
698 ms |
340 KB |
Output is correct |
23 |
Correct |
706 ms |
340 KB |
Output is correct |
24 |
Correct |
789 ms |
340 KB |
Output is correct |
25 |
Correct |
726 ms |
340 KB |
Output is correct |
26 |
Correct |
571 ms |
340 KB |
Output is correct |
27 |
Correct |
589 ms |
340 KB |
Output is correct |
28 |
Correct |
590 ms |
340 KB |
Output is correct |
29 |
Correct |
614 ms |
340 KB |
Output is correct |
30 |
Correct |
209 ms |
340 KB |
Output is correct |
31 |
Correct |
190 ms |
340 KB |
Output is correct |
32 |
Correct |
187 ms |
340 KB |
Output is correct |
33 |
Correct |
194 ms |
340 KB |
Output is correct |
34 |
Correct |
200 ms |
348 KB |
Output is correct |
35 |
Correct |
144 ms |
460 KB |
Output is correct |
36 |
Correct |
169 ms |
340 KB |
Output is correct |
37 |
Correct |
152 ms |
340 KB |
Output is correct |
38 |
Correct |
153 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
212 KB |
Output is correct |
2 |
Correct |
8 ms |
212 KB |
Output is correct |
3 |
Correct |
7 ms |
336 KB |
Output is correct |
4 |
Correct |
8 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
336 KB |
Output is correct |
6 |
Correct |
8 ms |
332 KB |
Output is correct |
7 |
Correct |
8 ms |
340 KB |
Output is correct |
8 |
Correct |
9 ms |
336 KB |
Output is correct |
9 |
Correct |
9 ms |
336 KB |
Output is correct |
10 |
Correct |
8 ms |
212 KB |
Output is correct |
11 |
Correct |
6 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
340 KB |
Output is correct |
13 |
Correct |
6 ms |
212 KB |
Output is correct |
14 |
Correct |
9 ms |
212 KB |
Output is correct |
15 |
Correct |
7 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
5 ms |
212 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
4 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
340 KB |
Output is correct |
2 |
Correct |
148 ms |
320 KB |
Output is correct |
3 |
Correct |
150 ms |
340 KB |
Output is correct |
4 |
Correct |
149 ms |
320 KB |
Output is correct |
5 |
Correct |
141 ms |
340 KB |
Output is correct |
6 |
Correct |
151 ms |
340 KB |
Output is correct |
7 |
Correct |
145 ms |
340 KB |
Output is correct |
8 |
Correct |
144 ms |
320 KB |
Output is correct |
9 |
Correct |
142 ms |
340 KB |
Output is correct |
10 |
Correct |
147 ms |
340 KB |
Output is correct |
11 |
Correct |
163 ms |
324 KB |
Output is correct |
12 |
Correct |
138 ms |
320 KB |
Output is correct |
13 |
Correct |
138 ms |
212 KB |
Output is correct |
14 |
Correct |
138 ms |
340 KB |
Output is correct |
15 |
Correct |
160 ms |
340 KB |
Output is correct |
16 |
Correct |
26 ms |
340 KB |
Output is correct |
17 |
Correct |
30 ms |
348 KB |
Output is correct |
18 |
Correct |
27 ms |
340 KB |
Output is correct |
19 |
Correct |
28 ms |
340 KB |
Output is correct |
20 |
Correct |
29 ms |
340 KB |
Output is correct |
21 |
Correct |
724 ms |
340 KB |
Output is correct |
22 |
Correct |
698 ms |
340 KB |
Output is correct |
23 |
Correct |
706 ms |
340 KB |
Output is correct |
24 |
Correct |
789 ms |
340 KB |
Output is correct |
25 |
Correct |
726 ms |
340 KB |
Output is correct |
26 |
Correct |
571 ms |
340 KB |
Output is correct |
27 |
Correct |
589 ms |
340 KB |
Output is correct |
28 |
Correct |
590 ms |
340 KB |
Output is correct |
29 |
Correct |
614 ms |
340 KB |
Output is correct |
30 |
Correct |
209 ms |
340 KB |
Output is correct |
31 |
Correct |
190 ms |
340 KB |
Output is correct |
32 |
Correct |
187 ms |
340 KB |
Output is correct |
33 |
Correct |
194 ms |
340 KB |
Output is correct |
34 |
Correct |
200 ms |
348 KB |
Output is correct |
35 |
Correct |
144 ms |
460 KB |
Output is correct |
36 |
Correct |
169 ms |
340 KB |
Output is correct |
37 |
Correct |
152 ms |
340 KB |
Output is correct |
38 |
Correct |
153 ms |
340 KB |
Output is correct |
39 |
Correct |
8 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
212 KB |
Output is correct |
41 |
Correct |
7 ms |
336 KB |
Output is correct |
42 |
Correct |
8 ms |
212 KB |
Output is correct |
43 |
Correct |
8 ms |
336 KB |
Output is correct |
44 |
Correct |
8 ms |
332 KB |
Output is correct |
45 |
Correct |
8 ms |
340 KB |
Output is correct |
46 |
Correct |
9 ms |
336 KB |
Output is correct |
47 |
Correct |
9 ms |
336 KB |
Output is correct |
48 |
Correct |
8 ms |
212 KB |
Output is correct |
49 |
Correct |
6 ms |
212 KB |
Output is correct |
50 |
Correct |
6 ms |
340 KB |
Output is correct |
51 |
Correct |
6 ms |
212 KB |
Output is correct |
52 |
Correct |
9 ms |
212 KB |
Output is correct |
53 |
Correct |
7 ms |
340 KB |
Output is correct |
54 |
Correct |
4 ms |
340 KB |
Output is correct |
55 |
Correct |
3 ms |
340 KB |
Output is correct |
56 |
Correct |
5 ms |
212 KB |
Output is correct |
57 |
Correct |
3 ms |
340 KB |
Output is correct |
58 |
Correct |
4 ms |
212 KB |
Output is correct |
59 |
Correct |
890 ms |
340 KB |
Output is correct |
60 |
Correct |
854 ms |
340 KB |
Output is correct |
61 |
Correct |
861 ms |
340 KB |
Output is correct |
62 |
Correct |
877 ms |
340 KB |
Output is correct |
63 |
Correct |
880 ms |
340 KB |
Output is correct |
64 |
Correct |
856 ms |
340 KB |
Output is correct |
65 |
Correct |
833 ms |
340 KB |
Output is correct |
66 |
Correct |
875 ms |
340 KB |
Output is correct |
67 |
Correct |
822 ms |
340 KB |
Output is correct |
68 |
Correct |
835 ms |
340 KB |
Output is correct |
69 |
Correct |
656 ms |
340 KB |
Output is correct |
70 |
Correct |
629 ms |
340 KB |
Output is correct |
71 |
Correct |
627 ms |
340 KB |
Output is correct |
72 |
Correct |
632 ms |
340 KB |
Output is correct |
73 |
Correct |
642 ms |
340 KB |
Output is correct |
74 |
Correct |
126 ms |
340 KB |
Output is correct |
75 |
Correct |
120 ms |
340 KB |
Output is correct |
76 |
Correct |
115 ms |
468 KB |
Output is correct |
77 |
Correct |
116 ms |
328 KB |
Output is correct |
78 |
Correct |
119 ms |
340 KB |
Output is correct |