#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ll long long
#define pb(n) push_back(n);
#define forn(i,n) for(ll i=0; i<n; i++)
#define fors(i,s) for(ll i=0; i<s.size(); i++)
#define forv(i,v,n) for(ll i=v; i<n; i++)
#define taha ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define tests ll t; cin>>t; while(t--)
#define endl '\n'
template < typename type >
void operator<<(ostream& out, vector<type> v){
for(auto i : v)
out << i << ' ';
}
ll mn = 1e9, mx = -1e9, mod = 1e9+7, a1, a2, a3;
void solve();
int main(){
taha
ll t = 1;
//cin >> t;
while(t--){
solve();
}
}
void solve(){
ll p, q, l, r; cin >> p >> q >> l >> r;
vector<bool> ans(r - l + 1);
vector<pair<ll, ll>> v1(p), v2(q);
forn(i, p)
cin >> v1[i].first >> v1[i].second;
forn(i, q)
cin >> v2[i].first >> v2[i].second;
forn(i, q){
forn(j, p){
for(int u = 0; u < r - l + 1; u++){
if(v2[i].first + l + u >= v1[j].first && v2[i].first + l + u <= v1[j].second)
ans[u] = 1;
if(v2[i].second + l + u >= v1[j].first && v2[i].second + l + u <= v1[j].second)
ans[u] = 1;
if(v2[i].first + l + u <= v1[j].first && v2[i].second + l + u >= v1[j].second)
ans[u] = 1;
}
}
}
ll sum = 0;
forn(i, r - l + 1){
sum+=ans[i];
}
cout << sum;
}
Ali and Helping innocent people | Book of Potion making |
Duration | Birthday Party |
e-maze-in | Bricks Game |
Char Sum | Two Strings |
Anagrams | Prime Number |
Lexical Sorting Reloaded | 1514A - Perfectly Imperfect Array |
580A- Kefa and First Steps | 1472B- Fair Division |
996A - Hit the Lottery | MSNSADM1 Football |
MATCHES Playing with Matches | HRDSEQ Hard Sequence |
DRCHEF Doctor Chef | 559. Maximum Depth of N-ary Tree |
821. Shortest Distance to a Character | 1441. Build an Array With Stack Operations |
1356. Sort Integers by The Number of 1 Bits | 922. Sort Array By Parity II |
344. Reverse String | 1047. Remove All Adjacent Duplicates In String |
977. Squares of a Sorted Array | 852. Peak Index in a Mountain Array |
461. Hamming Distance | 1748. Sum of Unique Elements |