#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
using namespace std;
typedef int ll;
ll n,q,a[100009][3],x,y,t,o,u;
ll p[400009],lz[400009];
void push(ll d,ll l,ll r)
{
p[d]+=lz[d];
if(l<r)
{
lz[d*2]+=lz[d];
lz[d*2+1]+=lz[d];
}
lz[d]=0;
}
void up(ll d,ll l,ll r,ll z)
{
push(d,l,r);
if(r<x||l>y)
return;
if(x<=l&&y>=r)
{
lz[d]+=z;
push(d,l,r);
return;
}
ll m=(l+r)/2,i=d*2;
up(i,l,m,z),up(i+1,m+1,r,z);
p[d]=min(p[i],p[i+1]);
}
ll best(ll d,ll l,ll r)
{
if(l>y)
return 1e9;
push(d,l,r);
if(r<=y)
return p[d];
ll m=(l+r)/2,i=d*2;
return min(best(i,l,m),best(i+1,m+1,r));
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
scanf("%d%d",&n,&q);
for(ll j=0; j<3; j++)
for(ll i=1; i<=n; i++)
{
scanf("%d",&x);
a[x][j]=i;
}
for(ll i=1; i<=n; i++)
{
x=min(a[i][0],min(a[i][1],a[i][2]));
y=max(a[i][0],max(a[i][1],a[i][2]))-1;
up(1,1,n,1);
}
while(q--)
{
scanf("%d",&t);
if(t==1)
{
scanf("%d",&x);
y=min(a[x][0],min(a[x][1],a[x][2]))-1;
if(best(1,1,n))
printf("DA\n");
else
printf("NE\n");
continue;
}
scanf("%d%d%d",&t,&o,&u),t--;
x=min(a[o][0],min(a[o][1],a[o][2]));
y=max(a[o][0],max(a[o][1],a[o][2]))-1;
up(1,1,n,-1);
x=min(a[u][0],min(a[u][1],a[u][2]));
y=max(a[u][0],max(a[u][1],a[u][2]))-1;
up(1,1,n,-1);
swap(a[o][t],a[u][t]);
x=min(a[o][0],min(a[o][1],a[o][2]));
y=max(a[o][0],max(a[o][1],a[o][2]))-1;
up(1,1,n,1);
x=min(a[u][0],min(a[u][1],a[u][2]));
y=max(a[u][0],max(a[u][1],a[u][2]))-1;
up(1,1,n,1);
}
return 0;
}
Compilation message
tenis.cpp: In function 'int main()':
tenis.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d",&n,&q);
| ~~~~~^~~~~~~~~~~~~~
tenis.cpp:51:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d",&x);
| ~~~~~^~~~~~~~~
tenis.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d",&t);
| ~~~~~^~~~~~~~~
tenis.cpp:65:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%d",&x);
| ~~~~~^~~~~~~~~
tenis.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | scanf("%d%d%d",&t,&o,&u),t--;
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
125 ms |
5168 KB |
Output is correct |
14 |
Correct |
121 ms |
5184 KB |
Output is correct |
15 |
Correct |
90 ms |
5304 KB |
Output is correct |
16 |
Correct |
91 ms |
5240 KB |
Output is correct |
17 |
Correct |
84 ms |
5252 KB |
Output is correct |
18 |
Correct |
89 ms |
5188 KB |
Output is correct |
19 |
Correct |
87 ms |
5232 KB |
Output is correct |
20 |
Correct |
95 ms |
5184 KB |
Output is correct |
21 |
Correct |
88 ms |
5176 KB |
Output is correct |
22 |
Correct |
95 ms |
5256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
6204 KB |
Output is correct |
2 |
Correct |
150 ms |
6208 KB |
Output is correct |
3 |
Correct |
153 ms |
6320 KB |
Output is correct |
4 |
Correct |
153 ms |
6256 KB |
Output is correct |
5 |
Correct |
149 ms |
6208 KB |
Output is correct |
6 |
Correct |
152 ms |
6340 KB |
Output is correct |
7 |
Correct |
152 ms |
6212 KB |
Output is correct |
8 |
Correct |
169 ms |
6340 KB |
Output is correct |
9 |
Correct |
160 ms |
6208 KB |
Output is correct |
10 |
Correct |
153 ms |
6212 KB |
Output is correct |
11 |
Correct |
148 ms |
6208 KB |
Output is correct |
12 |
Correct |
152 ms |
6208 KB |
Output is correct |
13 |
Correct |
179 ms |
6212 KB |
Output is correct |
14 |
Correct |
156 ms |
6268 KB |
Output is correct |
15 |
Correct |
162 ms |
6212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
125 ms |
5168 KB |
Output is correct |
14 |
Correct |
121 ms |
5184 KB |
Output is correct |
15 |
Correct |
90 ms |
5304 KB |
Output is correct |
16 |
Correct |
91 ms |
5240 KB |
Output is correct |
17 |
Correct |
84 ms |
5252 KB |
Output is correct |
18 |
Correct |
89 ms |
5188 KB |
Output is correct |
19 |
Correct |
87 ms |
5232 KB |
Output is correct |
20 |
Correct |
95 ms |
5184 KB |
Output is correct |
21 |
Correct |
88 ms |
5176 KB |
Output is correct |
22 |
Correct |
95 ms |
5256 KB |
Output is correct |
23 |
Correct |
196 ms |
6204 KB |
Output is correct |
24 |
Correct |
150 ms |
6208 KB |
Output is correct |
25 |
Correct |
153 ms |
6320 KB |
Output is correct |
26 |
Correct |
153 ms |
6256 KB |
Output is correct |
27 |
Correct |
149 ms |
6208 KB |
Output is correct |
28 |
Correct |
152 ms |
6340 KB |
Output is correct |
29 |
Correct |
152 ms |
6212 KB |
Output is correct |
30 |
Correct |
169 ms |
6340 KB |
Output is correct |
31 |
Correct |
160 ms |
6208 KB |
Output is correct |
32 |
Correct |
153 ms |
6212 KB |
Output is correct |
33 |
Correct |
148 ms |
6208 KB |
Output is correct |
34 |
Correct |
152 ms |
6208 KB |
Output is correct |
35 |
Correct |
179 ms |
6212 KB |
Output is correct |
36 |
Correct |
156 ms |
6268 KB |
Output is correct |
37 |
Correct |
162 ms |
6212 KB |
Output is correct |
38 |
Correct |
300 ms |
6580 KB |
Output is correct |
39 |
Correct |
181 ms |
6340 KB |
Output is correct |
40 |
Correct |
313 ms |
6680 KB |
Output is correct |
41 |
Correct |
201 ms |
6456 KB |
Output is correct |
42 |
Correct |
213 ms |
6476 KB |
Output is correct |
43 |
Correct |
333 ms |
6640 KB |
Output is correct |
44 |
Correct |
181 ms |
6528 KB |
Output is correct |
45 |
Correct |
234 ms |
6484 KB |
Output is correct |
46 |
Correct |
222 ms |
6528 KB |
Output is correct |
47 |
Correct |
196 ms |
6368 KB |
Output is correct |
48 |
Correct |
194 ms |
6328 KB |
Output is correct |
49 |
Correct |
205 ms |
6468 KB |
Output is correct |
50 |
Correct |
187 ms |
6456 KB |
Output is correct |
51 |
Correct |
212 ms |
6412 KB |
Output is correct |
52 |
Correct |
291 ms |
6728 KB |
Output is correct |
53 |
Correct |
189 ms |
6376 KB |
Output is correct |
54 |
Correct |
216 ms |
6456 KB |
Output is correct |
55 |
Correct |
213 ms |
6400 KB |
Output is correct |
56 |
Correct |
212 ms |
6468 KB |
Output is correct |
57 |
Correct |
203 ms |
6460 KB |
Output is correct |
58 |
Correct |
244 ms |
6472 KB |
Output is correct |