#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define fst first
#define snd second
const int maxn = 1e5 + 5;
int n;
int p[3][maxn], q[3][maxn], cnt[3], ansC[maxn], vis[maxn], vis2[maxn], cnt2[3][3];
long long ansG[3];
inline void brute(int i, int j){
pair<pair<int, int>, int> val = MP(MP(n, n), -1);
for(int k = 0; k < 3; ++k)
val = min(val, MP(MP(min(q[k][i], q[k][j]), max(q[k][i], q[k][j])), k));
int res = val.snd;
++ansG[res];
if(q[res][i] < q[res][j])
++ansC[i];
else
++ansC[j];
return;
}
inline void update(int i, int k){
vis[i] += k;
int mx = -1;
for(int j = 0; j < 3; ++j)
if(!~mx || q[j][i] < q[mx][i])
mx = j;
cnt[mx] += k;
for(int x = 0; x < 3; ++x)
for(int y = 0; y < 3; ++y)
cnt2[x][y] += (MP(q[x][i], x) < MP(q[y][i], y)) * k;
return;
}
int main(){
//freopen("tenis.in", "r", stdin);
scanf("%d", &n);
for(int i = 0; i < 3; ++i)
for(int j = 0; j < n; ++j){
scanf("%d", &p[i][j]), --p[i][j], q[i][p[i][j]] = j;
}
for(int i = 0; i < n; ++i)
update(i, 1);
for(int i = 0; i < n; ++i){
vector<int> vec;
for(int j = 0; j < 3; ++j)
if(vis[p[j][i]])
vec.PB(p[j][i]);
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for(int j = 0; j < vec.size(); ++j)
for(int k = j + 1; k < vec.size(); ++k)
brute(vec[j], vec[k]);
for(int j = 0; j < 3; ++j)
if(vis[p[j][i]])
update(p[j][i], -1);
for(int j = 0; j < 3; ++j){
if(vis2[p[j][i]])
continue;
int same = 0;
for(int k = 0; k < 3; ++k)
same += (p[k][i] == p[j][i]);
if(same == 1){
for(int k = 0; k < 3; ++k){
ansG[j] += cnt[k];
ansC[p[j][i]] += cnt[k];
}
}
else if(same == 2){
for(int k = 0; k < 3; ++k)
if(p[k][i] == p[j][i] && j != k){
ansG[j] += cnt2[j][k];
ansC[p[j][i]] += cnt2[j][k];
}
}
else{
ansG[j] += cnt[j];
ansC[p[j][i]] += cnt[j];
}
}
for(int j = 0; j < 3; ++j)
vis2[p[j][i]] = true;
}
for(int i = 0; i < 3; ++i)
printf("%lld ", ansG[i]); puts("");
for(int i = 0; i < n; ++i)
printf("%d ", ansC[i]); puts("");
return 0;
}
Compilation message
tenis.cpp: In function 'int main()':
tenis.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int j = 0; j < vec.size(); ++j)
| ~~^~~~~~~~~~~~
tenis.cpp:63:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int k = j + 1; k < vec.size(); ++k)
| ~~^~~~~~~~~~~~
tenis.cpp:100:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
100 | for(int i = 0; i < 3; ++i)
| ^~~
tenis.cpp:101:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
101 | printf("%lld ", ansG[i]); puts("");
| ^~~~
tenis.cpp:102:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
102 | for(int i = 0; i < n; ++i)
| ^~~
tenis.cpp:103:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
103 | printf("%d ", ansC[i]); puts("");
| ^~~~
tenis.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
tenis.cpp:48:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d", &p[i][j]), --p[i][j], q[i][p[i][j]] = j;
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
26 ms |
1940 KB |
Output is correct |
6 |
Correct |
38 ms |
2668 KB |
Output is correct |
7 |
Correct |
58 ms |
3520 KB |
Output is correct |
8 |
Correct |
65 ms |
4340 KB |
Output is correct |
9 |
Correct |
58 ms |
4296 KB |
Output is correct |
10 |
Correct |
70 ms |
4308 KB |
Output is correct |