#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 5e2 + 5;
const int modu = 1e9 + 7;
pir a[maxn];
void input(int n){
for (int i = 1 ; i <= n ; i++) cin >> a[i].fi >> a[i].se;
}
namespace sub1_2{
map <int,int> M;
const int N = 1e6 + 5;
struct fenwick_tree{
ll fenwick[N];
void update(int x,int n,ll val){
while (x <= n){
fenwick[x] = (fenwick[x] + val) % modu;
x = x | (x + 1);
}
}
ll calc(int x){
ll res = 0;
while (x > 0){
res = (res + fenwick[x]) % modu;
x = x & (x + 1);
x--;
}
return res;
}
} fw;
void compress(int n){
vector <int> V;
for (int i = 1 ; i <= n ; i++)
for (int j = a[i].fi ; j <= a[i].se ; j++)
V.push_back(j);
sort(V.begin(),V.end());
int cur = 0,lst = 0;
for (int x : V){
if (x != lst){
lst = x;
cur++;
}
M[x] = cur;
}
}
ll solve(int n){
compress(n);
int lim = 0;
for (int i = 1 ; i <= n ; i++) lim = max(lim,M[a[i].se]);
for (int i = a[1].fi ; i <= a[1].se ; i++)
fw.update(M[i],lim,1);
for (int i = 2 ; i <= n ; i++){
for (int v = a[i].se ; v >= a[i].fi ; v--){
ll val = fw.calc(M[v] - 1) + 1;
fw.update(M[v],lim,val);
}
}
return fw.calc(lim);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n;
cin >> n;
input(n);
cout << sub1_2::solve(n);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
388 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
480 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
388 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
480 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
142 ms |
4560 KB |
Output is correct |
22 |
Correct |
131 ms |
4564 KB |
Output is correct |
23 |
Correct |
125 ms |
4560 KB |
Output is correct |
24 |
Correct |
132 ms |
4564 KB |
Output is correct |
25 |
Correct |
139 ms |
4560 KB |
Output is correct |
26 |
Correct |
143 ms |
4864 KB |
Output is correct |
27 |
Correct |
140 ms |
4564 KB |
Output is correct |
28 |
Correct |
138 ms |
4560 KB |
Output is correct |
29 |
Correct |
143 ms |
4560 KB |
Output is correct |
30 |
Correct |
433 ms |
54404 KB |
Output is correct |
31 |
Correct |
438 ms |
53448 KB |
Output is correct |
32 |
Correct |
444 ms |
54456 KB |
Output is correct |
33 |
Correct |
443 ms |
53224 KB |
Output is correct |
34 |
Correct |
433 ms |
53600 KB |
Output is correct |
35 |
Correct |
441 ms |
51196 KB |
Output is correct |
36 |
Correct |
437 ms |
52992 KB |
Output is correct |
37 |
Correct |
473 ms |
53400 KB |
Output is correct |
38 |
Correct |
458 ms |
51704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
393 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
388 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
480 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
142 ms |
4560 KB |
Output is correct |
22 |
Correct |
131 ms |
4564 KB |
Output is correct |
23 |
Correct |
125 ms |
4560 KB |
Output is correct |
24 |
Correct |
132 ms |
4564 KB |
Output is correct |
25 |
Correct |
139 ms |
4560 KB |
Output is correct |
26 |
Correct |
143 ms |
4864 KB |
Output is correct |
27 |
Correct |
140 ms |
4564 KB |
Output is correct |
28 |
Correct |
138 ms |
4560 KB |
Output is correct |
29 |
Correct |
143 ms |
4560 KB |
Output is correct |
30 |
Correct |
433 ms |
54404 KB |
Output is correct |
31 |
Correct |
438 ms |
53448 KB |
Output is correct |
32 |
Correct |
444 ms |
54456 KB |
Output is correct |
33 |
Correct |
443 ms |
53224 KB |
Output is correct |
34 |
Correct |
433 ms |
53600 KB |
Output is correct |
35 |
Correct |
441 ms |
51196 KB |
Output is correct |
36 |
Correct |
437 ms |
52992 KB |
Output is correct |
37 |
Correct |
473 ms |
53400 KB |
Output is correct |
38 |
Correct |
458 ms |
51704 KB |
Output is correct |
39 |
Runtime error |
393 ms |
524288 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |