# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242473 | MatesV13 | Tenis (COI19_tenis) | C++11 | 1072 ms | 6920 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;
int n, q, ter[3][100005], rev[3][100005], v[100005], pa, pb, pc;
void provjeri (int idx){
if (v[idx]) return; v[idx]=1;
while (pa>rev[0][idx]){pa--; provjeri(ter[0][pa]);}
while (pb>rev[1][idx]){pb--; provjeri(ter[1][pb]);}
while (pc>rev[2][idx]){pc--; provjeri(ter[2][pc]);}
return;
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i=0; i<3; i++){
for (int j=0; j<n; j++){
cin >> ter[i][j];
rev[i][ter[i][j]]=j;
}
}
while (q--){
int tip; cin >> tip;
if (tip==1){
int x; cin >> x; pa=pb=pc=n;
for (int i=1; i<=n; i++) v[i]=0;
provjeri(x); bool ok=1;
for (int i=1; i<=n; i++){
ok = ok and v[i];
}
if (ok) cout << "DA\n";
else cout << "NE\n";
}
else {
int p, a, b, posa, posb;
cin >> p >> a >> b;
for (int i=0; i<n; i++)
if (ter[p-1][i]==a){
posa=i; break;
}
for (int i=0; i<n; i++)
if (ter[p-1][i]==b){
posb=i; break;
}
swap(rev[p-1][a], rev[p-1][b]);
swap(ter[p-1][posa], ter[p-1][posb]);
}
}
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... |