#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e5;
const int P=1<<17;
int t[N+10][3];
int pot;
int tr[2*P+10];
int lazy[2*P+10];
void push_down(int x)
{
for(int i:{2*x,2*x+1})
{
tr[i]+=lazy[x];
lazy[i]+=lazy[x];
}
lazy[x]=0;
return;
}
void add(int x,int l,int r,int ls,int rs,int c)
{
if(ls>rs)
swap(ls,rs);
if(rs<=l || r<ls)
return;
if(ls<=l && r<rs)
{
tr[x]+=c;
lazy[x]+=c;
return;
}
push_down(x);
int mid=(l+r)/2;
add(2*x,l,mid,ls,rs,c);
add(2*x+1,mid+1,r,ls,rs,c);
tr[x]=min(tr[2*x],tr[2*x+1]);
return;
}
int cut(int x)
{
if(x>=pot)
return x-pot+1;
push_down(x);
if(tr[2*x]==0)
return cut(2*x);
return cut(2*x+1);
}
void add_person(int x,int c)
{
add(1,1,pot,t[x][0],t[x][1],c);
add(1,1,pot,t[x][0],t[x][2],c);
add(1,1,pot,t[x][1],t[x][2],c);
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,q;
cin>>n>>q;
for(int j=0;j<3;j++)
{
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
t[x][j]=i;
}
}
for(pot=1;pot<n;pot*=2);
for(int i=1;i<=n;i++)
add_person(i,1);
while(q--)
{
int ty;
cin>>ty;
if(ty==1)
{
int x;
cin>>x;
cout<<(t[x][0]<=cut(1) ? "DA":"NE")<<"\n";
}
else
{
int a,b,c;
cin>>c>>a>>b;
c--;
add_person(a,-1);
add_person(b,-1);
swap(t[a][c],t[b][c]);
add_person(a,1);
add_person(b,1);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
109 ms |
4800 KB |
Output is correct |
14 |
Correct |
124 ms |
4820 KB |
Output is correct |
15 |
Correct |
111 ms |
4804 KB |
Output is correct |
16 |
Correct |
116 ms |
4784 KB |
Output is correct |
17 |
Correct |
123 ms |
4796 KB |
Output is correct |
18 |
Correct |
103 ms |
4824 KB |
Output is correct |
19 |
Correct |
108 ms |
4664 KB |
Output is correct |
20 |
Correct |
112 ms |
4808 KB |
Output is correct |
21 |
Correct |
109 ms |
4796 KB |
Output is correct |
22 |
Correct |
112 ms |
4828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
166 ms |
5804 KB |
Output is correct |
2 |
Correct |
144 ms |
5772 KB |
Output is correct |
3 |
Correct |
138 ms |
5896 KB |
Output is correct |
4 |
Correct |
150 ms |
5832 KB |
Output is correct |
5 |
Correct |
159 ms |
5764 KB |
Output is correct |
6 |
Correct |
146 ms |
5824 KB |
Output is correct |
7 |
Correct |
137 ms |
5816 KB |
Output is correct |
8 |
Correct |
165 ms |
5836 KB |
Output is correct |
9 |
Correct |
136 ms |
5892 KB |
Output is correct |
10 |
Correct |
149 ms |
5800 KB |
Output is correct |
11 |
Correct |
152 ms |
5804 KB |
Output is correct |
12 |
Correct |
154 ms |
5948 KB |
Output is correct |
13 |
Correct |
142 ms |
5824 KB |
Output is correct |
14 |
Correct |
131 ms |
5836 KB |
Output is correct |
15 |
Correct |
141 ms |
5760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
109 ms |
4800 KB |
Output is correct |
14 |
Correct |
124 ms |
4820 KB |
Output is correct |
15 |
Correct |
111 ms |
4804 KB |
Output is correct |
16 |
Correct |
116 ms |
4784 KB |
Output is correct |
17 |
Correct |
123 ms |
4796 KB |
Output is correct |
18 |
Correct |
103 ms |
4824 KB |
Output is correct |
19 |
Correct |
108 ms |
4664 KB |
Output is correct |
20 |
Correct |
112 ms |
4808 KB |
Output is correct |
21 |
Correct |
109 ms |
4796 KB |
Output is correct |
22 |
Correct |
112 ms |
4828 KB |
Output is correct |
23 |
Correct |
166 ms |
5804 KB |
Output is correct |
24 |
Correct |
144 ms |
5772 KB |
Output is correct |
25 |
Correct |
138 ms |
5896 KB |
Output is correct |
26 |
Correct |
150 ms |
5832 KB |
Output is correct |
27 |
Correct |
159 ms |
5764 KB |
Output is correct |
28 |
Correct |
146 ms |
5824 KB |
Output is correct |
29 |
Correct |
137 ms |
5816 KB |
Output is correct |
30 |
Correct |
165 ms |
5836 KB |
Output is correct |
31 |
Correct |
136 ms |
5892 KB |
Output is correct |
32 |
Correct |
149 ms |
5800 KB |
Output is correct |
33 |
Correct |
152 ms |
5804 KB |
Output is correct |
34 |
Correct |
154 ms |
5948 KB |
Output is correct |
35 |
Correct |
142 ms |
5824 KB |
Output is correct |
36 |
Correct |
131 ms |
5836 KB |
Output is correct |
37 |
Correct |
141 ms |
5760 KB |
Output is correct |
38 |
Correct |
393 ms |
6092 KB |
Output is correct |
39 |
Correct |
241 ms |
5896 KB |
Output is correct |
40 |
Correct |
415 ms |
6212 KB |
Output is correct |
41 |
Correct |
249 ms |
5996 KB |
Output is correct |
42 |
Correct |
244 ms |
6020 KB |
Output is correct |
43 |
Correct |
432 ms |
6144 KB |
Output is correct |
44 |
Correct |
201 ms |
5900 KB |
Output is correct |
45 |
Correct |
268 ms |
6024 KB |
Output is correct |
46 |
Correct |
227 ms |
6124 KB |
Output is correct |
47 |
Correct |
232 ms |
6020 KB |
Output is correct |
48 |
Correct |
231 ms |
5940 KB |
Output is correct |
49 |
Correct |
242 ms |
6040 KB |
Output is correct |
50 |
Correct |
245 ms |
5944 KB |
Output is correct |
51 |
Correct |
308 ms |
6072 KB |
Output is correct |
52 |
Correct |
387 ms |
6204 KB |
Output is correct |
53 |
Correct |
223 ms |
6148 KB |
Output is correct |
54 |
Correct |
257 ms |
5996 KB |
Output is correct |
55 |
Correct |
276 ms |
6020 KB |
Output is correct |
56 |
Correct |
257 ms |
6004 KB |
Output is correct |
57 |
Correct |
205 ms |
5964 KB |
Output is correct |
58 |
Correct |
268 ms |
6000 KB |
Output is correct |