이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5;
int n, q;
int s[4 * N], lz[4 * N], cur[N];
array<int, 3> pos[N];
void bld(int id = 1, int l = 0, int r = n - 1) {
  if (l == r) {
    s[id] = l + 1;
    return;
  }
  int m = (l + r) / 2;
  bld(id * 2, l, m);
  bld(id * 2 + 1, m + 1, r);
  s[id] = min(s[id * 2], s[id * 2 + 1]);
}
void app(int id, int x) {
  s[id] += x;
  lz[id] += x;
}
void psh(int id) {
  if (lz[id]) {
    app(id * 2, lz[id]);
    app(id * 2 + 1, lz[id]);
    lz[id] = 0;
  }
}
void upd(int i, int x) {
  int id = 1, l = 0, r = n - 1;
  while (l ^ r) {
    int m = (l + r) / 2;
    psh(id);
    id *= 2;
    if (i <= m) {
      r = m;
      app(id + 1, x);
    } else {
      l = m + 1;
      id += 1;
    }
  }
  s[id] += x;
  while (id > 1) {
    id /= 2;
    s[id] = min(s[id * 2], s[id * 2 + 1]);
  }
}
int qry() {
  int id = 1, l = 0, r = n - 1;
  while (l ^ r) {
    int m = (l + r) / 2;
    psh(id);
    id *= 2;
    if (s[id] > 0) {
      l = m + 1;
      id += 1;
    } else {
      r = m;
    }
  }
  return l;
}
void tog(int u) {
  upd(cur[u], 1);
  cur[u] = *max_element(pos[u].begin(), pos[u].end());
  upd(cur[u], -1);
}
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin >> n >> q;
  for (int j = 0; j < 3; ++j) {
    for (int i = 0; i < n; ++i) {
      int x; cin >> x; --x;
      pos[x][j] = i;
    }
  }
  bld();
  for (int i = 0; i < n; ++i) {
    cur[i] = *max_element(pos[i].begin(), pos[i].end());
    upd(cur[i], -1);
  }
  while (q--) {
    int t; cin >> t;
    if (t == 1) {
      int x; cin >> x; --x;
      cout << (cur[x] <= qry() ? "DA" : "NE") << "\n"; 
    } else {
      int p, a, b; cin >> p >> a >> b; --p, --a, --b;
      swap(pos[a][p], pos[b][p]);
      tog(a);
      tog(b);
    }
  }
  return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |