Korotkodul

CF

Jan 10th, 2022 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. using namespace std;
  12. using ll = long long;
  13. using ld = long double;
  14. using db = double;
  15. void cv(vector <int> &v){
  16. for (auto x: v) cout<<x<<' ';
  17. cout<<"\n";
  18. }
  19.  
  20. void cvl(vector <ll> &v){
  21. for (auto x: v) cout<<x<<' ';
  22. cout<<"\n";
  23. }
  24.  
  25.  
  26. void cvv(vector <vector <int> > &v){
  27. for (auto x: v) cv(x);
  28. cout<<"\n";
  29. }
  30. int t,n;
  31. vector <int> v;
  32.  
  33. vector <vector<int>> nd;
  34. map <int, vector<int>> var;
  35. vector <pair <int, vector<int> > > varV, ndV;
  36.  
  37. void ch(int x){
  38. int st=x;
  39. //cout<<"x y = "<<x<<' '<<y<<"\n";
  40. while (x >= 1){
  41. cout<<"x = "<<x<<"\n";
  42. if (x >= 1 && x <= n){
  43. cout<<"ok\n";
  44. nd[x-1].push_back(st);
  45. var[st].push_back(x);
  46.  
  47. }
  48. x /= 2;
  49. }
  50. //return 0;
  51. }
  52.  
  53. bool cmp( vector <int> a, vector <int> b){
  54. return a.size() < b.size();
  55. }
  56.  
  57. bool cmpV(pair <int, vector <int> > a, pair <int, vector <int> > b){
  58. return a.second.size() < b.second.size();
  59. //return a_sz < b_sz;
  60. }
  61.  
  62. int main()
  63. {
  64. /*ios::sync_with_stdio(0);
  65. cin.tie(0);
  66. cout.tie(0);*/
  67. cin>>t;
  68. for (int i=0;i<t;++i){
  69. cin>>n;
  70. v.resize(n);
  71. nd.resize(n);
  72. var.clear();
  73. //var.resize(n);
  74. //cout<<"v\n";
  75. for (int j=0;j<n;++j) cin>>v[j];
  76. for (int j = 0;j< n;++j){
  77. ch(v[j]);
  78. }
  79. //cv(v);
  80. sort(v.begin(), v.end());
  81. cout<<"v\n";
  82. cv(v);
  83.  
  84. cout<<"\n";
  85. //cout<<"var\n";
  86. for (auto x: var){
  87. //cout<<"("<<x.first<<"): "; cv(x.second);
  88. varV.push_back(x);
  89. }
  90.  
  91. cout<<"\n\n";
  92. for (int j = 0; j < n;++j){
  93. ndV.push_back({j+1, nd[j]});
  94. }
  95. sort(ndV.begin(), ndV.end(),cmpV);
  96. //sort(varV.begin(), varV.end(), cmpV);
  97. cout<<"nd\n";
  98. for (int j=0;j<n;++j){
  99. cout<<"("<<ndV[j].first<<"): ";
  100. cv(ndV[j].second);
  101. }
  102. cout<<"Var\n";
  103. for (int j=0;j<varV.size();++j){
  104. cout<<varV[j].first<<" : "; cv(varV[j].second);
  105. }
  106. cout<<"\n\n";
  107.  
  108. }
  109. }
  110. /*
  111. 6
  112. 4
  113. 1 8 25 2
  114. 2
  115. 1 1
  116. 9
  117. 9 8 3 4 2 7 1 5 6
  118. 3
  119. 8 2 1
  120. 4
  121. 24 7 16 7
  122. 5
  123. 22 6 22 4 22
  124.  
  125. */
  126.  
Add Comment
Please, Sign In to add comment