#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 = 100007;
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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
4 ms |
5196 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
4 ms |
5196 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
130 ms |
26420 KB |
Output is correct |
14 |
Correct |
136 ms |
26672 KB |
Output is correct |
15 |
Correct |
157 ms |
26728 KB |
Output is correct |
16 |
Correct |
163 ms |
26536 KB |
Output is correct |
17 |
Correct |
177 ms |
27448 KB |
Output is correct |
18 |
Correct |
146 ms |
27412 KB |
Output is correct |
19 |
Correct |
152 ms |
27124 KB |
Output is correct |
20 |
Correct |
97 ms |
25508 KB |
Output is correct |
21 |
Correct |
196 ms |
27296 KB |
Output is correct |
22 |
Correct |
144 ms |
27016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
25292 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
4 ms |
5196 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
130 ms |
26420 KB |
Output is correct |
14 |
Correct |
136 ms |
26672 KB |
Output is correct |
15 |
Correct |
157 ms |
26728 KB |
Output is correct |
16 |
Correct |
163 ms |
26536 KB |
Output is correct |
17 |
Correct |
177 ms |
27448 KB |
Output is correct |
18 |
Correct |
146 ms |
27412 KB |
Output is correct |
19 |
Correct |
152 ms |
27124 KB |
Output is correct |
20 |
Correct |
97 ms |
25508 KB |
Output is correct |
21 |
Correct |
196 ms |
27296 KB |
Output is correct |
22 |
Correct |
144 ms |
27016 KB |
Output is correct |
23 |
Execution timed out |
1090 ms |
25292 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |