#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
ll BIG = 1100002;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<ll> a(n), b(n);
vector<ll> nums;
nums.resize(BIG);
map<int, int> m;
bool st1 = true;
for(int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
m[a[i]]++;
m[b[i]]--;
if(a[i] != b[i]) st1 = false;
}
int x = 0;
ll mi = 0;
for(auto p : m) {
if(x == 0) {
mi += p.first - 1;
}
for(int i = 0; i < n; i++) {
if(a[i] == p.first) a[i] -= mi;
if(b[i] == p.first) b[i] -= mi;
}
x += p.second;
if(x == 0) {
mi -= p.first;
}
}
if(st1) {
vector<ll> sums(n, 1);
for(int i = 1; i < n; i++) {
for(int j = 0; j < i; j++) {
if(a[j] < a[i]) sums[i] += sums[j];
sums[i] %= MOD;
}
}
ll ans = 0;
for(int i = 0; i < n; i++) ans += sums[i];
cout << ans % MOD << '\n';
return 0;
}
nums[0] = 1;
for(int i = 0; i < n; i++) {
ll g = 0;
for(int j = 0; j < a[i]; j++) {
g += nums[j];
g %= MOD;
}
for(int j = a[i]; j <= b[i]; j++) {
ll x = g;
g += nums[j];
nums[j] += x;
nums[j] += MOD;
nums[j] %= MOD;
g %= MOD;
}
}
ll ans = 0;
for(int i = 1; i < BIG; i++) {
ans += nums[i];
ans %= MOD;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8916 KB |
Output is correct |
2 |
Correct |
6 ms |
8916 KB |
Output is correct |
3 |
Correct |
6 ms |
8916 KB |
Output is correct |
4 |
Correct |
6 ms |
8940 KB |
Output is correct |
5 |
Correct |
5 ms |
8916 KB |
Output is correct |
6 |
Correct |
7 ms |
8916 KB |
Output is correct |
7 |
Correct |
6 ms |
8916 KB |
Output is correct |
8 |
Correct |
5 ms |
8916 KB |
Output is correct |
9 |
Correct |
5 ms |
8916 KB |
Output is correct |
10 |
Correct |
5 ms |
8916 KB |
Output is correct |
11 |
Correct |
5 ms |
8916 KB |
Output is correct |
12 |
Correct |
5 ms |
8916 KB |
Output is correct |
13 |
Correct |
5 ms |
8916 KB |
Output is correct |
14 |
Correct |
5 ms |
8960 KB |
Output is correct |
15 |
Correct |
5 ms |
8916 KB |
Output is correct |
16 |
Correct |
5 ms |
8852 KB |
Output is correct |
17 |
Correct |
4 ms |
8916 KB |
Output is correct |
18 |
Correct |
5 ms |
8876 KB |
Output is correct |
19 |
Correct |
7 ms |
8916 KB |
Output is correct |
20 |
Correct |
5 ms |
8916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8916 KB |
Output is correct |
2 |
Correct |
6 ms |
8916 KB |
Output is correct |
3 |
Correct |
6 ms |
8916 KB |
Output is correct |
4 |
Correct |
6 ms |
8940 KB |
Output is correct |
5 |
Correct |
5 ms |
8916 KB |
Output is correct |
6 |
Correct |
7 ms |
8916 KB |
Output is correct |
7 |
Correct |
6 ms |
8916 KB |
Output is correct |
8 |
Correct |
5 ms |
8916 KB |
Output is correct |
9 |
Correct |
5 ms |
8916 KB |
Output is correct |
10 |
Correct |
5 ms |
8916 KB |
Output is correct |
11 |
Correct |
5 ms |
8916 KB |
Output is correct |
12 |
Correct |
5 ms |
8916 KB |
Output is correct |
13 |
Correct |
5 ms |
8916 KB |
Output is correct |
14 |
Correct |
5 ms |
8960 KB |
Output is correct |
15 |
Correct |
5 ms |
8916 KB |
Output is correct |
16 |
Correct |
5 ms |
8852 KB |
Output is correct |
17 |
Correct |
4 ms |
8916 KB |
Output is correct |
18 |
Correct |
5 ms |
8876 KB |
Output is correct |
19 |
Correct |
7 ms |
8916 KB |
Output is correct |
20 |
Correct |
5 ms |
8916 KB |
Output is correct |
21 |
Correct |
17 ms |
8916 KB |
Output is correct |
22 |
Correct |
18 ms |
8916 KB |
Output is correct |
23 |
Correct |
18 ms |
8976 KB |
Output is correct |
24 |
Correct |
17 ms |
8916 KB |
Output is correct |
25 |
Correct |
18 ms |
8916 KB |
Output is correct |
26 |
Correct |
17 ms |
8916 KB |
Output is correct |
27 |
Correct |
17 ms |
8916 KB |
Output is correct |
28 |
Correct |
16 ms |
8916 KB |
Output is correct |
29 |
Correct |
16 ms |
8916 KB |
Output is correct |
30 |
Correct |
703 ms |
8916 KB |
Output is correct |
31 |
Correct |
710 ms |
8916 KB |
Output is correct |
32 |
Correct |
724 ms |
8904 KB |
Output is correct |
33 |
Correct |
706 ms |
8916 KB |
Output is correct |
34 |
Correct |
730 ms |
8916 KB |
Output is correct |
35 |
Correct |
704 ms |
8916 KB |
Output is correct |
36 |
Correct |
700 ms |
8916 KB |
Output is correct |
37 |
Correct |
723 ms |
8916 KB |
Output is correct |
38 |
Correct |
716 ms |
8916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
17 ms |
17860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8916 KB |
Output is correct |
2 |
Correct |
6 ms |
8916 KB |
Output is correct |
3 |
Correct |
6 ms |
8916 KB |
Output is correct |
4 |
Correct |
6 ms |
8940 KB |
Output is correct |
5 |
Correct |
5 ms |
8916 KB |
Output is correct |
6 |
Correct |
7 ms |
8916 KB |
Output is correct |
7 |
Correct |
6 ms |
8916 KB |
Output is correct |
8 |
Correct |
5 ms |
8916 KB |
Output is correct |
9 |
Correct |
5 ms |
8916 KB |
Output is correct |
10 |
Correct |
5 ms |
8916 KB |
Output is correct |
11 |
Correct |
5 ms |
8916 KB |
Output is correct |
12 |
Correct |
5 ms |
8916 KB |
Output is correct |
13 |
Correct |
5 ms |
8916 KB |
Output is correct |
14 |
Correct |
5 ms |
8960 KB |
Output is correct |
15 |
Correct |
5 ms |
8916 KB |
Output is correct |
16 |
Correct |
5 ms |
8852 KB |
Output is correct |
17 |
Correct |
4 ms |
8916 KB |
Output is correct |
18 |
Correct |
5 ms |
8876 KB |
Output is correct |
19 |
Correct |
7 ms |
8916 KB |
Output is correct |
20 |
Correct |
5 ms |
8916 KB |
Output is correct |
21 |
Correct |
17 ms |
8916 KB |
Output is correct |
22 |
Correct |
18 ms |
8916 KB |
Output is correct |
23 |
Correct |
18 ms |
8976 KB |
Output is correct |
24 |
Correct |
17 ms |
8916 KB |
Output is correct |
25 |
Correct |
18 ms |
8916 KB |
Output is correct |
26 |
Correct |
17 ms |
8916 KB |
Output is correct |
27 |
Correct |
17 ms |
8916 KB |
Output is correct |
28 |
Correct |
16 ms |
8916 KB |
Output is correct |
29 |
Correct |
16 ms |
8916 KB |
Output is correct |
30 |
Correct |
703 ms |
8916 KB |
Output is correct |
31 |
Correct |
710 ms |
8916 KB |
Output is correct |
32 |
Correct |
724 ms |
8904 KB |
Output is correct |
33 |
Correct |
706 ms |
8916 KB |
Output is correct |
34 |
Correct |
730 ms |
8916 KB |
Output is correct |
35 |
Correct |
704 ms |
8916 KB |
Output is correct |
36 |
Correct |
700 ms |
8916 KB |
Output is correct |
37 |
Correct |
723 ms |
8916 KB |
Output is correct |
38 |
Correct |
716 ms |
8916 KB |
Output is correct |
39 |
Runtime error |
17 ms |
17860 KB |
Execution killed with signal 11 |
40 |
Halted |
0 ms |
0 KB |
- |