#include <bits/stdc++.h>
#define N 100005
using namespace std;
int t[4*N],lazy[4*N];
int pos[N][4];
void push(int v){
t[v*2] += lazy[v];
t[v*2+1] += lazy[v];
lazy[v*2] += lazy[v];
lazy[v*2+1] += lazy[v];
lazy[v] = 0;
}
void upd(int v,int tl,int tr,int l,int r,int val){
if(tr < l || r < tl)return;
if(l <= tl && tr <= r){
t[v]+=val;
lazy[v]+=val;
return;
}
push(v);
int tm = (tl+tr)/2;
upd(v*2,tl,tm,l,r,val);
upd(v*2+1,tm+1,tr,l,r,val);
t[v] = min(t[v*2],t[v*2+1]);
}
int get(int v,int tl,int tr,int l,int r){
if(tr < l || r < tl)return 1e9;
if(l <= tr && tr <= r){
return t[v];
}
push(v);
int tm = (tl+tr)/2;
return min(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
}
void solve(){
int n,q;
cin >> n >> q;
for(int i=1;i<4;i++){
for(int j=1;j<=n;j++){
int a;
cin >> a;
pos[a][i] = j;
}
}
for(int i=1;i<=n;i++){
upd(1,1,n,i,i,i);
upd(1,1,n,max({pos[i][1],pos[i][2],pos[i][3]}),n,-1);
}
while(q--){
int type;
cin >> type;
if(type == 1){
int x;
cin >> x;
cout << (get(1,1,n,1,max({pos[x][1],pos[x][2],pos[x][3]})-1) == 0?"NE":"DA") << endl;
}
if(type == 2){
int p,x,y;
cin >> p >> x >> y;
upd(1,1,n,max({pos[x][1],pos[x][2],pos[x][3]}),n,1);
upd(1,1,n,max({pos[y][1],pos[y][2],pos[y][3]}),n,1);
swap(pos[x][p],pos[y][p]);
upd(1,1,n,max({pos[x][1],pos[x][2],pos[x][3]}),n,-1);
upd(1,1,n,max({pos[y][1],pos[y][2],pos[y][3]}),n,-1);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
97 ms |
5740 KB |
Output is correct |
14 |
Correct |
99 ms |
5740 KB |
Output is correct |
15 |
Correct |
110 ms |
5868 KB |
Output is correct |
16 |
Correct |
101 ms |
5740 KB |
Output is correct |
17 |
Correct |
125 ms |
5760 KB |
Output is correct |
18 |
Correct |
99 ms |
5740 KB |
Output is correct |
19 |
Correct |
98 ms |
5612 KB |
Output is correct |
20 |
Correct |
97 ms |
5740 KB |
Output is correct |
21 |
Correct |
102 ms |
5740 KB |
Output is correct |
22 |
Correct |
103 ms |
5868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
399 ms |
6900 KB |
Output is correct |
2 |
Correct |
389 ms |
6832 KB |
Output is correct |
3 |
Correct |
394 ms |
6872 KB |
Output is correct |
4 |
Correct |
394 ms |
6968 KB |
Output is correct |
5 |
Correct |
392 ms |
6764 KB |
Output is correct |
6 |
Correct |
391 ms |
6892 KB |
Output is correct |
7 |
Correct |
394 ms |
6764 KB |
Output is correct |
8 |
Correct |
397 ms |
6804 KB |
Output is correct |
9 |
Correct |
453 ms |
6764 KB |
Output is correct |
10 |
Correct |
391 ms |
6812 KB |
Output is correct |
11 |
Correct |
399 ms |
6980 KB |
Output is correct |
12 |
Correct |
391 ms |
6764 KB |
Output is correct |
13 |
Correct |
392 ms |
6764 KB |
Output is correct |
14 |
Correct |
389 ms |
6892 KB |
Output is correct |
15 |
Correct |
388 ms |
6892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
97 ms |
5740 KB |
Output is correct |
14 |
Correct |
99 ms |
5740 KB |
Output is correct |
15 |
Correct |
110 ms |
5868 KB |
Output is correct |
16 |
Correct |
101 ms |
5740 KB |
Output is correct |
17 |
Correct |
125 ms |
5760 KB |
Output is correct |
18 |
Correct |
99 ms |
5740 KB |
Output is correct |
19 |
Correct |
98 ms |
5612 KB |
Output is correct |
20 |
Correct |
97 ms |
5740 KB |
Output is correct |
21 |
Correct |
102 ms |
5740 KB |
Output is correct |
22 |
Correct |
103 ms |
5868 KB |
Output is correct |
23 |
Correct |
399 ms |
6900 KB |
Output is correct |
24 |
Correct |
389 ms |
6832 KB |
Output is correct |
25 |
Correct |
394 ms |
6872 KB |
Output is correct |
26 |
Correct |
394 ms |
6968 KB |
Output is correct |
27 |
Correct |
392 ms |
6764 KB |
Output is correct |
28 |
Correct |
391 ms |
6892 KB |
Output is correct |
29 |
Correct |
394 ms |
6764 KB |
Output is correct |
30 |
Correct |
397 ms |
6804 KB |
Output is correct |
31 |
Correct |
453 ms |
6764 KB |
Output is correct |
32 |
Correct |
391 ms |
6812 KB |
Output is correct |
33 |
Correct |
399 ms |
6980 KB |
Output is correct |
34 |
Correct |
391 ms |
6764 KB |
Output is correct |
35 |
Correct |
392 ms |
6764 KB |
Output is correct |
36 |
Correct |
389 ms |
6892 KB |
Output is correct |
37 |
Correct |
388 ms |
6892 KB |
Output is correct |
38 |
Correct |
319 ms |
7308 KB |
Output is correct |
39 |
Correct |
358 ms |
7020 KB |
Output is correct |
40 |
Correct |
305 ms |
7148 KB |
Output is correct |
41 |
Correct |
336 ms |
7148 KB |
Output is correct |
42 |
Correct |
374 ms |
7148 KB |
Output is correct |
43 |
Correct |
302 ms |
7176 KB |
Output is correct |
44 |
Correct |
353 ms |
6892 KB |
Output is correct |
45 |
Correct |
352 ms |
6892 KB |
Output is correct |
46 |
Correct |
352 ms |
6892 KB |
Output is correct |
47 |
Correct |
333 ms |
7020 KB |
Output is correct |
48 |
Correct |
372 ms |
6992 KB |
Output is correct |
49 |
Correct |
334 ms |
7020 KB |
Output is correct |
50 |
Correct |
353 ms |
6892 KB |
Output is correct |
51 |
Correct |
339 ms |
7020 KB |
Output is correct |
52 |
Correct |
305 ms |
7148 KB |
Output is correct |
53 |
Correct |
333 ms |
7020 KB |
Output is correct |
54 |
Correct |
327 ms |
6892 KB |
Output is correct |
55 |
Correct |
337 ms |
7020 KB |
Output is correct |
56 |
Correct |
332 ms |
7020 KB |
Output is correct |
57 |
Correct |
355 ms |
7224 KB |
Output is correct |
58 |
Correct |
354 ms |
7020 KB |
Output is correct |