Advertisement
he_obviously

Untitled

Oct 29th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <limits.h>
  5. #include <map>
  6. #include <unordered_map>
  7. #include <set>
  8. #include <unordered_set>
  9. #include <string>
  10. #include <algorithm>
  11. #include <iomanip>
  12. #include <random>
  13. #include <time.h>
  14. #include <bitset>
  15. #include <queue>
  16. #include <deque>
  17.  
  18. using namespace std;
  19.  
  20. typedef long long ll;
  21. typedef unsigned long long ull;
  22. typedef long double ld;
  23.  
  24. #define all(x) (x).begin(),(x).end()
  25. #define sz(x) (int)x.size()
  26.  
  27. int main() {
  28.  
  29.     ios_base::sync_with_stdio(0);
  30.     cin.tie(0); cout.tie(0);
  31.  
  32.     int n;
  33.     cin >> n;
  34.  
  35.     vector<int> a[3];
  36.  
  37.     for (int i = 0; i < 3; ++i) {
  38.         a[i].resize(n);
  39.         for (int j = 0; j < n; ++j) {
  40.             int pos;
  41.             cin >> pos;
  42.             --pos;
  43.             a[i][pos] = j;
  44.         }
  45.     }
  46.  
  47.     int cnt[3];
  48.     cnt[0] = cnt[1] = cnt[2] = 0;
  49.  
  50.     vector<vector<int>> comp(n, vector<int>(n, -1));
  51.  
  52.     for (int f = 0; f < n - 1; ++f) {
  53.         for (int s = f + 1; s < n; ++s) {
  54.             int mnf = min(a[0][f], min(a[1][f], a[2][f]));
  55.             int mns = min(a[0][s], min(a[1][s], a[2][s]));
  56.             if (mnf < mns) {
  57.                 int pos = 0;
  58.                 for (int i = 0; i < 3; ++i) {
  59.                     if (a[i][f] == mnf && a[pos][f] != mnf) {
  60.                         pos = i;
  61.                     }
  62.                     if (a[i][f] == mnf && a[i][s] < a[pos][s]) {
  63.                         pos = i;
  64.                     }
  65.                 }
  66.                 comp[f][s] = comp[s][f] = pos;
  67.                 ++cnt[pos];
  68.             }
  69.             else if (mns < mnf) {
  70.                 int pos = 0;
  71.                 for (int i = 0; i < 3; ++i) {
  72.                     if (a[i][s] == mns && a[pos][s] != mns) {
  73.                         pos = i;
  74.                     }
  75.                     if (a[i][s] == mns && a[i][f] < a[pos][f]) {
  76.                         pos = i;
  77.                     }
  78.                 }
  79.                 comp[f][s] = comp[s][f] = pos;
  80.                 ++cnt[pos];
  81.             }
  82.             else {
  83.                 if (a[0][f] == mnf && a[0][s] == mnf) {
  84.                     comp[f][s] = comp[s][f] = 0;
  85.                     ++cnt[0];
  86.                 }
  87.                 else if (a[1][f] == mnf && a[1][s] == mnf) {
  88.                     comp[f][s] = comp[s][f] = 1;
  89.                     ++cnt[1];
  90.                 }
  91.                 else if (a[2][f] == mnf && a[2][s] == mnf) {
  92.                     comp[f][s] = comp[s][f] = 2;
  93.                     ++cnt[2];
  94.                 }
  95.                 else {
  96.                     int pos = 0;
  97.                     for (int i = 0; i < 3; ++i) {
  98.                         if (min(a[i][f], a[i][s]) == mnf) {
  99.                             if (min(a[pos][f], a[pos][s]) != mnf) {
  100.                                 pos = i;
  101.                             }
  102.                             if (max(a[i][f], a[i][s]) < max(a[pos][f], a[pos][s])) {
  103.                                 pos = i;
  104.                             }
  105.                         }
  106.                     }
  107.                     comp[f][s] = comp[s][f] = pos;
  108.                     ++cnt[pos];
  109.                 }
  110.             }
  111.         }
  112.     }
  113.  
  114.     cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << "\n";
  115.  
  116.     vector<int> vic(n, 0);
  117.  
  118.     for (int i = 0; i < n; ++i) {
  119.         for (int j = i + 1; j < n; ++j) {
  120.             if (i == j) continue;
  121.             if (a[comp[i][j]][i] < a[comp[i][j]][j]) {
  122.                 ++vic[i];
  123.             }
  124.             else {
  125.                 ++vic[j];
  126.             }
  127.         }
  128.     }
  129.  
  130.     for (int i : vic) {
  131.         cout << i << " ";
  132.     }
  133.  
  134.     return 0;
  135. }
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement