#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
const int mod = 1e9 + 7;
struct FT{
vector<int> bit, a;
int n;
FT(int ns){
n = ns;
bit.resize(n + 1);
a.resize(n + 1);
}
int get(int v){
int out = 0;
while (v > 0){
out = (out + bit[v]) % mod;
v = (v & (v + 1)) - 1;
}
return out;
}
void upd(int v, int x){
x = (x - a[v]);
a[v] = x;
while (v <= n){
bit[v] = (bit[v] + x) % mod;
v |= (v + 1);
}
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> l(n + 1), r(n + 1);
set<int> st;
for (int i = 1; i <= n; i++){
cin>>l[i]>>r[i];
for (int j = l[i]; j <= r[i]; j++){
st.insert(j);
}
}
vector<int> a = {0};
for (int j: st) a.pb(j);
int m = (int) a.size() - 1;
FT T(m);
vector<int> :: iterator it;
for (int i = 1; i <= n; i++){
it = lower_bound(a.begin(), a.end(), r[i]);
int f = (int) (it - a.begin());
for (int j = r[i]; j >= l[i]; j--){
T.upd(f, T.get(f) + 1);
f--;
}
}
int out = T.get(m);
if (out < 0) out += mod;
cout<<T.get(m)<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |