# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
222638 | kingfran1907 | Tenis (COI19_tenis) | C++14 | 1085 ms | 5756 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 maxn = 1e5+10;
int n, q;
int niz[3][maxn];
int pos[3][maxn];
bool bio[maxn];
int las[3];
queue< int > qs;
void bfs() {
memset(las, -1, sizeof las);
memset(bio, false, sizeof bio);
bio[niz[0][0]] = true; qs.push(niz[0][0]);
bio[niz[1][0]] = true; qs.push(niz[1][0]);
bio[niz[2][0]] = true; qs.push(niz[2][0]);
while (!qs.empty()) {
int x = qs.front();
qs.pop();
for (int i = 0; i < 3; i++) {
for (int j = las[i] + 1; j <= pos[i][x]; j++) {
if (!bio[niz[i][j]]) {
qs.push(niz[i][j]);
bio[niz[i][j]] = true;
}
}
las[i] = max(las[i], pos[i][x]);
}
}
}
int main() {
scanf("%d%d", &n, &q);
for (int i = 0; i < 3; i++)
for (int j = 0; j < n; j++)
scanf("%d", &niz[i][j]);
for (int i = 0; i < 3; i++)
for (int j = 0; j < n; j++)
pos[i][niz[i][j]] = j;
bfs();
for (int i = 0; i < q; i++) {
int type;
scanf("%d", &type);
if (type == 1) {
int x;
scanf("%d", &x);
if (bio[x]) printf("DA\n");
else printf("NE\n");
} else {
int p, a, b;
scanf("%d%d%d", &p, &a, &b); p--;
int pa = pos[p][a], pb = pos[p][b];
swap(niz[p][pa], niz[p][pb]);
swap(pos[p][a], pos[p][b]);
bfs();
}
}
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... |