# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
368289 |
2021-02-19T21:36:12 Z |
Vimmer |
Tenis (COCI20_tenis) |
C++14 |
|
82 ms |
5096 KB |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
#define N 100501
#define NN 1000500
#define PB push_back
#define M ll(1e9 + 7)
#define all(x) x.begin(), x.end()
#define sz(x) ll(x.size())
#define _ << " " <<
#define pri(x) cout << x << endl
#define endl '\n'
#define F first
#define S second
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef long double ld;
//typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll pos[3][N], ans[N], kol[3], skok[4][3], X, Y;
bool cmpr(ll l, ll r)
{
ll L, R;
if (pos[l][X] > pos[l][Y])
L = pos[l][X];
else L = pos[l][Y];
if (pos[r][X] > pos[r][Y])
R = pos[r][X];
else R = pos[r][Y];
if (L == R) return l < r;
return L < R;
}
ll get(ll x)
{
return min(pos[0][x], min(pos[1][x], pos[2][x]));
}
bool cmp(ll l, ll r)
{
return get(l) <= get(r);
}
ll opr(ll x)
{
if (pos[0][x] <= pos[1][x] && pos[0][x] <= pos[2][x]) return 0;
if (pos[1][x] <= pos[2][x] && pos[1][x] <= pos[0][x]) return 1;
return 2;
}
ll sk(ll x, ll mn)
{
ll kl = 0;
for (ll t = 0; t < 3; t++)
if (pos[t][x] == mn) kl++;
return kl;
}
void calc(ll i, ll j)
{
X = i;
Y = j;
ll x = 1e9;
for (ll t = 0; t < 3; t++)
{
if (pos[t][i] > pos[t][j])
x = min(x, pos[t][j]);
else x = min(x, pos[t][i]);
}
vector <ll> who; who.clear();
for (ll t = 0; t < 3; t++)
{
if (pos[t][i] == x && pos[t][i] < pos[t][j])
{
who.PB(t);
}
if (pos[t][j] == x && pos[t][j] < pos[t][i])
{
who.PB(t);
}
}
sort(all(who), cmpr);
ll t = who[0];
kol[t]++;
if (pos[t][i] > pos[t][j])
ans[j]++;
else ans[i]++;
}
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("pixels.in", "r", stdin);
// freopen("pixels.out", "w", stdout);
ll n;
cin >> n;
for (ll i = 0; i < 3; i++)
for (ll j = 0; j < n; j++)
{
ll x;
cin >> x;
x--;
pos[i][x] = j;
}
vector <ll> vr; vr.clear();
for (ll i = 0; i < n; i++)
vr.PB(i);
sort(all(vr), cmp);
for (ll i = 0; i < sz(vr); i++)
{
ll u = i;
while (u < sz(vr) && get(vr[i]) == get(vr[u]))
u++;
ll l = i, r = u;
if (l + 1 == r)
{
ans[vr[l]] += n - r;
if (sk(vr[l], pos[opr(vr[l])][vr[l]]) == 1)
kol[opr(vr[l])] += n - r;
}
else if (l + 2 == r)
{
ans[vr[l]] = ans[vr[l + 1]] = n - r;
calc(vr[l], vr[l + 1]);
ll lt = opr(vr[l]), rt = opr(vr[l + 1]);
if (sk(vr[l], pos[lt][vr[l]]) == 1)
{
kol[lt] += n - r;
}
if (sk(vr[l + 1], pos[rt][vr[l + 1]]) == 1)
{
kol[rt] += n - r;
}
}
else
{
ans[vr[l]] = ans[vr[l + 2]] = ans[vr[l + 1]] = n - r;
kol[opr(vr[l])] += n - r;
kol[opr(vr[l + 1])] += n - r;
kol[opr(vr[l + 2])] += n - r;
calc(vr[l], vr[l + 1]);
calc(vr[l], vr[l + 2]);
calc(vr[l + 1], vr[l + 2]);
}
i = u - 1;
}
for (ll i = n - 1; i >= 0; i--)
{
ll u = i;
while (u >= 0 && get(vr[u]) == get(vr[i]))
{
ll psr = vr[u];
ll xr = opr(psr);
if (sk(psr, pos[xr][psr]) == 3)
{
for (ll t = 0; t < 3; t++)
kol[t] += skok[3][t];
}
else if (sk(psr, pos[xr][psr]) == 2)
{
ll ps = psr;
ll val = 0;
ll mn = pos[xr][psr];
if (pos[0][ps] == mn && pos[2][ps] == mn)
val = 1;
else if (pos[1][ps] == mn && pos[2][ps] == mn)
val = 2;
for (ll t = 0; t < 3; t++)
kol[t] += skok[val][t];
}
u--;
}
for (ll t = i; t > u; t--)
{
ll ps = vr[t];
ll x = opr(ps);
skok[3][x]++;
if (pos[0][ps] <= pos[1][ps])
skok[0][0]++;
else skok[0][1]++;
if (pos[0][ps] <= pos[2][ps])
skok[1][0]++;
else skok[1][2]++;
if (pos[1][ps] <= pos[2][ps])
skok[2][1]++;
else skok[2][2]++;
}
i = u + 1;
}
ll sum = kol[0] + kol[1] + kol[2];
if (sum != 1ll * n * (n - 1) / 2)
assert(0);
for (ll i = 0; i < 3; i++) cout << kol[i] << " ";
cout << endl;
for (ll i = 0; i < n; i++) cout << ans[i] << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
29 ms |
2284 KB |
Output is correct |
6 |
Correct |
43 ms |
3180 KB |
Output is correct |
7 |
Correct |
58 ms |
4072 KB |
Output is correct |
8 |
Correct |
77 ms |
4968 KB |
Output is correct |
9 |
Correct |
76 ms |
5096 KB |
Output is correct |
10 |
Correct |
82 ms |
4968 KB |
Output is correct |