1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,int> PLI;
const int mod = 1e9+7;

PII segs[500005];
bitset<50005> mask[100005];

long long pot(long long a, long long x){
    if(x == 0) return 1;
    if(x&1) return pot(a, x-1)*a%mod;
    long long tmp = pot(a, x/2);
    return tmp*tmp%mod;
}

int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>segs[i].first>>segs[i].second;
    }

    long long res = 0;
    set<int> pos;
    for(int i=n;i>0;i--){
        bitset<50005> cur;
        cur[i] = 1;
        while(true){
            auto it = pos.lower_bound(segs[i].first);
            if(it == pos.end()) break;
            if(*it > segs[i].second) break;
            pos.erase(it);
            cur |= mask[*it];
        }
        int cnt = cur.count();
        res = (res+pot(cnt, mod-2))%mod;
        mask[segs[i].first] = cur;
        mask[segs[i].second] = cur;
        pos.insert(segs[i].first);
        pos.insert(segs[i].second);
    }
    cout<<res<<endl;
}