#include<iostream>
using namespace std;
using pii = pair<int, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define dforsn(i, s, n) for(int i=n-1; i>=(int)s; --i)
#define F first
#define S second
const int MAXN=200010, INF=1000000000;
int n, q, he, lazy[MAXN], inv[3][MAXN];
pii tr[2*MAXN];
void apply(int p, int value){
if(p<n) lazy[p]+=value;
tr[p].F+=value;
}
void build(int p){
while(p>1) p>>=1, tr[p]=min(tr[p<<1], tr[p<<1|1]), tr[p].F+=lazy[p];
}
void push(int p){
for(int s=he; s>0; --s){
int i=p>>s;
if(lazy[i]){
apply(i<<1, lazy[i]);
apply(i<<1|1, lazy[i]);
lazy[i]=0;
}
}
}
void inc(int l, int r, int value){
l+=n, r+=n;
int l0=l, r0=r;
for(; l<r; l>>=1, r>>=1){
if(l&1) apply(l++, value);
if(r&1) apply(--r, value);
}
build(l0);
build(r0-1);
}
pii query(int l, int r){
pii ret = {INF, INF};
l+=n, r+=n;
push(l);
push(r-1);
for(; l<r; l>>=1, r>>=1){
if(l&1) ret=min(tr[l++], ret);
if(r&1) ret=min(ret, tr[--r]);
}
return ret;
}
void sim_add(int l, int r, int value){
if(l>=r) swap(l, r);
inc(l, r, value);
}
int main(){
scanf("%d %d", &n, &q);
he = 8*sizeof(int) - __builtin_clz(n);
forn(i, n) tr[n+i].S=i;
dforsn(i, 1, n) tr[i]=min(tr[i<<1], tr[i<<1|1]);
forn(i, 3) forn(j, n){
int a; scanf("%d", &a), --a;
inv[i][a]=j;
}
forn(j, 2) forn(i, n) sim_add(inv[0][i], inv[j+1][i], 1);
forn(i, q){
int type; scanf("%d", &type);
if(type==1){
int x; scanf("%d", &x), --x;
int bnd = query(0, n).S;
printf(inv[0][x]<=bnd? "DA\n" : "NE\n");
}
else{
int p, a[2]; scanf("%d %d %d", &p, a, a+1), --p, --a[0], --a[1];
if(p==0){
forn(j, 2) forn(k, 2){
sim_add(inv[0][a[j]], inv[k+1][a[j]], -1);
sim_add(inv[0][a[j]], inv[k+1][a[j^1]], 1);
}
}
else{
forn(j, 2){
sim_add(inv[0][a[j]], inv[p][a[j]], -1);
sim_add(inv[0][a[j]], inv[p][a[j^1]], 1);
}
}
swap(inv[p][a[0]], inv[p][a[1]]);
}
}
}
Compilation message
tenis.cpp: In function 'int main()':
tenis.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~
tenis.cpp:67:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | int a; scanf("%d", &a), --a;
| ~~~~~^~~~~~~~~~
tenis.cpp:72:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | int type; scanf("%d", &type);
| ~~~~~^~~~~~~~~~~~~
tenis.cpp:74:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | int x; scanf("%d", &x), --x;
| ~~~~~^~~~~~~~~~
tenis.cpp:79:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | int p, a[2]; scanf("%d %d %d", &p, a, a+1), --p, --a[0], --a[1];
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 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 |
388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 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 |
388 KB |
Output is correct |
13 |
Correct |
77 ms |
3412 KB |
Output is correct |
14 |
Correct |
79 ms |
3420 KB |
Output is correct |
15 |
Correct |
79 ms |
3404 KB |
Output is correct |
16 |
Correct |
70 ms |
3412 KB |
Output is correct |
17 |
Correct |
54 ms |
3372 KB |
Output is correct |
18 |
Correct |
57 ms |
3276 KB |
Output is correct |
19 |
Correct |
62 ms |
5068 KB |
Output is correct |
20 |
Correct |
84 ms |
5052 KB |
Output is correct |
21 |
Correct |
55 ms |
5068 KB |
Output is correct |
22 |
Correct |
72 ms |
5140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
3676 KB |
Output is correct |
2 |
Correct |
96 ms |
3688 KB |
Output is correct |
3 |
Correct |
96 ms |
3680 KB |
Output is correct |
4 |
Correct |
82 ms |
3676 KB |
Output is correct |
5 |
Correct |
107 ms |
3668 KB |
Output is correct |
6 |
Correct |
90 ms |
3644 KB |
Output is correct |
7 |
Correct |
91 ms |
3660 KB |
Output is correct |
8 |
Correct |
78 ms |
3676 KB |
Output is correct |
9 |
Correct |
101 ms |
3680 KB |
Output is correct |
10 |
Correct |
91 ms |
3660 KB |
Output is correct |
11 |
Correct |
100 ms |
3672 KB |
Output is correct |
12 |
Correct |
93 ms |
3648 KB |
Output is correct |
13 |
Correct |
104 ms |
3692 KB |
Output is correct |
14 |
Correct |
98 ms |
3696 KB |
Output is correct |
15 |
Correct |
100 ms |
3680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 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 |
388 KB |
Output is correct |
13 |
Correct |
77 ms |
3412 KB |
Output is correct |
14 |
Correct |
79 ms |
3420 KB |
Output is correct |
15 |
Correct |
79 ms |
3404 KB |
Output is correct |
16 |
Correct |
70 ms |
3412 KB |
Output is correct |
17 |
Correct |
54 ms |
3372 KB |
Output is correct |
18 |
Correct |
57 ms |
3276 KB |
Output is correct |
19 |
Correct |
62 ms |
5068 KB |
Output is correct |
20 |
Correct |
84 ms |
5052 KB |
Output is correct |
21 |
Correct |
55 ms |
5068 KB |
Output is correct |
22 |
Correct |
72 ms |
5140 KB |
Output is correct |
23 |
Correct |
98 ms |
3676 KB |
Output is correct |
24 |
Correct |
96 ms |
3688 KB |
Output is correct |
25 |
Correct |
96 ms |
3680 KB |
Output is correct |
26 |
Correct |
82 ms |
3676 KB |
Output is correct |
27 |
Correct |
107 ms |
3668 KB |
Output is correct |
28 |
Correct |
90 ms |
3644 KB |
Output is correct |
29 |
Correct |
91 ms |
3660 KB |
Output is correct |
30 |
Correct |
78 ms |
3676 KB |
Output is correct |
31 |
Correct |
101 ms |
3680 KB |
Output is correct |
32 |
Correct |
91 ms |
3660 KB |
Output is correct |
33 |
Correct |
100 ms |
3672 KB |
Output is correct |
34 |
Correct |
93 ms |
3648 KB |
Output is correct |
35 |
Correct |
104 ms |
3692 KB |
Output is correct |
36 |
Correct |
98 ms |
3696 KB |
Output is correct |
37 |
Correct |
100 ms |
3680 KB |
Output is correct |
38 |
Correct |
227 ms |
6452 KB |
Output is correct |
39 |
Correct |
120 ms |
6204 KB |
Output is correct |
40 |
Correct |
227 ms |
6564 KB |
Output is correct |
41 |
Correct |
154 ms |
6312 KB |
Output is correct |
42 |
Correct |
139 ms |
6356 KB |
Output is correct |
43 |
Correct |
215 ms |
6592 KB |
Output is correct |
44 |
Correct |
115 ms |
6224 KB |
Output is correct |
45 |
Correct |
145 ms |
6340 KB |
Output is correct |
46 |
Correct |
120 ms |
6208 KB |
Output is correct |
47 |
Correct |
124 ms |
6344 KB |
Output is correct |
48 |
Correct |
134 ms |
6220 KB |
Output is correct |
49 |
Correct |
144 ms |
6388 KB |
Output is correct |
50 |
Correct |
117 ms |
6228 KB |
Output is correct |
51 |
Correct |
135 ms |
6352 KB |
Output is correct |
52 |
Correct |
216 ms |
6472 KB |
Output is correct |
53 |
Correct |
117 ms |
6372 KB |
Output is correct |
54 |
Correct |
126 ms |
6336 KB |
Output is correct |
55 |
Correct |
132 ms |
6444 KB |
Output is correct |
56 |
Correct |
125 ms |
6380 KB |
Output is correct |
57 |
Correct |
119 ms |
6216 KB |
Output is correct |
58 |
Correct |
178 ms |
6376 KB |
Output is correct |