#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 1007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
multiset <int> adj[M];
ll n, q, a[5][M], cnt, pos[5][M];
bool vist[M];
void dfs(int node){
vist[node] = 1; ++cnt;
for(auto i : adj[node]) if(!vist[i]) dfs(i);
return;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for(int i = 1; i <= 3; ++i){
for(int j = 1; j <= n; ++j){
cin >> a[i][j];
pos[i][a[i][j]] = j;
if(j > 1) adj[a[i][j - 1]].insert(a[i][j]);
}
}
while(q--){
int type;
cin >> type;
if(type == 1){
int x;
cin >> x;
dfs(x);
if(cnt == n) cout << "DA\n";
else cout << "NE\n";
for(int i = 1; i <= n; ++i) vist[i] = 0; cnt = 0;
}
else{
int x, y, k;
cin >> k >> x >> y;
int i = pos[k][x], j = pos[k][y];
if(i > 1) adj[a[k][i - 1]].erase(adj[a[k][i - 1]].find(a[k][i]));
if(i < n) adj[a[k][i]].erase(adj[a[k][i]].find(a[k][i + 1]));
if(j < n && j + 1 != i) adj[a[k][j]].erase(adj[a[k][j]].find(a[k][j + 1]));
if(j > 1 && j - 1 != i) adj[a[k][j - 1]].erase(adj[a[k][j - 1]].find(a[k][j]));
swap(a[k][i], a[k][j]);
if(i > 1) adj[a[k][i - 1]].insert(a[k][i]);
if(i < n) adj[a[k][i]].insert(a[k][i + 1]);
if(j < n && j + 1 != i) adj[a[k][j]].insert(a[k][j + 1]);
if(j > 1 && j - 1 != i) adj[a[k][j - 1]].insert(a[k][j]);
}
}
return 0;
}
Compilation message
tenis.cpp: In function 'int main()':
tenis.cpp:53:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
53 | for(int i = 1; i <= n; ++i) vist[i] = 0; cnt = 0;
| ^~~
tenis.cpp:53:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
53 | for(int i = 1; i <= n; ++i) vist[i] = 0; cnt = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
508 KB |
Output is correct |
13 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
508 KB |
Output is correct |
13 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |