This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> mn(n, n - 1);
vector<vector<int>> a(3, vector<int> (n));
vector<vector<int>> id(3, vector<int> (n));
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
--a[i][j];
id[i][a[i][j]] = j;
mn[a[i][j]] = min(mn[a[i][j]], j);
}
}
vector<int> suf(n);
for (int i = 0; i < n; ++i) {
suf[mn[i]]++;
}
for (int i = n - 2; i >= 0; --i) {
suf[i] += suf[i + 1];
}
vector<bool> vis(n);
vector<long long> c(3), p(n);
for (int j = 0; j < n - 1; ++j) {
for (int i = 0; i < 3; ++i) {
if (vis[a[i][j]]) {
continue;
}
vis[a[i][j]] = true;
c[i] += suf[j + 1];
p[a[i][j]] += suf[j + 1];
for (int k = i + 1; k < 3; ++k) {
if (vis[a[k][j]]) {
continue;
}
if (id[k][a[i][j]] < id[i][a[k][j]]) {
c[k]++;
p[a[k][j]]++;
} else {
c[i]++;
p[a[i][j]]++;
}
}
}
}
for (int i = 0; i < 3; ++i) {
cout << c[i] << " \n"[i == 2];
}
for (int i = 0; i < n; ++i) {
cout << p[i] << " \n"[i == n - 1];
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |