This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Nurstan Duisengaliev(REALBOY)
// Respa Gold_2022
// IZHO GOLD_2022
// IOI_2022
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define pll pair <ll, ll>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
using namespace std;
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 1;
int n, a[N], b[N];
int pos[N][4], posmx[N];
int posmx2[N];
ll ans[N], cnt[4];
int X[4][N];
void Input () {
cin >> n;
for (int i = 1; i <= n; i ++) {
int x;
cin >> x;
X[1][i] = x;
pos[x][1] = i;
posmx[x] = i;
posmx2[x] = 1;
}
for (int i = 1; i <= n; i ++) {
int x;
cin >> x;
pos[x][2] = i;
X[2][i] = x;
if (posmx[x] > i) posmx2[x] = 2;
posmx[x] = min (posmx[x], i);
}
for (int i = 1; i <= n; i ++) {
int x;
cin >> x;
pos[x][3] = i;
X[3][i] = x;
if (posmx[x] > i) posmx2[x] = 3;
posmx[x] = min (posmx[x], i);
}
}
void Output () {
cout << cnt[1] << " " << cnt[2] << " " << cnt[3] << endl;
for (int i = 1; i <= n; i ++) {
cout << ans[i] << " ";
}
exit (0);
}
int pref[N][7], prefcnt[N][4];
void solve () {
vector <pii> v;
for (int i = 1; i <= n; i ++) {
v.pb (mp (-posmx[i], i));
}
sort (all (v));
for (int i = 0; i < sz (v); i ++) {
int x = v[i].S;
if (i != 0) {
for (int j = 1; j <= 6; j ++) {
if (j <= 3) prefcnt[i][j] = prefcnt[i - 1][j];
pref[i][j] = pref[i - 1][j];
}
}
if (pos[x][1] <= pos[x][2]) pref[i][1] ++;
else pref[i][2] ++;
if (pos[x][1] <= pos[x][3]) pref[i][3] ++;
else pref[i][4] ++;
if (pos[x][2] <= pos[x][3]) pref[i][5] ++;
else pref[i][6] ++;
prefcnt[i][posmx2[x]] ++;
}
for (int i = 1; i <= n; i ++) {
int l = 0, r = sz (v) - 1, o = -1;
while (l <= r) {
int mid = l + r >> 1;
if (v[mid].F < -posmx[i]) {
o = mid;
l = mid + 1;
}
else r = mid - 1;
}
if (o == -1) continue;
ans[i] += o + 1;
if ((pos[i][1] == posmx[i]) + (pos[i][2] == posmx[i]) + (pos[i][3] == posmx[i]) == 3) {
cnt[1] += prefcnt[o][1];
cnt[2] += prefcnt[o][2];
cnt[3] += prefcnt[o][3];
}
else if ((pos[i][1] == posmx[i]) + (pos[i][2] == posmx[i]) + (pos[i][3] == posmx[i]) == 2) {
if (pos[i][1] != posmx[i]) {
cnt[2] += pref[o][5];
cnt[3] += pref[o][6];
}
else if (pos[i][2] != posmx[i]) {
cnt[1] += pref[o][3];
cnt[3] += pref[o][4];
}
else {
cnt[1] += pref[o][1];
cnt[2] += pref[o][2];
}
}
else {
int p;
if (pos[i][1] == posmx[i]) p = 1;
else if (pos[i][2] == posmx[i]) p = 2;
else p = 3;
cnt[p] += o + 1;
}
}
for (int i = 1; i <= n; i ++) {
set <int> s;
for (int k = 1; k <= 3; k ++) {
int j = X[k][posmx[i]];
if (posmx[i] == posmx[j] && i < j) s.in (j);
}
for (auto j : s) {
int o = mod;
int ok = min (posmx[i], posmx[j]);
for (int t = 1; t <= 3; t ++) {
if (min (pos[i][t], pos[j][t]) == ok) {
o = min (o, max (pos[i][t], pos[j][t]));
}
}
int p = -1;
for (int t = 1; t <= 3; t ++) {
if (min (pos[i][t], pos[j][t]) == ok && max (pos[i][t], pos[j][t]) == o) {
p = t;
break;
}
}
cnt[p] ++;
if (pos[i][p] < pos[j][p]) ans[i] ++;
else ans[j] ++;
}
}
}
main () {
boost ();
Input ();
solve ();
Output ();
return 0;
}
Compilation message (stderr)
tenis.cpp: In function 'void solve()':
tenis.cpp:98:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
98 | int mid = l + r >> 1;
| ~~^~~
tenis.cpp: At global scope:
tenis.cpp:162:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
162 | main () {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |