Language: C++

#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
#define ls(x) tr[x].l
#define rs(x) tr[x].r
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int P = 1e9 + 7 ; 
const int N = 2e5 + 5 ; 
int n, m, cnt, num, Rt, M, lef[N], ref[N], dp[N] ;
struct node { int p, f ; } a[N << 1] ;
struct Px { int x, y ; } c[N] ; 
bool cmp( node x, node y ) { return x.p < y.p ; }
bool cmp2( Px a, Px b ) { return ( a.x == b.x ) ? ( a.y > b.y ) : a.x < b.x ; }
struct Tr { int l, r, w ; } tr[N * 20] ;
void insert( int &x, int l, int r, int wh, int val ) {
	if( !x ) x = ++ num ; tr[x].w += val, tr[x].w %= P ; 
	if( l == r ) return ; 
	int mid = ( l + r ) >> 1 ; 
	if( mid >= wh ) insert( ls(x), l, mid, wh, val ) ;
	else insert( rs(x), mid + 1, r, wh, val ) ;
}
int query( int x, int l, int r, int wh ) {
	if( l == r ) return 0 ; 
	int mid = ( l + r ) >> 1 ; 
	if( mid >= wh ) return query( ls(x), l, mid, wh ) ;
	else return ( query( rs(x), mid + 1, r, wh ) + tr[ls(x)].w ) % P ; 
}
signed main()
{
	n = gi(), m = gi() ; int maxn = 0 ;
	rep( i, 1, n ) a[i].p = gi(), maxn = max( maxn, a[i].p ), a[i].f = 1 ; 
	rep( i, 1, m ) a[i + n].p = gi(), maxn = max( maxn, a[i + n].p ) ; 
	M = n + m, ++ maxn ; 
	sort( a + 1, a + M + 1, cmp ) ;
	rep( i, 1, M ) lef[i] = ( a[i].f ) ? lef[i - 1] : a[i].p ; 
	drep( i, 1, M ) ref[i] = ( a[i].f ) ? ref[i + 1] : a[i].p ; 
	rep( i, 1, M ) {
		if( (!lef[i]) || (!ref[i]) || (!a[i].f) ) continue ; 
		++ cnt, c[cnt].x = a[i].p - lef[i], c[cnt].y = ref[i] - a[i].p ; 
	}
	sort( c + 1, c + cnt + 1, cmp2 ) ; int Ans = 1 ; 
	rep( i, 1, cnt ) {
		dp[i] = 1 + query( 1, 1, maxn, c[i].y ) ;
		insert( Rt, 1, maxn, c[i].y + 1, dp[i] ) ;
		Ans = ( Ans + dp[i] ) % P ; 
	}
	cout << Ans << endl ; 
	return 0 ;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |         rep( i, 1, n ) a[i].p = gi(), maxn = max( maxn, a[i].p ), a[i].f = 1 ;
      |              ^
a.cc:4:42: note: in definition of macro 'rep'
    4 | #define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
      |                                          ^
a.cc:41:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   41 |         rep( i, 1, m ) a[i + n].p = gi(), maxn = max( maxn, a[i + n].p ) ;
      |              ^
a.cc:4:42: note: in definition of macro 'rep'
    4 | #define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
      |                                          ^
a.cc:44:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 |         rep( i, 1, M ) lef[i] = ( a[i].f ) ? lef[i - 1] : a[i].p ;
      |              ^
a.cc:4:42: note: in definition of macro 'rep'
    4 | #define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
      |                                          ^
a.cc:45:15: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |         drep( i, 1, M ) ref[i] = ( a[i].f ) ? ref[i + 1] : a[i].p ;
      |               ^
a.cc:5:43: note: in definition of macro 'drep'
    5 | #define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
      |                                           ^
a.cc:45:25: error: reference to 'ref' is ambiguous
   45 |         drep( i, 1, M ) ref[i] = ( a[i].f ) ? ref[i + 1] : a[i].p ;
      |                         ^~~
In file included from /usr/include/c++/14/string:52,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:36: note:                 'long long int ref [200005]'
   18 | int n, m, cnt, num, Rt, M, lef[N], ref[N], dp[N] ;
      |                                    ^~~
a.cc:45:47: error: reference to 'ref' is ambiguous
   45 |         drep( i, 1, M ) ref[i] = ( a[i].f ) ? ref[i + 1] : a[i].p ;
      |                                               ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:36: note:                 'long long int ref [200005]'
   18 | int n, m, cnt, num, Rt, M, lef[N], ref[N], dp[N] ;
      |                                    ^~~
a.cc:46:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         rep( i, 1, M ) {
      |              ^
a.cc:4:42: note: in definition of macro 'rep'
    4 | #define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
      |                                          ^
a.cc:47:36: error: reference to 'ref' is ambiguous
   47 |                 if( (!lef[i]) || (!ref[i]) || (!a[i].f) ) continue ;
      |                                    ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:36: note:                 'long long int ref [200005]'
   18 | int n, m, cnt, num, Rt, M, lef[N], ref[N], dp[N] ;
      |                                    ^~~
a.cc:48:64: error: reference to 'ref' is ambiguous
   48 |                 ++ cnt, c[cnt].x = a[i].p - lef[i], c[cnt].y = ref[i] - a[i].p ;
      |                                                                ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:18:36: note:                 'long long int ref [200005]'
   18 | int n, m, cnt, num, Rt, M, lef[N], ref[N], dp[N] ;
      |                                    ^~~
a.cc:51:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   51 |         rep( i, 1, cnt ) {
      |              ^
a.cc:4:42: note: in definition of macro 'rep'
    4 | #define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
      |                                          ^