Korotkodul

Электрички OK

Jan 19th, 2022 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. #include <iostream>
  8. #include <cmath>
  9. #include <vector>
  10. #include <queue>
  11. #include <algorithm>
  12. #include <string>
  13. #include <stack>
  14. #include <set>
  15. #include <map>
  16. #define pii pair <int,int>
  17. #define vec vector
  18. using namespace std;
  19. using ll = long long;
  20. using ld = long double;
  21. using db = double;
  22. void cv(vector <int> &v){
  23. for (auto x: v) cout<<x<<' ';
  24. cout<<"\n";
  25. }
  26.  
  27. void cvl(vector <ll> &v){
  28. for (auto x: v) cout<<x<<' ';
  29. cout<<"\n";
  30. }
  31.  
  32.  
  33. void cvv(vector <vector <int> > &v){
  34. for (auto x: v) cv(x);
  35. cout<<"\n";
  36. }
  37. int n;
  38. struct el{
  39. ll a,b, c,d;
  40. };
  41.  
  42.  
  43. void mk(el &x){
  44. cin>>x.a>>x.b>>x.c>>x.d;
  45. }
  46.  
  47. ll tm(el x, int st){
  48. return x.c + x.d * (st - x.a);
  49. }
  50.  
  51. pii inter(el x, el y){
  52. pii res = {max(x.a, y.a), min(x.b, y.b)};
  53. if (res.first <= res.second){
  54. return res;
  55. }
  56. return {-1, -1};
  57. }
  58.  
  59.  
  60. vector <el> v;
  61. vector <vector <int> > G;
  62. void mkG(){
  63. el x,y;
  64. ll tx, ty;
  65. pii cmn;
  66. G.resize(n);
  67. for (int i = 0; i < n;++i){
  68. x = v[i];
  69. for (int j = 0; j < n && j != i ; ++ j){
  70. y = v[j];
  71. cmn = inter(x, y);
  72. if (cmn == pii {-1, -1}){
  73. continue;
  74. }
  75. //int stn = (cmn.first + cmn.second) / 2;
  76. int stn = cmn.first;
  77. tx = tm(x, stn);
  78. ty = tm(y, stn);
  79. if (tx < ty){
  80. G[i].push_back(j);
  81. }
  82. else if (tx > ty){
  83. G[j].push_back(i);
  84. }
  85. else if (tx == ty){
  86. stn = cmn.second;
  87. tx = tm(x, stn);
  88. ty = tm(y, stn);
  89. if (tx < ty){
  90. G[i].push_back(j);
  91. }
  92. else if (tx > ty){
  93. G[j].push_back(i);
  94. }
  95. else{
  96. stn = (cmn.first + cmn.second) / 2;
  97. tx = tm(x, stn);
  98. ty = tm(y, stn);
  99. if (tx < ty){
  100. G[i].push_back(j);
  101. }
  102. else if (tx > ty){
  103. G[j].push_back(i);
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. const int wh=0, gr=1, bl=2;
  111. vector <int> clr;
  112. vector <int> ans;
  113.  
  114. void dfs(int v) {
  115. clr[v] = gr;
  116. for (int u: G[v]){
  117. if (clr[u] == wh){
  118. dfs(u);
  119. }
  120. }
  121. clr[v] = bl;
  122. ans.push_back(v+1);
  123. }
  124.  
  125. int main()
  126. {
  127. ios::sync_with_stdio(0);
  128. cin.tie(0);
  129. cout.tie(0);
  130. cin>>n;
  131. v.resize(n);
  132. for (int i=0;i<n;++i) mk(v[i]);
  133. mkG();
  134. clr.assign(n, wh);
  135. for (int i = 0; i < n;++i){
  136. if (clr[i] == wh) dfs(i);
  137. }
  138. reverse(ans.begin(), ans.end());
  139. cv(ans);
  140. }
  141. /*
  142. 3
  143. 1 10 3 4
  144. 3 5 3 4
  145. 10 11 10 1
  146. */
  147.  
  148.  
  149.  
Add Comment
Please, Sign In to add comment