#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, q;
int a[MAXN], b[MAXN], c[MAXN];
ll yer1[MAXN], yer2[MAXN], yer3[MAXN], mx[MAXN];
int t[4*MAXN];
void build(int v, int tl, int tr){
if(tl == tr){
t[v] = max(mx[a[tl]], max(mx[b[tl]], mx[c[tl]]));
}else{
int tm = (tl + tr) / 2;
build(2*v, tl, tm);
build(2*v + 1, tm + 1, tr);
t[v] = max(t[2*v], t[2*v + 1]);
}
}
void upd(int v, int tl , int tr, int pos){
if(tl == tr){
t[v] = max(mx[a[tl]], max(mx[b[tl]], mx[c[tl]]));
}else{
int tm = (tl + tr) / 2;
if(pos <= tm)
build(2*v, tl, tm);
else
build(2*v + 1, tm + 1, tr);
t[v] = max(t[2*v], t[2*v + 1]);
}
}
int que(int v, int tl, int tr, int l, int r){
if(l > r) return 0;
else if(tl == l && r == tr){
return t[v];
}else{
int tm = (tl + tr)/2;
ll ans1 = que(2*v, tl, tm, l, min(tm, r)),
ans2 = que(2*v + 1, tm + 1, tr, max(tm + 1, l), r);
return max(ans1, ans2);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("../IO/int.txt","r",stdin);
freopen("../IO/out.txt","w",stdout);
#endif
cin>>n>>q;
for(int i = 1; i <= n; i++){
cin>>a[i];
yer1[a[i]] = i;
}
for(int i = 1; i <= n; i++){
cin>>b[i];
yer2[b[i]] = i;
}
for(int i = 1; i <= n; i++){
cin>>c[i];
yer3[c[i]] = i;
mx[c[i]] = max(yer3[c[i]], max(yer2[c[i]], yer1[c[i]]));
}
bool deg = 0;
build(1, 1, n);
int yer;
while(q--){
int type;
cin>>type;
if(type == 1){
int x;
cin>>x;
if(deg == 0){
deg = 1;
int cur = 1;
ll nx = que(1, 1, n, 1, cur);
while(nx != cur){
//cout<<cur<<" "<<nx<<endl;
cur = nx;
nx = que(1, 1, n, 1, nx);
}
yer = cur;
}
//cout<<yer<<endl;
cout<<(yer >= yer1[x] ? "DA" : "NE")<<endl;
}else{
deg = 0;
int court, l, r;
cin>>court>>l>>r;
if(court == 1){
swap(a[yer1[l]], a[yer1[r]]);
swap(yer1[l], yer1[r]);
ll cur1 = a[yer1[l]], cur2 = a[yer1[r]];
mx[cur1] = max(yer3[cur1], max(yer2[cur1], yer1[cur1]));
mx[cur2] = max(yer3[cur2], max(yer2[cur2], yer1[cur2]));
upd(1, 1, n, yer1[l]);
upd(1, 1, n, yer1[r]);
}else if(court == 2){
swap(b[yer2[l]], b[yer2[r]]);
swap(yer2[l], yer2[r]);
ll cur1 = b[yer2[l]], cur2 = b[yer2[r]];
mx[cur1] = max(yer3[cur1], max(yer2[cur1], yer1[cur1]));
mx[cur2] = max(yer3[cur2], max(yer2[cur2], yer1[cur2]));
upd(1, 1, n, yer2[l]);
upd(1, 1, n, yer2[r]);
}else{
swap(c[yer3[l]], c[yer3[r]]);
swap(yer3[l], yer3[r]);
ll cur1 = c[yer3[l]], cur2 = c[yer3[r]];
mx[cur1] = max(yer3[cur1], max(yer2[cur1], yer1[cur1]));
mx[cur2] = max(yer3[cur2], max(yer2[cur2], yer1[cur2]));
upd(1, 1, n, yer3[l]);
upd(1, 1, n, yer3[r]);
}
}
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
424 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
424 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
65 ms |
7384 KB |
Output is correct |
14 |
Correct |
62 ms |
7416 KB |
Output is correct |
15 |
Correct |
62 ms |
7544 KB |
Output is correct |
16 |
Correct |
57 ms |
7412 KB |
Output is correct |
17 |
Correct |
49 ms |
7416 KB |
Output is correct |
18 |
Correct |
57 ms |
7544 KB |
Output is correct |
19 |
Correct |
53 ms |
7416 KB |
Output is correct |
20 |
Correct |
71 ms |
7416 KB |
Output is correct |
21 |
Correct |
51 ms |
7416 KB |
Output is correct |
22 |
Correct |
62 ms |
7356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
8440 KB |
Output is correct |
2 |
Correct |
70 ms |
8556 KB |
Output is correct |
3 |
Correct |
70 ms |
8440 KB |
Output is correct |
4 |
Correct |
69 ms |
8568 KB |
Output is correct |
5 |
Correct |
70 ms |
8440 KB |
Output is correct |
6 |
Correct |
70 ms |
8564 KB |
Output is correct |
7 |
Correct |
70 ms |
8444 KB |
Output is correct |
8 |
Correct |
70 ms |
8440 KB |
Output is correct |
9 |
Correct |
70 ms |
8568 KB |
Output is correct |
10 |
Correct |
70 ms |
8412 KB |
Output is correct |
11 |
Correct |
72 ms |
8412 KB |
Output is correct |
12 |
Correct |
75 ms |
8588 KB |
Output is correct |
13 |
Correct |
75 ms |
8504 KB |
Output is correct |
14 |
Correct |
72 ms |
8440 KB |
Output is correct |
15 |
Correct |
73 ms |
8488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
424 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
65 ms |
7384 KB |
Output is correct |
14 |
Correct |
62 ms |
7416 KB |
Output is correct |
15 |
Correct |
62 ms |
7544 KB |
Output is correct |
16 |
Correct |
57 ms |
7412 KB |
Output is correct |
17 |
Correct |
49 ms |
7416 KB |
Output is correct |
18 |
Correct |
57 ms |
7544 KB |
Output is correct |
19 |
Correct |
53 ms |
7416 KB |
Output is correct |
20 |
Correct |
71 ms |
7416 KB |
Output is correct |
21 |
Correct |
51 ms |
7416 KB |
Output is correct |
22 |
Correct |
62 ms |
7356 KB |
Output is correct |
23 |
Correct |
70 ms |
8440 KB |
Output is correct |
24 |
Correct |
70 ms |
8556 KB |
Output is correct |
25 |
Correct |
70 ms |
8440 KB |
Output is correct |
26 |
Correct |
69 ms |
8568 KB |
Output is correct |
27 |
Correct |
70 ms |
8440 KB |
Output is correct |
28 |
Correct |
70 ms |
8564 KB |
Output is correct |
29 |
Correct |
70 ms |
8444 KB |
Output is correct |
30 |
Correct |
70 ms |
8440 KB |
Output is correct |
31 |
Correct |
70 ms |
8568 KB |
Output is correct |
32 |
Correct |
70 ms |
8412 KB |
Output is correct |
33 |
Correct |
72 ms |
8412 KB |
Output is correct |
34 |
Correct |
75 ms |
8588 KB |
Output is correct |
35 |
Correct |
75 ms |
8504 KB |
Output is correct |
36 |
Correct |
72 ms |
8440 KB |
Output is correct |
37 |
Correct |
73 ms |
8488 KB |
Output is correct |
38 |
Execution timed out |
1072 ms |
7580 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |