#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[3][n];
int pos[3][n];
vector <int> cnt(3, 0);
vector <int> cnt1(n, 0);
for(int i = 0; i < 3; i++)
{
for(int j = 0;j < n; j++)
{
cin >> a[i][j];
a[i][j]--;
pos[i][a[i][j]] = j;
}
}
for(int i = 0; i < 3; i++)
{
int sum = 0;
vector <int> bal(n, 0);
vector <vector <int> > mat(n, vector <int> (8, 0));
vector <int> mat1(8, 0);
for(int j = n - 1; j >= 0; j--)
{
vector <int> vc;
for(int t = 0; t < 3; t++)
{
if(a[t][j] == a[i][j])
{
continue;
}
vc.push_back(a[t][j]);
}
sort(vc.begin(), vc.end());
vc.resize(unique(vc.begin(), vc.end()) - vc.begin());
for(int it = 0; it < vc.size(); it++)
{
int t = vc[it];
bool fl = 1;
// cout << t << " ";
for(int k = 0; k < 3; k++)
{
if(pos[k][t] < j || pos[k][a[i][j]] < j)
{
fl = 0;
}
if(t == a[k][j])
{
if(pos[k][a[i][j]] < pos[i][t] || pos[k][a[i][j]] == pos[i][t] && k < i)
{
fl = 0;
}
}
else if(a[i][j] == a[k][j])
{
if(pos[k][t] < pos[i][t] || pos[k][t] == pos[i][t] && k < i)
{
fl = 0;
}
}
}
if(fl)
{
cnt[i]++;
cnt1[a[i][j]]++;
}
}
// cout << "\n";
bool flag = 1;
for(int t = 0; t < 3; t++)
{
if(t != i && pos[t][a[i][j]] <= j)
{
flag = 0;
}
}
if(flag)
{
// cnt1[a[i][j]] += sum;
// cnt[i] += sum;
}
int mina = j;
for(int t =0; t < 3; t++)
{
mina = min(mina, pos[t][a[i][j]]);
}
if(mina == j)
{
int maskt = 0;
for(int t = 0; t < 3; t++)
{
if(t != i && a[t][j] == a[i][j])
{
maskt += (1 << t);
}
}
cnt[i] += mat1[maskt];
cnt1[a[i][j]] += mat1[maskt];
// cout << mat1[maskt] << " ";
}
else
{
// cout << 0 << " ";
}
int mask1 = 0;
for(int t = 0; t < 3; t++)
{
if((pos[t][a[i][j]] > j || pos[t][a[i][j]] == j && t > i) && t != i)
{
mask1 |= (1 << t);
}
}
for(int mask2 = mask1; mask2 >= 0; mask2 = (mask2 - 1) & mask1)
{
mat[mina][mask2]++;
if(mask2 == 0)
{
break;
}
}
for(int k = 0; k < 8; k++)
{
mat1[k] += mat[j][k];
}
bal[mina]++;
sum += bal[j];
}
// cout << "\n";
}
for(int i = 0; i < 3; i++)
{
cout << cnt[i] << " ";
}
cout << "\n";
for(int i = 0; i < n; i++)
{
cout << cnt1[i] << " ";
}
return 0;
}
Compilation message
tenis.cpp: In function 'int main()':
tenis.cpp:43:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int it = 0; it < vc.size(); it++)
| ~~~^~~~~~~~~~~
tenis.cpp:56:88: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
56 | if(pos[k][a[i][j]] < pos[i][t] || pos[k][a[i][j]] == pos[i][t] && k < i)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
tenis.cpp:63:76: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
63 | if(pos[k][t] < pos[i][t] || pos[k][t] == pos[i][t] && k < i)
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
tenis.cpp:115:65: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
115 | if((pos[t][a[i][j]] > j || pos[t][a[i][j]] == j && t > i) && t != i)
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
876 KB |
Output is correct |
5 |
Correct |
57 ms |
7168 KB |
Output is correct |
6 |
Correct |
93 ms |
10512 KB |
Output is correct |
7 |
Correct |
139 ms |
13984 KB |
Output is correct |
8 |
Correct |
230 ms |
17332 KB |
Output is correct |
9 |
Correct |
120 ms |
17400 KB |
Output is correct |
10 |
Correct |
107 ms |
17324 KB |
Output is correct |