Submission #144257

#TimeUsernameProblemLanguageResultExecution timeMemory
144257SamAndTenis (COI19_tenis)C++17
18 / 100
117 ms2444 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1003; struct ban { int x, y, z; }; int n, q; ban a[N]; bool aa[N][N], bb[N][N]; int c[N]; vector<int> v; void dfs(int x) { c[x] = 1; for (int h = 1; h <= n; ++h) { if (aa[x][h] == true) { if (!c[h]) dfs(h); } } v.push_back(x); } int k; void dfs1(int x) { c[x] = k; for (int h = 1; h <= n; ++h) { if (bb[x][h] == true) { if (!c[h]) dfs1(h); } } } int qq; bool cc[N]; void bil() { memset(aa, false, sizeof aa); memset(bb, false, sizeof bb); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (a[i].x <= a[j].x || a[i].y <= a[j].y || a[i].z <= a[j].z) { aa[i][j] = true; bb[j][i] = true; } } } memset(c, 0, sizeof c); v.clear(); for (int i = 1; i <= n; ++i) { if (c[i] == 0) dfs(i); } memset(c, 0, sizeof c); k = 0; reverse(v.begin(), v.end()); for (int i = 0; i < v.size(); ++i) { int x = v[i]; if (!c[x]) { ++k; dfs1(x); } } memset(cc, false, sizeof cc); for (int x = 1; x <= n; ++x) { for (int y = 1; y <= n; ++y) { if (aa[x][y] == true) { if (c[x] == c[y]) continue; cc[c[y]] = true; } } } qq = 0; for (int i = 1; i <= k; ++i) { if (cc[i] == false) ++qq; } } int main() { scanf("%d%d", &n, &q); for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); a[x].x = i; } for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); a[x].y = i; } for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); a[x].z = i; } bil(); while (q--) { int ty; scanf("%d", &ty); if (ty == 1) { int x; scanf("%d", &x); if (qq == 1 && cc[c[x]] == false) printf("DA\n"); else printf("NE\n"); } else { int p, x, y; scanf("%d%d%d", &p, &x, &y); if (p == 1) swap(a[x].x, a[y].x); else if (p == 2) swap(a[x].y, a[y].y); else swap(a[x].z, a[y].z); bil(); } } return 0; }

Compilation message (stderr)

tenis.cpp: In function 'void bil()':
tenis.cpp:72:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
tenis.cpp: In function 'int main()':
tenis.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:108:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
tenis.cpp:114:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
tenis.cpp:120:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
tenis.cpp:127:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ty);
         ~~~~~^~~~~~~~~~~
tenis.cpp:131:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
tenis.cpp:140:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d", &p, &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...