#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n0 = 1003, mod = 1e9 + 7;
int n, l[n0], r[n0], k, inv[n0];
void add(int & x, int y) {
x += y;
if (x >= mod) x -= mod;
}
int bp(int x, int y) {
int res = 1;
while (y) {
if (y & 1)
res = (ll)res * x % mod;
x = (ll)x * x % mod;
y /= 2;
}
return res;
}
struct Block {
int l = 0, r = 0, t = 0;
int val[n0], c[n0], cur = 0, last = 0;
Block() {
c[0] = 1;
}
void upd(int x) {
val[t++] = x;
c[t] = ((ll)c[t - 1] * (r - l + t) % mod) * inv[t] % mod;
cur = last = 0;
for (int i = 0; i < t; i++) {
add(cur, (ll)c[t - i] * val[i] % mod);
add(last, (ll)c[t - i - 1] * val[i] % mod);
}
}
};
Block b[n0];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
for (int i = 1; i < n0; i++)
inv[i] = bp(i, mod - 2);
cin >> n;
vector <int> crd;
for (int i = 0; i < n; i++) {
cin >> l[i] >> r[i];
r[i]++;
crd.pb(l[i]), crd.pb(r[i]);
}
crd.pb(0), crd.pb(1);
sort(all(crd));
for (int i = 1; i < SZ(crd); i++) {
if (crd[i - 1] < crd[i]) {
b[k].l = crd[i - 1];
b[k++].r = crd[i] - 1;
}
}
b[0].upd(1);
for (int i = 0; i < n; i++) {
int cur = 0, j = 0;
for (; j < k && b[j].r < l[i]; j++)
add(cur, b[j].cur);
for (; j < k && b[j].r < r[i]; j++) {
b[j].upd(cur);
cur = b[j].last;
}
}
int res = 0;
for (int i = 0; i < k; i++)
add(res, b[i].cur);
add(res, mod - 1);
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8320 KB |
Output is correct |
2 |
Correct |
6 ms |
8320 KB |
Output is correct |
3 |
Correct |
5 ms |
8320 KB |
Output is correct |
4 |
Correct |
6 ms |
8320 KB |
Output is correct |
5 |
Correct |
8 ms |
8320 KB |
Output is correct |
6 |
Correct |
6 ms |
8320 KB |
Output is correct |
7 |
Correct |
6 ms |
8320 KB |
Output is correct |
8 |
Correct |
6 ms |
8320 KB |
Output is correct |
9 |
Correct |
6 ms |
8192 KB |
Output is correct |
10 |
Correct |
7 ms |
8320 KB |
Output is correct |
11 |
Correct |
5 ms |
8320 KB |
Output is correct |
12 |
Correct |
7 ms |
8320 KB |
Output is correct |
13 |
Correct |
7 ms |
8320 KB |
Output is correct |
14 |
Correct |
7 ms |
8320 KB |
Output is correct |
15 |
Correct |
6 ms |
8320 KB |
Output is correct |
16 |
Correct |
5 ms |
8320 KB |
Output is correct |
17 |
Correct |
6 ms |
8320 KB |
Output is correct |
18 |
Correct |
5 ms |
8320 KB |
Output is correct |
19 |
Correct |
4 ms |
8320 KB |
Output is correct |
20 |
Correct |
6 ms |
8320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8320 KB |
Output is correct |
2 |
Correct |
6 ms |
8320 KB |
Output is correct |
3 |
Correct |
5 ms |
8320 KB |
Output is correct |
4 |
Correct |
6 ms |
8320 KB |
Output is correct |
5 |
Correct |
8 ms |
8320 KB |
Output is correct |
6 |
Correct |
6 ms |
8320 KB |
Output is correct |
7 |
Correct |
6 ms |
8320 KB |
Output is correct |
8 |
Correct |
6 ms |
8320 KB |
Output is correct |
9 |
Correct |
6 ms |
8192 KB |
Output is correct |
10 |
Correct |
7 ms |
8320 KB |
Output is correct |
11 |
Correct |
5 ms |
8320 KB |
Output is correct |
12 |
Correct |
7 ms |
8320 KB |
Output is correct |
13 |
Correct |
7 ms |
8320 KB |
Output is correct |
14 |
Correct |
7 ms |
8320 KB |
Output is correct |
15 |
Correct |
6 ms |
8320 KB |
Output is correct |
16 |
Correct |
5 ms |
8320 KB |
Output is correct |
17 |
Correct |
6 ms |
8320 KB |
Output is correct |
18 |
Correct |
5 ms |
8320 KB |
Output is correct |
19 |
Correct |
4 ms |
8320 KB |
Output is correct |
20 |
Correct |
6 ms |
8320 KB |
Output is correct |
21 |
Correct |
118 ms |
8308 KB |
Output is correct |
22 |
Correct |
113 ms |
8192 KB |
Output is correct |
23 |
Correct |
129 ms |
8312 KB |
Output is correct |
24 |
Correct |
107 ms |
8312 KB |
Output is correct |
25 |
Correct |
108 ms |
8192 KB |
Output is correct |
26 |
Correct |
230 ms |
8320 KB |
Output is correct |
27 |
Correct |
267 ms |
8312 KB |
Output is correct |
28 |
Correct |
237 ms |
8192 KB |
Output is correct |
29 |
Correct |
233 ms |
8312 KB |
Output is correct |
30 |
Correct |
6 ms |
8320 KB |
Output is correct |
31 |
Correct |
6 ms |
8320 KB |
Output is correct |
32 |
Correct |
5 ms |
8320 KB |
Output is correct |
33 |
Correct |
7 ms |
8192 KB |
Output is correct |
34 |
Correct |
5 ms |
8320 KB |
Output is correct |
35 |
Correct |
6 ms |
8320 KB |
Output is correct |
36 |
Correct |
5 ms |
8320 KB |
Output is correct |
37 |
Correct |
6 ms |
8320 KB |
Output is correct |
38 |
Correct |
5 ms |
8320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8192 KB |
Output is correct |
2 |
Correct |
6 ms |
8192 KB |
Output is correct |
3 |
Correct |
7 ms |
8320 KB |
Output is correct |
4 |
Correct |
7 ms |
8192 KB |
Output is correct |
5 |
Correct |
6 ms |
8192 KB |
Output is correct |
6 |
Correct |
7 ms |
8192 KB |
Output is correct |
7 |
Correct |
7 ms |
8192 KB |
Output is correct |
8 |
Correct |
7 ms |
8192 KB |
Output is correct |
9 |
Correct |
8 ms |
8192 KB |
Output is correct |
10 |
Correct |
9 ms |
8192 KB |
Output is correct |
11 |
Correct |
7 ms |
8192 KB |
Output is correct |
12 |
Correct |
6 ms |
8192 KB |
Output is correct |
13 |
Correct |
6 ms |
8192 KB |
Output is correct |
14 |
Correct |
6 ms |
8192 KB |
Output is correct |
15 |
Correct |
6 ms |
8192 KB |
Output is correct |
16 |
Correct |
5 ms |
8192 KB |
Output is correct |
17 |
Correct |
5 ms |
8192 KB |
Output is correct |
18 |
Correct |
5 ms |
8192 KB |
Output is correct |
19 |
Correct |
5 ms |
8192 KB |
Output is correct |
20 |
Correct |
6 ms |
8192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8320 KB |
Output is correct |
2 |
Correct |
6 ms |
8320 KB |
Output is correct |
3 |
Correct |
5 ms |
8320 KB |
Output is correct |
4 |
Correct |
6 ms |
8320 KB |
Output is correct |
5 |
Correct |
8 ms |
8320 KB |
Output is correct |
6 |
Correct |
6 ms |
8320 KB |
Output is correct |
7 |
Correct |
6 ms |
8320 KB |
Output is correct |
8 |
Correct |
6 ms |
8320 KB |
Output is correct |
9 |
Correct |
6 ms |
8192 KB |
Output is correct |
10 |
Correct |
7 ms |
8320 KB |
Output is correct |
11 |
Correct |
5 ms |
8320 KB |
Output is correct |
12 |
Correct |
7 ms |
8320 KB |
Output is correct |
13 |
Correct |
7 ms |
8320 KB |
Output is correct |
14 |
Correct |
7 ms |
8320 KB |
Output is correct |
15 |
Correct |
6 ms |
8320 KB |
Output is correct |
16 |
Correct |
5 ms |
8320 KB |
Output is correct |
17 |
Correct |
6 ms |
8320 KB |
Output is correct |
18 |
Correct |
5 ms |
8320 KB |
Output is correct |
19 |
Correct |
4 ms |
8320 KB |
Output is correct |
20 |
Correct |
6 ms |
8320 KB |
Output is correct |
21 |
Correct |
118 ms |
8308 KB |
Output is correct |
22 |
Correct |
113 ms |
8192 KB |
Output is correct |
23 |
Correct |
129 ms |
8312 KB |
Output is correct |
24 |
Correct |
107 ms |
8312 KB |
Output is correct |
25 |
Correct |
108 ms |
8192 KB |
Output is correct |
26 |
Correct |
230 ms |
8320 KB |
Output is correct |
27 |
Correct |
267 ms |
8312 KB |
Output is correct |
28 |
Correct |
237 ms |
8192 KB |
Output is correct |
29 |
Correct |
233 ms |
8312 KB |
Output is correct |
30 |
Correct |
6 ms |
8320 KB |
Output is correct |
31 |
Correct |
6 ms |
8320 KB |
Output is correct |
32 |
Correct |
5 ms |
8320 KB |
Output is correct |
33 |
Correct |
7 ms |
8192 KB |
Output is correct |
34 |
Correct |
5 ms |
8320 KB |
Output is correct |
35 |
Correct |
6 ms |
8320 KB |
Output is correct |
36 |
Correct |
5 ms |
8320 KB |
Output is correct |
37 |
Correct |
6 ms |
8320 KB |
Output is correct |
38 |
Correct |
5 ms |
8320 KB |
Output is correct |
39 |
Correct |
7 ms |
8192 KB |
Output is correct |
40 |
Correct |
6 ms |
8192 KB |
Output is correct |
41 |
Correct |
7 ms |
8320 KB |
Output is correct |
42 |
Correct |
7 ms |
8192 KB |
Output is correct |
43 |
Correct |
6 ms |
8192 KB |
Output is correct |
44 |
Correct |
7 ms |
8192 KB |
Output is correct |
45 |
Correct |
7 ms |
8192 KB |
Output is correct |
46 |
Correct |
7 ms |
8192 KB |
Output is correct |
47 |
Correct |
8 ms |
8192 KB |
Output is correct |
48 |
Correct |
9 ms |
8192 KB |
Output is correct |
49 |
Correct |
7 ms |
8192 KB |
Output is correct |
50 |
Correct |
6 ms |
8192 KB |
Output is correct |
51 |
Correct |
6 ms |
8192 KB |
Output is correct |
52 |
Correct |
6 ms |
8192 KB |
Output is correct |
53 |
Correct |
6 ms |
8192 KB |
Output is correct |
54 |
Correct |
5 ms |
8192 KB |
Output is correct |
55 |
Correct |
5 ms |
8192 KB |
Output is correct |
56 |
Correct |
5 ms |
8192 KB |
Output is correct |
57 |
Correct |
5 ms |
8192 KB |
Output is correct |
58 |
Correct |
6 ms |
8192 KB |
Output is correct |
59 |
Correct |
122 ms |
8440 KB |
Output is correct |
60 |
Correct |
116 ms |
8320 KB |
Output is correct |
61 |
Correct |
110 ms |
8320 KB |
Output is correct |
62 |
Correct |
125 ms |
8320 KB |
Output is correct |
63 |
Correct |
130 ms |
8320 KB |
Output is correct |
64 |
Correct |
336 ms |
8320 KB |
Output is correct |
65 |
Correct |
266 ms |
8320 KB |
Output is correct |
66 |
Correct |
286 ms |
8320 KB |
Output is correct |
67 |
Correct |
288 ms |
8320 KB |
Output is correct |
68 |
Correct |
267 ms |
8320 KB |
Output is correct |
69 |
Correct |
101 ms |
8320 KB |
Output is correct |
70 |
Correct |
104 ms |
8320 KB |
Output is correct |
71 |
Correct |
103 ms |
8320 KB |
Output is correct |
72 |
Correct |
124 ms |
8320 KB |
Output is correct |
73 |
Correct |
124 ms |
8320 KB |
Output is correct |
74 |
Correct |
28 ms |
8320 KB |
Output is correct |
75 |
Correct |
26 ms |
8320 KB |
Output is correct |
76 |
Correct |
34 ms |
8312 KB |
Output is correct |
77 |
Correct |
28 ms |
8320 KB |
Output is correct |
78 |
Correct |
31 ms |
8320 KB |
Output is correct |