总结一下规律:
1. 两个区间不相交:1
2. 两个期间完全重合:r - l
3. 相交房间数 + 1 - (l == L) - (r == R) (使用差分数组维护)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include "bits/stdc++.h"
using namespace std;
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fios ofstream("test.txt");cout.rdbuf(out.rdbuf())
#define endl "\n"
#define INF 0x3f3f3f3f
#define MINF 2146473647
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) (x & (-x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 110;
int l, r;
int L, R;
int b[N], a[N];
int main()
{
int T;
cin >> T;
while(T--)
{
cin >> l >> r >> L >> R;
if(r < L || R < l) cout << 1 << endl;
else if(l == L && r == R) cout << r - l << endl;
else
{
memset(a, 0, sizeof a), memset(b, 0, sizeof b);
b[l]++, b[L]++, b[r + 1]--, b[R + 1]--;
for(int i = 1; i < N; i++) a[i] = a[i - 1] + b[i];
int cnt = 0;
for(int i = 1; i < N; i++)
if(a[i] == 2) cnt++;
if(l == L) cnt--;
if(r == R) cnt--;
cout << cnt + 1 << endl;
}
}
return 0;
}