# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
185647 | anonymous | Tenis (COI19_tenis) | C++14 | 1076 ms | 9148 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<iostream>
#include<queue>
#define MAXN 100005
using namespace std;
int N,Q, L[MAXN][3], Pos[MAXN][3], Worst[3][3][MAXN]; //(i,j,k) lowest ranked player on court type i in first k of court type j
bool done[MAXN];
int f1=1, f2=1, f3=1; //frontiers
int op, qa, qb, qc;
queue <int> q;
void slv() {
f1=1, f2=1, f3=1;
for (int i=0; i<3; i++) {
for (int j=1; j<=N; j++) {
Pos[L[j][i]][i]=j;
}
}
for (int i=0; i<3; i++) {
for (int j=1; j<=N; j++) {
for (int k=0; k<3; k++) {
Worst[i][k][j]=0;
} //i is current court, k is court being maximised, j is prefix
}
}
for (int i=0; i<3; i++) {
for (int j=1; j<=N; j++) {
for (int k=0; k<3; k++) {
Worst[i][k][j]=max(max(Worst[i][k][j], Worst[i][k][j-1]), Pos[L[j][i]][k]);
} //i is current court, k is court being maximised, j is prefix
}
}
while (true) {
int pf1=f1, pf2=f2, pf3=f3;
int A[3]={f1,f2,f3};
for (int i=0; i<3; i++) {
f1=max(f1, Worst[0][i][A[i]]);
f2=max(f2, Worst[1][i][A[i]]);
f3=max(f3, Worst[2][i][A[i]]);
}
//printf("%d %d %d\n",f1,f2,f3);
if (f1 == pf1 && f2 == pf2 && f3 == pf3) {break;}
}
}
bool ask(int x) {
return(Pos[x][0] <= f1 || Pos[x][1] <= f2 || Pos[x][2] <= f3);
}
int main() {
//freopen("tenin.txt","r",stdin);
scanf("%d %d",&N,&Q);
for (int i=0; i<3; i++) {
for (int j=1; j<=N; j++) {
scanf("%d", &L[j][i]);
}
}
slv();
for (int i=0; i<Q; i++) {
scanf("%d", &op);
if (op == 2) {
scanf("%d %d %d", &qa, &qb, &qc);
swap(L[Pos[qb][qa-1]][qa-1], L[Pos[qc][qa-1]][qa-1]);
slv();
} else {
scanf("%d", &qa);
printf("%s\n", ask(qa) ? "DA" : "NE");
}
}
}
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... |