fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. #include <ext/pb_ds/tree_policy.hpp>
  6. using namespace __gnu_pbds;
  7.  
  8. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  9.  
  10. int main(){
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(NULL);
  13. cout.tie(NULL);
  14. int n, m, i, j;
  15. cin >> n >> m;
  16. int arr[n][m];
  17. int ans[n][m];
  18.  
  19. for(i = 0; i < n; i++)
  20. for(j = 0; j < m; j++)
  21. cin >> arr[i][j];
  22.  
  23. vector<ordered_set> row;
  24. vector<ordered_set> col;
  25.  
  26. ordered_set myset;
  27. myset.clear();
  28.  
  29. for(i = 0; i < n; i++){
  30. myset.clear();
  31. for(j = 0; j < m; j++)
  32. myset.insert(arr[i][j]);
  33. row.emplace_back(myset);
  34. }
  35. for(i = 0; i < m; i++){
  36. myset.clear();
  37. for(j = 0; j < n; j++)
  38. myset.insert(arr[i][j]);
  39. col.emplace_back(myset);
  40. }
  41. for(i = 0; i < n; i++){
  42. for(j = 0; j < m; j++){
  43. ans[i][j] = max(row[i].order_of_key(arr[i][j]), col[j].order_of_key(arr[i][j]));
  44. ans[i][j] += max(row[i].size()-row[i].order_of_key(arr[i][j]), col[j].size() - col[j].order_of_key(arr[i][j]));
  45. }
  46. }
  47. i = 1; j = 2;
  48. // cout<<max(row[i].order_of_key(arr[i][j]), col[j].order_of_key(arr[i][j]))<<"\n";
  49. // cout<<max(row[i].size()-row[i].order_of_key(arr[i][j]), col[j].size() - col[j].order_of_key(arr[i][j]))<<"\n";
  50. // // cout<<col[2].size()-col[2].order_of_key(arr[1][2]);
  51. for(auto it = col[j].begin(); it != col[j].end(); ++it)
  52. cout<<*it<<" ";
  53.  
  54. // for(i = 0; i < n; i++){
  55. // for(j = 0; j < m; j++)
  56. // cout<<ans[i][j]<<" ";
  57. // cout<<"\n";
  58. // }
  59. // row.clear();
  60. // col.clear();
  61. // myset.clear();
  62. }
Success #stdin #stdout 0s 4440KB
stdin
2 3
1 2 1
2 1 2
stdout
21976 609927618