#include <bits/stdc++.h>
using namespace std;
const int mod = (int) 1e9 + 7;
template<typename T>
class segtree {
private:
int b;
vector<T> tr;
public:
segtree() {}
segtree(int n) {
b = 1;
while (b < n) {
b <<= 1;
}
tr.assign(2 * b, 0);
}
void upd(int i, const T& val) {
tr[i += b] = val;
for (i >>= 1; i > 0; i >>= 1) {
tr[i] = (tr[i << 1] + tr[i << 1 | 1]) % mod;
}
}
T qry(int l, int r) {
T ans = 0;
for (l += b, r += b; l <= r; l >>= 1, r >>= 1) {
if (l & 1) ans = (ans + tr[l++]) % mod;
if (!(r & 1)) ans = (ans + tr[r--]) % mod;
}
return ans;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n), b(n), se;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
for (int j = a[i]; j <= b[i]; j++) {
se.push_back(j);
}
}
sort(se.begin(), se.end());
int idd = 1;
map<int, int> mp;
for (int i = 0; i < (int) se.size(); i++) {
if (i == 0 || se[i] != se[i - 1]) {
mp[se[i]] = idd++;
}
}
for (int i = 0; i < n; i++) {
a[i] = mp[a[i]];
b[i] = mp[b[i]];
}
segtree<long long> st(idd);
vector<long long> dp(idd, 0);
dp[0] = 1;
st.upd(0, 1);
for (int i = 0; i < n; i++) {
for (int j = b[i]; j >= a[i]; j--) {
dp[j] = (dp[j] + st.qry(0, j - 1)) % mod;
st.upd(j, dp[j]);
}
}
long long sum = 0;
for (int i = 1; i < idd; i++) {
sum = (sum + dp[i]) % mod;
}
cout << sum << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
160 ms |
4548 KB |
Output is correct |
22 |
Correct |
162 ms |
4548 KB |
Output is correct |
23 |
Correct |
148 ms |
4548 KB |
Output is correct |
24 |
Correct |
185 ms |
4548 KB |
Output is correct |
25 |
Correct |
183 ms |
4548 KB |
Output is correct |
26 |
Correct |
163 ms |
4548 KB |
Output is correct |
27 |
Correct |
167 ms |
4548 KB |
Output is correct |
28 |
Correct |
167 ms |
4548 KB |
Output is correct |
29 |
Correct |
170 ms |
4548 KB |
Output is correct |
30 |
Correct |
526 ms |
74836 KB |
Output is correct |
31 |
Correct |
554 ms |
73708 KB |
Output is correct |
32 |
Correct |
513 ms |
74836 KB |
Output is correct |
33 |
Correct |
502 ms |
73332 KB |
Output is correct |
34 |
Correct |
511 ms |
73908 KB |
Output is correct |
35 |
Correct |
491 ms |
71216 KB |
Output is correct |
36 |
Correct |
508 ms |
73020 KB |
Output is correct |
37 |
Correct |
519 ms |
73652 KB |
Output is correct |
38 |
Correct |
496 ms |
71864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
565 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
160 ms |
4548 KB |
Output is correct |
22 |
Correct |
162 ms |
4548 KB |
Output is correct |
23 |
Correct |
148 ms |
4548 KB |
Output is correct |
24 |
Correct |
185 ms |
4548 KB |
Output is correct |
25 |
Correct |
183 ms |
4548 KB |
Output is correct |
26 |
Correct |
163 ms |
4548 KB |
Output is correct |
27 |
Correct |
167 ms |
4548 KB |
Output is correct |
28 |
Correct |
167 ms |
4548 KB |
Output is correct |
29 |
Correct |
170 ms |
4548 KB |
Output is correct |
30 |
Correct |
526 ms |
74836 KB |
Output is correct |
31 |
Correct |
554 ms |
73708 KB |
Output is correct |
32 |
Correct |
513 ms |
74836 KB |
Output is correct |
33 |
Correct |
502 ms |
73332 KB |
Output is correct |
34 |
Correct |
511 ms |
73908 KB |
Output is correct |
35 |
Correct |
491 ms |
71216 KB |
Output is correct |
36 |
Correct |
508 ms |
73020 KB |
Output is correct |
37 |
Correct |
519 ms |
73652 KB |
Output is correct |
38 |
Correct |
496 ms |
71864 KB |
Output is correct |
39 |
Runtime error |
565 ms |
524292 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |