#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
struct fen{
long long fn[(1<<20)];
void upd(int i,long long w){
i++;
while(i<(1<<20)){
fn[i]+=w;
fn[i]%=mod;
i+=(-i)&i;
}
}
long long pors(int i){
i++;
long long ret=0;
while(i>0){
ret+=fn[i];
i-=(-i)&i;
}
ret%=mod;
return ret;
}
}fenw;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<pair<int,int>>all(n);
vector<int>allind;
for(int i=0;i<n;i++){
cin>>all[i].first>>all[i].second;
for(int j=all[i].first;j<=all[i].second;j++)
{
allind.push_back(j);
}
}
allind.push_back(0);
sort(allind.begin(),allind.end());
allind.resize(unique(allind.begin(),allind.end())-allind.begin());
fenw.upd(0,1);
for(int i=0;i<n;i++){
int lp=lower_bound(allind.begin(),allind.end(),all[i].first)-allind.begin();
for(int j=all[i].second-all[i].first;j>=0;j--){
fenw.upd(lp+j,fenw.pors(lp+j-1));
}
}
long long res=fenw.pors((int)allind.size());
res+=mod-1;
res%=mod;
cout<<res<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
148 ms |
4544 KB |
Output is correct |
22 |
Correct |
140 ms |
4556 KB |
Output is correct |
23 |
Correct |
134 ms |
4552 KB |
Output is correct |
24 |
Correct |
142 ms |
4556 KB |
Output is correct |
25 |
Correct |
148 ms |
4556 KB |
Output is correct |
26 |
Correct |
156 ms |
4556 KB |
Output is correct |
27 |
Correct |
162 ms |
4548 KB |
Output is correct |
28 |
Correct |
163 ms |
4548 KB |
Output is correct |
29 |
Correct |
161 ms |
4556 KB |
Output is correct |
30 |
Correct |
143 ms |
12040 KB |
Output is correct |
31 |
Correct |
182 ms |
11832 KB |
Output is correct |
32 |
Correct |
185 ms |
12084 KB |
Output is correct |
33 |
Correct |
180 ms |
11780 KB |
Output is correct |
34 |
Correct |
180 ms |
11852 KB |
Output is correct |
35 |
Correct |
137 ms |
11320 KB |
Output is correct |
36 |
Correct |
139 ms |
11656 KB |
Output is correct |
37 |
Correct |
139 ms |
11808 KB |
Output is correct |
38 |
Correct |
134 ms |
11456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
495 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
148 ms |
4544 KB |
Output is correct |
22 |
Correct |
140 ms |
4556 KB |
Output is correct |
23 |
Correct |
134 ms |
4552 KB |
Output is correct |
24 |
Correct |
142 ms |
4556 KB |
Output is correct |
25 |
Correct |
148 ms |
4556 KB |
Output is correct |
26 |
Correct |
156 ms |
4556 KB |
Output is correct |
27 |
Correct |
162 ms |
4548 KB |
Output is correct |
28 |
Correct |
163 ms |
4548 KB |
Output is correct |
29 |
Correct |
161 ms |
4556 KB |
Output is correct |
30 |
Correct |
143 ms |
12040 KB |
Output is correct |
31 |
Correct |
182 ms |
11832 KB |
Output is correct |
32 |
Correct |
185 ms |
12084 KB |
Output is correct |
33 |
Correct |
180 ms |
11780 KB |
Output is correct |
34 |
Correct |
180 ms |
11852 KB |
Output is correct |
35 |
Correct |
137 ms |
11320 KB |
Output is correct |
36 |
Correct |
139 ms |
11656 KB |
Output is correct |
37 |
Correct |
139 ms |
11808 KB |
Output is correct |
38 |
Correct |
134 ms |
11456 KB |
Output is correct |
39 |
Runtime error |
495 ms |
524288 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |