#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
const int mod = 1e9 + 7; //998244353;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int logo = 20;
const int MAXN = 1e6 + 7;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int ps[5][MAXN], n, q;
ii merge(ii a, ii b){
if(a.X <= b.X) return a;
return b;
}
struct tournament{
ii seg[trsz];
int p[trsz];
tournament(){
for(int i=off; i<trsz; i++) seg[i].Y = i - off;
for(int i=off-1; i>=0; i--) seg[i] = merge(seg[i * 2], seg[i * 2 + 1]);
}
void prop(int x){
if(p[x] == 0) return;
seg[x].X += p[x];
if(x < off) p[x * 2] += p[x], p[x * 2 + 1] += p[x];
p[x] = 0;
}
void update(int x, int lo, int hi, int a, int b, int vl){
prop(x);
if(lo >= b or hi <= a) return;
if(lo >= a and hi <= b){
p[x] = vl;
prop(x);
return;
}
int mid = (lo + hi) / 2;
update(x * 2, lo, mid, a, b, vl);
update(x * 2 + 1, mid, hi, a, b, vl);
seg[x] = merge(seg[x * 2], seg[x * 2 + 1]);
}
void upd(int l, int r, int vl){
update(1, 0, off, l, r, vl);
}
}t;
int getv(int x){
int rt = 0;
for(int i=1; i<=3; i++) rt = max(rt, ps[i][x]);
return rt;
}
void ad(int x, int vl){
int a = getv(x);
t.upd(a, n + 1, vl);
}
void solve(){
cin >> n >> q;
for(int j=1; j<=3; j++){
for(int i=1; i<=n; i++){
int x;
cin >> x;
ps[j][x] = i;
}
}
t.upd(0, 1, 1);
for(int i=1; i<=n; i++) t.upd(i, n + 1, 1);
for(int i=1; i<=n; i++) ad(i, -1);
while(q--){
int ty, x, y, z;
cin >> ty >> x;
if(ty == 2){
cin >> y >> z;
ad(y, 1);
ad(z, 1);
swap(ps[x][y], ps[x][z]);
ad(y, -1);
ad(z, -1);
continue;
}
if(t.seg[1].Y < getv(x)) cout << "NE\n";
else cout << "DA\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while(tt--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
25180 KB |
Output is correct |
2 |
Correct |
5 ms |
25180 KB |
Output is correct |
3 |
Correct |
5 ms |
25180 KB |
Output is correct |
4 |
Correct |
5 ms |
25180 KB |
Output is correct |
5 |
Correct |
5 ms |
25188 KB |
Output is correct |
6 |
Correct |
5 ms |
25176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
25180 KB |
Output is correct |
2 |
Correct |
5 ms |
25180 KB |
Output is correct |
3 |
Correct |
5 ms |
25180 KB |
Output is correct |
4 |
Correct |
5 ms |
25180 KB |
Output is correct |
5 |
Correct |
5 ms |
25188 KB |
Output is correct |
6 |
Correct |
5 ms |
25176 KB |
Output is correct |
7 |
Correct |
5 ms |
25180 KB |
Output is correct |
8 |
Correct |
6 ms |
25180 KB |
Output is correct |
9 |
Correct |
6 ms |
25180 KB |
Output is correct |
10 |
Correct |
7 ms |
25260 KB |
Output is correct |
11 |
Correct |
5 ms |
25180 KB |
Output is correct |
12 |
Correct |
5 ms |
25176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
25180 KB |
Output is correct |
2 |
Correct |
5 ms |
25180 KB |
Output is correct |
3 |
Correct |
5 ms |
25180 KB |
Output is correct |
4 |
Correct |
5 ms |
25180 KB |
Output is correct |
5 |
Correct |
5 ms |
25188 KB |
Output is correct |
6 |
Correct |
5 ms |
25176 KB |
Output is correct |
7 |
Correct |
5 ms |
25180 KB |
Output is correct |
8 |
Correct |
6 ms |
25180 KB |
Output is correct |
9 |
Correct |
6 ms |
25180 KB |
Output is correct |
10 |
Correct |
7 ms |
25260 KB |
Output is correct |
11 |
Correct |
5 ms |
25180 KB |
Output is correct |
12 |
Correct |
5 ms |
25176 KB |
Output is correct |
13 |
Correct |
97 ms |
31388 KB |
Output is correct |
14 |
Correct |
94 ms |
31644 KB |
Output is correct |
15 |
Correct |
94 ms |
29868 KB |
Output is correct |
16 |
Correct |
99 ms |
29776 KB |
Output is correct |
17 |
Correct |
93 ms |
29776 KB |
Output is correct |
18 |
Correct |
97 ms |
31584 KB |
Output is correct |
19 |
Correct |
92 ms |
29776 KB |
Output is correct |
20 |
Correct |
96 ms |
29776 KB |
Output is correct |
21 |
Correct |
95 ms |
31572 KB |
Output is correct |
22 |
Correct |
93 ms |
29804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
30736 KB |
Output is correct |
2 |
Correct |
115 ms |
30784 KB |
Output is correct |
3 |
Correct |
105 ms |
30804 KB |
Output is correct |
4 |
Correct |
104 ms |
30804 KB |
Output is correct |
5 |
Correct |
106 ms |
32592 KB |
Output is correct |
6 |
Correct |
109 ms |
30748 KB |
Output is correct |
7 |
Correct |
104 ms |
30804 KB |
Output is correct |
8 |
Correct |
112 ms |
30756 KB |
Output is correct |
9 |
Correct |
104 ms |
30800 KB |
Output is correct |
10 |
Correct |
102 ms |
32528 KB |
Output is correct |
11 |
Correct |
105 ms |
32592 KB |
Output is correct |
12 |
Correct |
104 ms |
30804 KB |
Output is correct |
13 |
Correct |
105 ms |
30684 KB |
Output is correct |
14 |
Correct |
95 ms |
32576 KB |
Output is correct |
15 |
Correct |
104 ms |
32592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
25180 KB |
Output is correct |
2 |
Correct |
5 ms |
25180 KB |
Output is correct |
3 |
Correct |
5 ms |
25180 KB |
Output is correct |
4 |
Correct |
5 ms |
25180 KB |
Output is correct |
5 |
Correct |
5 ms |
25188 KB |
Output is correct |
6 |
Correct |
5 ms |
25176 KB |
Output is correct |
7 |
Correct |
5 ms |
25180 KB |
Output is correct |
8 |
Correct |
6 ms |
25180 KB |
Output is correct |
9 |
Correct |
6 ms |
25180 KB |
Output is correct |
10 |
Correct |
7 ms |
25260 KB |
Output is correct |
11 |
Correct |
5 ms |
25180 KB |
Output is correct |
12 |
Correct |
5 ms |
25176 KB |
Output is correct |
13 |
Correct |
97 ms |
31388 KB |
Output is correct |
14 |
Correct |
94 ms |
31644 KB |
Output is correct |
15 |
Correct |
94 ms |
29868 KB |
Output is correct |
16 |
Correct |
99 ms |
29776 KB |
Output is correct |
17 |
Correct |
93 ms |
29776 KB |
Output is correct |
18 |
Correct |
97 ms |
31584 KB |
Output is correct |
19 |
Correct |
92 ms |
29776 KB |
Output is correct |
20 |
Correct |
96 ms |
29776 KB |
Output is correct |
21 |
Correct |
95 ms |
31572 KB |
Output is correct |
22 |
Correct |
93 ms |
29804 KB |
Output is correct |
23 |
Correct |
117 ms |
30736 KB |
Output is correct |
24 |
Correct |
115 ms |
30784 KB |
Output is correct |
25 |
Correct |
105 ms |
30804 KB |
Output is correct |
26 |
Correct |
104 ms |
30804 KB |
Output is correct |
27 |
Correct |
106 ms |
32592 KB |
Output is correct |
28 |
Correct |
109 ms |
30748 KB |
Output is correct |
29 |
Correct |
104 ms |
30804 KB |
Output is correct |
30 |
Correct |
112 ms |
30756 KB |
Output is correct |
31 |
Correct |
104 ms |
30800 KB |
Output is correct |
32 |
Correct |
102 ms |
32528 KB |
Output is correct |
33 |
Correct |
105 ms |
32592 KB |
Output is correct |
34 |
Correct |
104 ms |
30804 KB |
Output is correct |
35 |
Correct |
105 ms |
30684 KB |
Output is correct |
36 |
Correct |
95 ms |
32576 KB |
Output is correct |
37 |
Correct |
104 ms |
32592 KB |
Output is correct |
38 |
Correct |
216 ms |
31060 KB |
Output is correct |
39 |
Correct |
134 ms |
32548 KB |
Output is correct |
40 |
Correct |
239 ms |
30956 KB |
Output is correct |
41 |
Correct |
154 ms |
32836 KB |
Output is correct |
42 |
Correct |
194 ms |
30948 KB |
Output is correct |
43 |
Correct |
219 ms |
31004 KB |
Output is correct |
44 |
Correct |
137 ms |
30744 KB |
Output is correct |
45 |
Correct |
184 ms |
32852 KB |
Output is correct |
46 |
Correct |
141 ms |
32772 KB |
Output is correct |
47 |
Correct |
159 ms |
32592 KB |
Output is correct |
48 |
Correct |
138 ms |
30804 KB |
Output is correct |
49 |
Correct |
170 ms |
31004 KB |
Output is correct |
50 |
Correct |
140 ms |
30784 KB |
Output is correct |
51 |
Correct |
182 ms |
30804 KB |
Output is correct |
52 |
Correct |
216 ms |
31192 KB |
Output is correct |
53 |
Correct |
132 ms |
31004 KB |
Output is correct |
54 |
Correct |
129 ms |
32672 KB |
Output is correct |
55 |
Correct |
161 ms |
32852 KB |
Output is correct |
56 |
Correct |
141 ms |
32852 KB |
Output is correct |
57 |
Correct |
133 ms |
32592 KB |
Output is correct |
58 |
Correct |
160 ms |
32800 KB |
Output is correct |