Submission #476365

#TimeUsernameProblemLanguageResultExecution timeMemory
476365Mackerel_PikeTenis (COCI20_tenis)C++14
110 / 110
70 ms4340 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...