Advertisement
Galebickosikasa

Untitled

Oct 14th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #pragma GCC target("avx,avx2")
  2. #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
  3. #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,tune=native")
  4. #pragma GCC optimize("03")
  5.  
  6. #include <iostream>
  7. #include <vector>
  8. #include <cmath>
  9. #include <numeric>
  10. #include <algorithm>
  11. #include <unordered_set>
  12. #include <unordered_map>
  13. #include <set>
  14. #include <map>
  15. #include <queue>
  16. #include <deque>
  17. #include <bitset>
  18. #include <stack>
  19. #include <random>
  20.  
  21. #define pb push_back
  22. #define ll long long
  23. #define ld long double
  24. #define all(a) a.begin(), a.end()
  25. #define sz(a) (int)a.size()
  26.  
  27. using namespace std;
  28.  
  29. //tg: @galebickosikasa
  30.  
  31. const int maxn = (int)3e5;
  32. const int inf = (int)2e9;
  33. const ld eps = 1e-9;
  34. mt19937 SuperRandom;
  35.  
  36. struct Segment{
  37. ld l, r, t;
  38. };
  39.  
  40. bool comp(const Segment& a, const Segment& b){
  41. ld m1 = (a.l + a.r) / 2, m2 = (b.l + b.r) / 2;
  42. return m1 < m2;
  43. }
  44.  
  45. int kek(const vector<Segment>& goo){
  46. ld l = 0, m_prev = -1;
  47. for (auto& x: goo){
  48. if (m_prev != -1){
  49. ld m = (x.l + x.r) / 2;
  50. if (m_prev == m) return 0;
  51. m_prev = m;
  52. } else{
  53. m_prev = (x.l + x.r) / 2;
  54. }
  55. ld l_tmp = max(l, x.l);
  56. if (l_tmp + x.t > x.r) return 0;
  57. l = l_tmp + x.t;
  58. }
  59. return 1;
  60. }
  61.  
  62. istream& operator >> (istream& in, Segment& s){
  63. in >> s.l >> s.r >> s.t;
  64. return in;
  65. }
  66.  
  67. int main(){
  68. ios_base::sync_with_stdio(false);
  69. cout.tie(nullptr);
  70. cin.tie(nullptr);
  71. int q;
  72. cin >> q;
  73. while (q--){
  74. int n;
  75. cin >> n;
  76. vector<Segment> goo(n);
  77. for (auto& x: goo) cin >> x;
  78. sort(all(goo), comp);
  79. cout << kek(goo) << '\n';
  80. }
  81.  
  82. }
  83. /*
  84. 2
  85. 2
  86. 1 7 4
  87. 1 3 2
  88. 2
  89. 1 6 4
  90. 1 3 2
  91.  
  92. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement