#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+7;
const ll LOGN = 30;
const ll MAXN = 1e5 + 100;
const ll MULT = 1e9;
int rankV[3][MAXN];
int sg[4*MAXN], lazy[4*MAXN];
void init(int k, int a, int b) {
if (a == b) {
sg[k] = a;
return ;
}
init(2*k, a, (a+b)/2);
init(2*k+1, (a+b)/2+1, b);
sg[k] = min(sg[2*k], sg[2*k+1]);
}
void push(int k, int a, int b) {
sg[k] += lazy[k];
if (a != b) {
lazy[2*k] += lazy[k];
lazy[2*k+1] += lazy[k];
}
lazy[k] = 0;
}
void update(int k, int a, int b, int q_l, int q_r, int val) {
push(k, a, b);
if (q_r < a || q_l > b)
return ;
if (q_l <= a && b <= q_r) {
lazy[k] += val;
push(k, a, b);
return ;
}
update(2*k, a, (a+b)/2, q_l, q_r, val);
update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
sg[k] = min(sg[2*k], sg[2*k+1]);
}
int query(int k, int a, int b) {
push(k, a, b);
if (a == b) {
return a;
}
if (sg[2*k] == 0)
return query(2*k, a, a+b/2);
return query(2*k+1, (a+b)/2+1, b);
}
int maxi(int x, int y, int z) {
return max(x, max(y, z));
}
int main() {
fast
int N, Q;
cin >> N >> Q;
for (int i = 1; i <= N; i++) {
int x; cin >> x;
rankV[0][x] = i;
}
for (int i = 1; i <= N; i++) {
int x; cin >> x;
rankV[1][x] = i;
}
for (int i = 1; i <= N; i++) {
int x; cin >> x;
rankV[2][x] = i;
}
init(1, 1, N);
for (int i = 1; i <= N; i++)
update(1, 1, N, maxi(rankV[0][i], rankV[1][i], rankV[2][i]), N, -1);
while (Q--) {
int type;
cin >> type;
if (type == 1) {
int x; cin >> x;
if (maxi(rankV[0][x], rankV[1][x], rankV[2][x]) <= query(1, 1, N))
cout << "DA\n";
else
cout << "NE\n";
} else {
int p, a, b; cin >> p >> a >> b;
update(1, 1, N, maxi(rankV[0][a], rankV[1][a], rankV[2][a]), N, 1);
update(1, 1, N, maxi(rankV[0][b], rankV[1][b], rankV[2][b]), N, 1);
swap(rankV[p-1][a], rankV[p-1][b]);
update(1, 1, N, maxi(rankV[0][a], rankV[1][a], rankV[2][a]), N, -1);
update(1, 1, N, maxi(rankV[0][b], rankV[1][b], rankV[2][b]), N, -1);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
8796 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
8796 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
8796 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
59 ms |
7440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
8796 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |