fork download
  1. // Codeforces.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <string>
  7. #include <map>
  8. #include <vector>
  9. #include <queue>
  10. #include <stack>
  11. #include <cmath>
  12. using namespace std;
  13.  
  14.  
  15.  
  16.  
  17. int main()
  18. {
  19. int t,l,r,L,R;
  20. vector < pair < int, int > > v;
  21. cin >> t;
  22. while (t--)
  23. {
  24. v.clear();
  25. cin >> l >> r >> L >> R;
  26. v.push_back(make_pair(l, r));
  27. v.push_back(make_pair(L, R));
  28. sort(v.begin(), v.end());
  29. if (v[1].first > v[0].second) {
  30. cout << 1 << endl;
  31. continue;
  32. }
  33. int locked = min(v[1].second,v[0].second) - v[1].first;
  34. if (v[1].first > v[0].first)locked++;
  35. if (v[0].second > v[1].second || v[0].second < v[1].second)locked++;
  36. cout << locked << endl;
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 5280KB
stdin
4
1 2
3 4
2 5
2 5
3 7
6 7
4 5
2 8
stdout
1
3
2
3