对于这种计算边界的东西,烦死人,不过画个图也就解决了
Problem - B - Codeforces
#include <bits/stdc++.h>using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> PII;
#define pb emplace_back
//#define int ll
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define ps push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc u << 1
#define rc u << 1 | 1void solve();const int N = 1e6 + 10;signed main() {IOS;ll t = 1;cin >> t;while (t--)solve();return 0;
}void solve() {vector<PII> a(2);for(int i = 0; i < 2; ++ i){cin >> a[i].x >> a[i].y;}sort(all(a));//____,,,____//相加于一个点,或者不想交if(a[0].y <= a[1].x){ll ans = 1;if(a[0].y == a[1].x) ans ++;cout << ans << endl;return;}//相交点>= 1if(a[0].x == a[1].x){if(a[0].y <= a[1].y)//sort之后a0y <= a1y{ll ans = 1; if(a[0].y == a[1].y) ans--;cout << a[0].y - a[0].x + ans << endl;return;}}else//a0x < a1x{if(a[0].y <= a[1].y){ll ans = 1; if(a[1].y == a[0].y) ans --;cout << a[0].y - a[1].x + 1 + ans << endl;return;}else{cout << a[1].y - a[1].x + 1 + 1 << endl;return;}}
}