# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
144257 | SamAnd | Tenis (COI19_tenis) | C++17 | 117 ms | 2444 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |