#include <iostream>
#include <vector>
using namespace std;
const int N = 1e5 + 10;
vector<int> nei[N];
int a[N], b[N], c[N], ind1[N], ind2[N], ind3[N], Mn[N], seen[N];
void dfs(int u){
seen[u] = 1;
for (int i : nei[u])
if (!seen[i])
dfs(i);
}
void solve1(int n, int m){
for (int i=n, mn = n + 1;i>=1;i--){
mn = min(mn, ind1[b[i]]);
Mn[b[i]] = mn;
}
for (int i=n, mn = n + 1;i>=1;i--){
mn = min(mn, ind1[c[i]]);
Mn[c[i]] = min(Mn[c[i]], mn);
}
// for (int i=1;i<=n;i++)
// cout<<i<<" "<<Mn[i]<<'\n';
// exit(0);
for (int i=1;i<=n;i++)
nei[i].clear(), seen[i] = 0;
for (int i=1;i<n;i++)
nei[i+1].push_back(i);
for (int i=1;i<=n;i++)
if (Mn[i] < ind1[i]){
nei[Mn[i]].push_back(ind1[i]);
// cout<<ind1[i]<<" "<<Mn[i]<<'\n';
}
dfs(1);
}
int main(){
int n, m;
cin>>n>>m;
for (int i=1;i<=n;i++)
cin>>a[i], ind1[a[i]] = i;
for (int j=1;j<=n;j++)
cin>>b[j], ind2[b[j]] = j;
for (int k=1;k<=n;k++)
cin>>c[k], ind3[c[k]] = k;
int done = 0;
while (m--){
int t,x, P, A, B;
cin>>t;
if (t == 2){
cin>>P>>A>>B;
done = 0;
if (P == 1){
a[ind1[A]] = B;
a[ind1[B]] = A;
swap(ind1[A], ind1[B]);
}
else if (P == 2){
b[ind2[A]] = B;
b[ind2[B]] = A;
swap(ind2[A], ind2[B]);
}
else{
c[ind3[A]] = B;
c[ind3[B]] = A;
swap(ind3[A], ind3[B]);
}
}
else{
if (!done)
solve1(n, m);
done = 1;
cin>>x;
if (seen[ind1[x]])
cout<<"DA\n";
else
cout<<"NE\n";
}
}
}
/*
6 1
4 6 1 5 3 2
4 1 5 2 6 3
4 6 1 5 2 3
1 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5724 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5724 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
47 ms |
11244 KB |
Output is correct |
14 |
Correct |
47 ms |
11348 KB |
Output is correct |
15 |
Correct |
47 ms |
10840 KB |
Output is correct |
16 |
Correct |
46 ms |
10852 KB |
Output is correct |
17 |
Correct |
47 ms |
10572 KB |
Output is correct |
18 |
Correct |
45 ms |
10348 KB |
Output is correct |
19 |
Correct |
52 ms |
10396 KB |
Output is correct |
20 |
Correct |
40 ms |
6484 KB |
Output is correct |
21 |
Correct |
49 ms |
10324 KB |
Output is correct |
22 |
Correct |
47 ms |
10556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
10320 KB |
Output is correct |
2 |
Correct |
160 ms |
12356 KB |
Output is correct |
3 |
Correct |
165 ms |
12372 KB |
Output is correct |
4 |
Correct |
168 ms |
12108 KB |
Output is correct |
5 |
Correct |
160 ms |
12360 KB |
Output is correct |
6 |
Correct |
159 ms |
12116 KB |
Output is correct |
7 |
Correct |
155 ms |
12244 KB |
Output is correct |
8 |
Correct |
158 ms |
11972 KB |
Output is correct |
9 |
Correct |
156 ms |
12356 KB |
Output is correct |
10 |
Correct |
149 ms |
12112 KB |
Output is correct |
11 |
Correct |
152 ms |
12500 KB |
Output is correct |
12 |
Correct |
165 ms |
12244 KB |
Output is correct |
13 |
Correct |
155 ms |
12372 KB |
Output is correct |
14 |
Correct |
156 ms |
12368 KB |
Output is correct |
15 |
Correct |
157 ms |
12368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5724 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
47 ms |
11244 KB |
Output is correct |
14 |
Correct |
47 ms |
11348 KB |
Output is correct |
15 |
Correct |
47 ms |
10840 KB |
Output is correct |
16 |
Correct |
46 ms |
10852 KB |
Output is correct |
17 |
Correct |
47 ms |
10572 KB |
Output is correct |
18 |
Correct |
45 ms |
10348 KB |
Output is correct |
19 |
Correct |
52 ms |
10396 KB |
Output is correct |
20 |
Correct |
40 ms |
6484 KB |
Output is correct |
21 |
Correct |
49 ms |
10324 KB |
Output is correct |
22 |
Correct |
47 ms |
10556 KB |
Output is correct |
23 |
Correct |
151 ms |
10320 KB |
Output is correct |
24 |
Correct |
160 ms |
12356 KB |
Output is correct |
25 |
Correct |
165 ms |
12372 KB |
Output is correct |
26 |
Correct |
168 ms |
12108 KB |
Output is correct |
27 |
Correct |
160 ms |
12360 KB |
Output is correct |
28 |
Correct |
159 ms |
12116 KB |
Output is correct |
29 |
Correct |
155 ms |
12244 KB |
Output is correct |
30 |
Correct |
158 ms |
11972 KB |
Output is correct |
31 |
Correct |
156 ms |
12356 KB |
Output is correct |
32 |
Correct |
149 ms |
12112 KB |
Output is correct |
33 |
Correct |
152 ms |
12500 KB |
Output is correct |
34 |
Correct |
165 ms |
12244 KB |
Output is correct |
35 |
Correct |
155 ms |
12372 KB |
Output is correct |
36 |
Correct |
156 ms |
12368 KB |
Output is correct |
37 |
Correct |
157 ms |
12368 KB |
Output is correct |
38 |
Execution timed out |
1059 ms |
12116 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |