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 = 1e5 + 10;
int n, q, p[N][3], ind[N][3];
bool check(int x){
int it[3] = {n, n, n};
int nit[3] = {ind[x][0], ind[x][1], ind[x][2]};
int ite = 4 * n;
while (ite > 0){
for (int j = 0; j < 3; j ++){
ite--;
for (int i = it[j]; i >= nit[j]; i --){
ite--;
int ele = p[i][j];
nit[0] = min(nit[0], ind[ele][0]);
nit[1] = min(nit[1], ind[ele][1]);
nit[2] = min(nit[2], ind[ele][2]);
}
it[j] = nit[j] - 1;
}
}
return nit[0] == 1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int j = 0; j < 3; j ++){
for (int i = 1; i <= n; i ++){
cin >> p[i][j];
ind[p[i][j]][j] = i;
}
}
for (int i = 0; i < q; i ++){
int t;
cin >> t;
if (t == 1){
int x;
cin >> x;
cout << (check(x) ? "DA\n" : "NE\n");
}
else{
int j, a, b;
cin >> j >> a >> b;
j--;
swap(p[ind[a][j]][j], p[ind[b][j]][j]);
swap(ind[a][j], ind[b][j]);
}
}
}
# | 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... |