Submission #1081594

# Submission time Handle Problem Language Result Execution time Memory
1081594 2024-08-30T07:55:13 Z juicy Tenis (COI19_tenis) C++17
100 / 100
90 ms 7248 KB
#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
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 484 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 484 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 484 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 484 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 484 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 40 ms 5712 KB Output is correct
14 Correct 35 ms 5712 KB Output is correct
15 Correct 32 ms 5712 KB Output is correct
16 Correct 32 ms 5716 KB Output is correct
17 Correct 36 ms 5696 KB Output is correct
18 Correct 36 ms 5588 KB Output is correct
19 Correct 33 ms 5576 KB Output is correct
20 Correct 34 ms 5716 KB Output is correct
21 Correct 36 ms 5724 KB Output is correct
22 Correct 32 ms 5720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 6856 KB Output is correct
2 Correct 52 ms 6620 KB Output is correct
3 Correct 45 ms 6716 KB Output is correct
4 Correct 54 ms 6740 KB Output is correct
5 Correct 46 ms 6736 KB Output is correct
6 Correct 48 ms 6740 KB Output is correct
7 Correct 44 ms 6608 KB Output is correct
8 Correct 46 ms 6796 KB Output is correct
9 Correct 58 ms 6636 KB Output is correct
10 Correct 48 ms 6716 KB Output is correct
11 Correct 44 ms 6632 KB Output is correct
12 Correct 47 ms 6604 KB Output is correct
13 Correct 48 ms 6972 KB Output is correct
14 Correct 53 ms 6744 KB Output is correct
15 Correct 44 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 484 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 484 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 40 ms 5712 KB Output is correct
14 Correct 35 ms 5712 KB Output is correct
15 Correct 32 ms 5712 KB Output is correct
16 Correct 32 ms 5716 KB Output is correct
17 Correct 36 ms 5696 KB Output is correct
18 Correct 36 ms 5588 KB Output is correct
19 Correct 33 ms 5576 KB Output is correct
20 Correct 34 ms 5716 KB Output is correct
21 Correct 36 ms 5724 KB Output is correct
22 Correct 32 ms 5720 KB Output is correct
23 Correct 47 ms 6856 KB Output is correct
24 Correct 52 ms 6620 KB Output is correct
25 Correct 45 ms 6716 KB Output is correct
26 Correct 54 ms 6740 KB Output is correct
27 Correct 46 ms 6736 KB Output is correct
28 Correct 48 ms 6740 KB Output is correct
29 Correct 44 ms 6608 KB Output is correct
30 Correct 46 ms 6796 KB Output is correct
31 Correct 58 ms 6636 KB Output is correct
32 Correct 48 ms 6716 KB Output is correct
33 Correct 44 ms 6632 KB Output is correct
34 Correct 47 ms 6604 KB Output is correct
35 Correct 48 ms 6972 KB Output is correct
36 Correct 53 ms 6744 KB Output is correct
37 Correct 44 ms 6740 KB Output is correct
38 Correct 81 ms 6996 KB Output is correct
39 Correct 58 ms 6736 KB Output is correct
40 Correct 90 ms 7248 KB Output is correct
41 Correct 59 ms 6844 KB Output is correct
42 Correct 62 ms 6856 KB Output is correct
43 Correct 81 ms 6992 KB Output is correct
44 Correct 52 ms 6740 KB Output is correct
45 Correct 59 ms 6812 KB Output is correct
46 Correct 53 ms 6704 KB Output is correct
47 Correct 66 ms 6856 KB Output is correct
48 Correct 55 ms 6740 KB Output is correct
49 Correct 62 ms 6992 KB Output is correct
50 Correct 53 ms 6748 KB Output is correct
51 Correct 64 ms 6996 KB Output is correct
52 Correct 84 ms 6996 KB Output is correct
53 Correct 57 ms 6864 KB Output is correct
54 Correct 58 ms 6992 KB Output is correct
55 Correct 62 ms 6996 KB Output is correct
56 Correct 62 ms 6976 KB Output is correct
57 Correct 54 ms 6916 KB Output is correct
58 Correct 67 ms 6992 KB Output is correct