#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"
const ld PI = 3.1415926535;
const int N = 5e5 + 10;
const int M = 1e5 + 10;
int mod = 1e9+7;
const int infi = INT_MAX;
const ll infl = 2e18;
const int P = 505319;
const ld eps = 1e-9;
int mult(int a, int b){
return a * 1LL * b % mod;
}
int sum(int a, int b){
a %= mod;
b %= mod;
if(a + b >= mod)
return a + b - mod;
if(a + b < 0)
return a + b + mod;
return a + b;
}
int binpow(int a, int n){
if (n == 0)
return 1;
if (n % 2 == 1){
return mult(binpow(a, n - 1), a);
}
else{
auto b = binpow(a, n / 2);
return mult(b, b);
}
}
int n, l[N], r[N], sm[N], f[N], fi[N];
vector<int> al[N];
int C(int n, int k){
return mult(f[n], mult(fi[k], fi[n - k]));
}
void solve(){
cin >> n;
vector<int> di = {};
for(int i = 1; i <= n; i++){
cin >> l[i] >> r[i];
di.pb(l[i]);
di.pb(r[i] + 1);
}
di.pb(0);
sort(all(di));
di.resize(unique(all(di)) - di.begin());
sm[0] = 1;
al[0].pb(1);
for(int i = 1; i <= n; i++){
int cur = 0;
for(int j = 0; j < sz(di) - 1; j++){
int lr = di[j], rr = di[j + 1] - 1;
int len = rr - lr + 1;
if(lr >= l[i] && rr <= r[i]){
al[j].pb(cur);
int nsm = 0;
for(int k = 0; k < sz(al[j]); k++){
nsm =sum(nsm, mult(C(sz(al[j]) - k - 1 + len, sz(al[j]) - k), al[j][k]));
}
cur = sum(cur, sm[j]);
sm[j] = nsm;
}else{
cur = sum(cur, sm[j]);
}
}
}
int ans = 0;
for(int i = 0; i < sz(di) - 1; i++)
ans = sum(ans, sm[i]);
cout << sum(ans, -1) << '\n';
}
signed main(){
mispertion;
f[0] = 1;
for(int i = 1; i < N; i++)
f[i] = mult(f[i - 1], i);
for(int i = 0; i < N; i++){
fi[i] = binpow(f[i], mod - 2);
}
int t = 1;
//cin >> t;
while (t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
20048 KB |
Output is correct |
2 |
Correct |
155 ms |
19996 KB |
Output is correct |
3 |
Correct |
155 ms |
20036 KB |
Output is correct |
4 |
Correct |
156 ms |
20052 KB |
Output is correct |
5 |
Correct |
153 ms |
19872 KB |
Output is correct |
6 |
Correct |
155 ms |
20304 KB |
Output is correct |
7 |
Correct |
155 ms |
20064 KB |
Output is correct |
8 |
Correct |
156 ms |
19968 KB |
Output is correct |
9 |
Correct |
159 ms |
20052 KB |
Output is correct |
10 |
Correct |
156 ms |
20024 KB |
Output is correct |
11 |
Correct |
153 ms |
20048 KB |
Output is correct |
12 |
Correct |
154 ms |
20004 KB |
Output is correct |
13 |
Correct |
155 ms |
19896 KB |
Output is correct |
14 |
Correct |
152 ms |
20048 KB |
Output is correct |
15 |
Correct |
156 ms |
20048 KB |
Output is correct |
16 |
Correct |
158 ms |
19932 KB |
Output is correct |
17 |
Correct |
153 ms |
19836 KB |
Output is correct |
18 |
Correct |
158 ms |
19980 KB |
Output is correct |
19 |
Correct |
153 ms |
20044 KB |
Output is correct |
20 |
Correct |
153 ms |
20048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
20048 KB |
Output is correct |
2 |
Correct |
155 ms |
19996 KB |
Output is correct |
3 |
Correct |
155 ms |
20036 KB |
Output is correct |
4 |
Correct |
156 ms |
20052 KB |
Output is correct |
5 |
Correct |
153 ms |
19872 KB |
Output is correct |
6 |
Correct |
155 ms |
20304 KB |
Output is correct |
7 |
Correct |
155 ms |
20064 KB |
Output is correct |
8 |
Correct |
156 ms |
19968 KB |
Output is correct |
9 |
Correct |
159 ms |
20052 KB |
Output is correct |
10 |
Correct |
156 ms |
20024 KB |
Output is correct |
11 |
Correct |
153 ms |
20048 KB |
Output is correct |
12 |
Correct |
154 ms |
20004 KB |
Output is correct |
13 |
Correct |
155 ms |
19896 KB |
Output is correct |
14 |
Correct |
152 ms |
20048 KB |
Output is correct |
15 |
Correct |
156 ms |
20048 KB |
Output is correct |
16 |
Correct |
158 ms |
19932 KB |
Output is correct |
17 |
Correct |
153 ms |
19836 KB |
Output is correct |
18 |
Correct |
158 ms |
19980 KB |
Output is correct |
19 |
Correct |
153 ms |
20044 KB |
Output is correct |
20 |
Correct |
153 ms |
20048 KB |
Output is correct |
21 |
Correct |
449 ms |
21840 KB |
Output is correct |
22 |
Correct |
450 ms |
21832 KB |
Output is correct |
23 |
Correct |
397 ms |
21592 KB |
Output is correct |
24 |
Correct |
430 ms |
21844 KB |
Output is correct |
25 |
Correct |
446 ms |
21588 KB |
Output is correct |
26 |
Correct |
797 ms |
22352 KB |
Output is correct |
27 |
Correct |
815 ms |
22420 KB |
Output is correct |
28 |
Correct |
810 ms |
22188 KB |
Output is correct |
29 |
Correct |
795 ms |
22352 KB |
Output is correct |
30 |
Correct |
155 ms |
20172 KB |
Output is correct |
31 |
Correct |
152 ms |
19872 KB |
Output is correct |
32 |
Correct |
153 ms |
19976 KB |
Output is correct |
33 |
Correct |
162 ms |
20004 KB |
Output is correct |
34 |
Correct |
153 ms |
20048 KB |
Output is correct |
35 |
Correct |
156 ms |
20044 KB |
Output is correct |
36 |
Correct |
153 ms |
20304 KB |
Output is correct |
37 |
Correct |
159 ms |
19988 KB |
Output is correct |
38 |
Correct |
154 ms |
20056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
163 ms |
40276 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
20048 KB |
Output is correct |
2 |
Correct |
155 ms |
19996 KB |
Output is correct |
3 |
Correct |
155 ms |
20036 KB |
Output is correct |
4 |
Correct |
156 ms |
20052 KB |
Output is correct |
5 |
Correct |
153 ms |
19872 KB |
Output is correct |
6 |
Correct |
155 ms |
20304 KB |
Output is correct |
7 |
Correct |
155 ms |
20064 KB |
Output is correct |
8 |
Correct |
156 ms |
19968 KB |
Output is correct |
9 |
Correct |
159 ms |
20052 KB |
Output is correct |
10 |
Correct |
156 ms |
20024 KB |
Output is correct |
11 |
Correct |
153 ms |
20048 KB |
Output is correct |
12 |
Correct |
154 ms |
20004 KB |
Output is correct |
13 |
Correct |
155 ms |
19896 KB |
Output is correct |
14 |
Correct |
152 ms |
20048 KB |
Output is correct |
15 |
Correct |
156 ms |
20048 KB |
Output is correct |
16 |
Correct |
158 ms |
19932 KB |
Output is correct |
17 |
Correct |
153 ms |
19836 KB |
Output is correct |
18 |
Correct |
158 ms |
19980 KB |
Output is correct |
19 |
Correct |
153 ms |
20044 KB |
Output is correct |
20 |
Correct |
153 ms |
20048 KB |
Output is correct |
21 |
Correct |
449 ms |
21840 KB |
Output is correct |
22 |
Correct |
450 ms |
21832 KB |
Output is correct |
23 |
Correct |
397 ms |
21592 KB |
Output is correct |
24 |
Correct |
430 ms |
21844 KB |
Output is correct |
25 |
Correct |
446 ms |
21588 KB |
Output is correct |
26 |
Correct |
797 ms |
22352 KB |
Output is correct |
27 |
Correct |
815 ms |
22420 KB |
Output is correct |
28 |
Correct |
810 ms |
22188 KB |
Output is correct |
29 |
Correct |
795 ms |
22352 KB |
Output is correct |
30 |
Correct |
155 ms |
20172 KB |
Output is correct |
31 |
Correct |
152 ms |
19872 KB |
Output is correct |
32 |
Correct |
153 ms |
19976 KB |
Output is correct |
33 |
Correct |
162 ms |
20004 KB |
Output is correct |
34 |
Correct |
153 ms |
20048 KB |
Output is correct |
35 |
Correct |
156 ms |
20044 KB |
Output is correct |
36 |
Correct |
153 ms |
20304 KB |
Output is correct |
37 |
Correct |
159 ms |
19988 KB |
Output is correct |
38 |
Correct |
154 ms |
20056 KB |
Output is correct |
39 |
Runtime error |
163 ms |
40276 KB |
Execution killed with signal 11 |
40 |
Halted |
0 ms |
0 KB |
- |