//```// YF YUSUF
#include <bits/stdc++.h>
using namespace std;
#ifdef YF_CHECK
bool LOCAL = 1;
#else
#pragma GCC target("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
bool LOCAL = 0;
#endif
using i128 = __int128;
using ll = long long;
using ld = long double;
using vll = vector <ll>;
using mll = map <ll,ll>;
using pll = pair <ll,ll>;
using vvl = vector <vll>;
using vpll = vector <pll>;
template<class T>bool MIN(T&a,T b){bool ret=(a>b);if(ret)a=b;return ret;}
template<class T>bool MAX(T&a,T b){bool ret=(a<b);if(ret)a=b;return ret;}
#define rall(a) a.rbegin(),a.rend()
#define all(a) a.begin(),a.end()
#define sgr v+v+1,(tl+tr)/2+1,tr
#define sgl v+v,tl,(tl+tr)/2
#define pb push_back
#define S second
#define F first
mt19937_64 MT(time(0));
ll BP(ll a,ll b,ll mod=1e9+7){
if(b==0)return 1;
ll q=BP(a,b/2,mod);
return ((q*q)%mod*(b%2?a:1ll))%mod;
}
ll f(ll x){return x*(x+1)/2;}
ll dup(ll a,ll b){return (a+b-1)/b;}
ll lcm(ll a,ll b){return a/__gcd(a,b)*b;}
ll invf(ll x){return (-1+sqrt(1+8*x))/2;}
ll lg(ll x){return (x ? 63 - __builtin_clzll(x) : -1);}
const ll mod=998244353;
const ll INF=1e18;
const ll inf=1e9+7;
const ll N =5e2+7;
ll n, a[N], b[N];
class treap{
struct node{
ll key, priority;
ll sum, val, size, add;
node *l = nullptr, *r=nullptr;
node(ll key,ll value):key(key), val(value), priority(MT()){
sum = value;
size = 1;
add = 0;
}
} *root = nullptr;
static ll key (node *n){return n ? n->key : 0;}
static ll sum (node *n){return n ? n->sum : 0;}
static ll val (node *n){return n ? n->val : 0;}
static ll add (node *n){return n ? n->add : 0;}
static ll size(node *n){return n ? n->size : 0;}
static void update(node *n){
if(n){
n->size = 1 + size(n->l) + size(n->r);
n->sum = (n->val + sum(n->l) + sum(n->r)) % inf;
}
}
static void push(node *n){
if(n){
if(n->l)
n->l->add = (n->add + n->l->add);
if(n->r)
n->r->add = (n->add + n->r->add);
n->val = (n->val + n->add) % inf;
n->sum = (n->sum + n->add * n->size) % inf;
n->add = 0;
}
}
static node *merge(node *a, node *b){
if(!a || !b)
return a ? a : b;
push(a);
push(b);
if(a->priority > b->priority){
a->r = merge(a->r, b);
update(a);
return a;
} else {
b->l = merge(a, b->l);
update(b);
return b;
}
}
static void split(node *n, int key, node* &a, node* &b){
if(!n){
a = b = nullptr;
return;
}
push(n);
if(n->key < key){
split(n->r, key, n->r, b);
a = n;
} else {
split(n->l, key, a, n->l);
b = n;
}
update(a);
update(b);
}
public:
void insert(int key){
node *less, *equal, *greater;
split(root, key, less, greater);
split(greater, key + 1, equal, greater);
if(!equal)
equal = new node(key, 0);
// cout<<key<<" "<<size(equal)<<" size of eq\n";
root = merge(less, merge(equal, greater));
}
void add(ll l, ll r,ll x){
node *less, *equal, *greater;
split(root, l, less, greater);
split(greater, r + 1, equal, greater);
// cout<<l<<" "<<r<<" "<<size(less)<<" "<<size(equal)<<" "<<size(greater)<<"\n";
if(equal)
equal->add = (equal->add + x) % inf;
// else
// cout<<"wasted\n";
root = merge(less, merge(equal, greater));
}
ll get(ll l,ll r){
node *less, *equal, *greater;
split(root, l, less, greater);
split(greater, r + 1, equal, greater);
ll res = sum(equal);
root = merge(less, merge(equal, greater));
return res;
}
};
void YF_MAIN(ll TEST){
cin>>n;
treap tr;
tr.insert(0);
tr.add(0, 0, 1);
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
for(int x = b[i]; x>=a[i]; x--){
ll sum = tr.get(0, x-1);
// cout<<i<<" "<<sum<<" "<<x<<"\n";
tr.insert(x);
tr.add(x, x, sum);
}
}
cout<<(tr.get(0, inf) + inf - 1) % inf;
}
const bool TECT=0;
const bool FLSH=1;
const ll SN=1e0 + 7; ll SM[SN];
const ll FN=1e0 + 7; ll FACT[FN], inv[FN], FMOD=inf;
ll PNK(ll n,ll k){return FACT[n] *inv[n-k]%FMOD;}
ll CNK(ll n,ll k){return PNK(n,k)*inv[k ]%FMOD;}
void BEFORE(){
for(ll i=2;i<SN;i++){
if(SM[i])continue;
for(ll j=i;j<SN;j+=i)
MAX(SM[j],i);
}
FACT[0]=inv[0]=1;
for(int i=1;i<FN;i++){
FACT[i]=FACT[i-1]*i%FMOD;
inv[i]=BP(FACT[i],FMOD-2,FMOD);
}
}
signed main(){
// freopen(("input.txt"),"r",stdin);freopen(("output.txt"),"w",stdout);
if(FLSH){
ios_base::sync_with_stdio(0);
cout.setf(ios::fixed);
cout.precision(0);
cout.tie(0);
cin.tie(0);
}
int TEST=1;
if(TECT)
cin>>TEST;
BEFORE();
for(int T=1;T<=TEST;T++){
// cout<<"Case "<<T<<": ";
YF_MAIN(T);
cout<<(T==TEST ? "" : "\n");
}
return 0;
}
// YF YUSUF ```
| # | 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... |