답안 #526377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526377 2022-02-14T13:57:23 Z Alex_tz307 Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
3563 ms 101020 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
#define INF 0x3f3f3f3f

using namespace std;

struct ST {
  int n;
  vector<int> t, lazy;

  ST(int N) : n(N) {
    int dim = 1;
    while (dim < n) {
      dim *= 2;
    }
    dim *= 2;
    t.resize(dim, -INF);
    lazy.resize(dim);
  }

  void updateNode(int x, int v) {
    t[x] += v;
    lazy[x] += v;
  }

  void push(int x) {
    if (lazy[x] == 0) {
      return;
    }
    for (int i = 0; i < 2; ++i) {
      updateNode(x * 2 + i, lazy[x]);
    }
    lazy[x] = 0;
  }

  void update(int x, int lx, int rx, int st, int dr, int v) {
    if (st <= lx && rx <= dr) {
      updateNode(x, v);
      return;
    }
    push(x);
    int mid = (lx + rx) / 2;
    if (st <= mid) {
      update(x * 2, lx, mid, st, dr, v);
    }
    if (mid < dr) {
      update(x * 2 + 1, mid + 1, rx, st, dr, v);
    }
    t[x] = max(t[x * 2], t[x * 2 + 1]);
  }

  void update(int st, int dr, int v) {
    if (dr < st) {
      return;
    }
    update(1, 0, n - 1, st, dr, v);
  }

  int getMax() {
    return t[1];
  }
};

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
  int n = a.size(), q = x.size();
  vector<pair<int, int>> pairs;
  pairs.reserve(n + q);
  for (int i = 0; i < n; ++i) {
    pairs.emplace_back(a[i], i);
  }
  for (int i = 0; i < q; ++i) {
    pairs.emplace_back(v[i], x[i]);
  }
  sort(pairs.begin(), pairs.end());
  map<pair<int, int>, int> order;
  order[pairs[0]] = 0;
  int N = 0;
  for (int i = 1; i < (int)pairs.size(); ++i) {
    if (pairs[i] != pairs[i - 1]) {
      N += 1;
    }
    order[pairs[i]] = N;
  }
  N += 1;
  ST t(N);
  auto update = [&](const int &index, const int &pos, const int &sgn) -> void {
    t.update(index, index, sgn * (INF + pos));
    t.update(index + 1, N - 1, -sgn);
  };
  for (int i = 0; i < n; ++i) {
    update(order[{a[i], i}], i, 1);
  }
  vector<int> sol(q);
  for (int i = 0; i < q; ++i) {
    update(order[{a[x[i]], x[i]}], x[i], -1);
    a[x[i]] = v[i];
    update(order[{a[x[i]], x[i]}], x[i], 1);
    sol[i] = t.getMax();
  }
  return sol;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 5 ms 588 KB Output is correct
5 Correct 5 ms 692 KB Output is correct
6 Correct 4 ms 684 KB Output is correct
7 Correct 5 ms 588 KB Output is correct
8 Correct 6 ms 588 KB Output is correct
9 Correct 6 ms 588 KB Output is correct
10 Correct 4 ms 588 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 5 ms 588 KB Output is correct
15 Correct 4 ms 644 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 5 ms 588 KB Output is correct
5 Correct 5 ms 692 KB Output is correct
6 Correct 4 ms 684 KB Output is correct
7 Correct 5 ms 588 KB Output is correct
8 Correct 6 ms 588 KB Output is correct
9 Correct 6 ms 588 KB Output is correct
10 Correct 4 ms 588 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 5 ms 588 KB Output is correct
15 Correct 4 ms 644 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 17 ms 1740 KB Output is correct
20 Correct 25 ms 1868 KB Output is correct
21 Correct 21 ms 1868 KB Output is correct
22 Correct 20 ms 1876 KB Output is correct
23 Correct 18 ms 1760 KB Output is correct
24 Correct 20 ms 1740 KB Output is correct
25 Correct 20 ms 1684 KB Output is correct
26 Correct 17 ms 1612 KB Output is correct
27 Correct 17 ms 1632 KB Output is correct
28 Correct 17 ms 1612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 3152 KB Output is correct
2 Correct 90 ms 6516 KB Output is correct
3 Correct 179 ms 10612 KB Output is correct
4 Correct 187 ms 10732 KB Output is correct
5 Correct 177 ms 10560 KB Output is correct
6 Correct 171 ms 10484 KB Output is correct
7 Correct 175 ms 10548 KB Output is correct
8 Correct 178 ms 10484 KB Output is correct
9 Correct 172 ms 10576 KB Output is correct
10 Correct 116 ms 6788 KB Output is correct
11 Correct 121 ms 6896 KB Output is correct
12 Correct 117 ms 6864 KB Output is correct
13 Correct 114 ms 6852 KB Output is correct
14 Correct 111 ms 6864 KB Output is correct
15 Correct 113 ms 6884 KB Output is correct
16 Correct 102 ms 6824 KB Output is correct
17 Correct 104 ms 6828 KB Output is correct
18 Correct 106 ms 6988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 5 ms 588 KB Output is correct
5 Correct 5 ms 692 KB Output is correct
6 Correct 4 ms 684 KB Output is correct
7 Correct 5 ms 588 KB Output is correct
8 Correct 6 ms 588 KB Output is correct
9 Correct 6 ms 588 KB Output is correct
10 Correct 4 ms 588 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 5 ms 588 KB Output is correct
15 Correct 4 ms 644 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 17 ms 1740 KB Output is correct
20 Correct 25 ms 1868 KB Output is correct
21 Correct 21 ms 1868 KB Output is correct
22 Correct 20 ms 1876 KB Output is correct
23 Correct 18 ms 1760 KB Output is correct
24 Correct 20 ms 1740 KB Output is correct
25 Correct 20 ms 1684 KB Output is correct
26 Correct 17 ms 1612 KB Output is correct
27 Correct 17 ms 1632 KB Output is correct
28 Correct 17 ms 1612 KB Output is correct
29 Correct 29 ms 3152 KB Output is correct
30 Correct 90 ms 6516 KB Output is correct
31 Correct 179 ms 10612 KB Output is correct
32 Correct 187 ms 10732 KB Output is correct
33 Correct 177 ms 10560 KB Output is correct
34 Correct 171 ms 10484 KB Output is correct
35 Correct 175 ms 10548 KB Output is correct
36 Correct 178 ms 10484 KB Output is correct
37 Correct 172 ms 10576 KB Output is correct
38 Correct 116 ms 6788 KB Output is correct
39 Correct 121 ms 6896 KB Output is correct
40 Correct 117 ms 6864 KB Output is correct
41 Correct 114 ms 6852 KB Output is correct
42 Correct 111 ms 6864 KB Output is correct
43 Correct 113 ms 6884 KB Output is correct
44 Correct 102 ms 6824 KB Output is correct
45 Correct 104 ms 6828 KB Output is correct
46 Correct 106 ms 6988 KB Output is correct
47 Correct 832 ms 33476 KB Output is correct
48 Correct 3327 ms 93832 KB Output is correct
49 Correct 3563 ms 100936 KB Output is correct
50 Correct 3540 ms 101020 KB Output is correct
51 Correct 3546 ms 100892 KB Output is correct
52 Correct 3523 ms 100840 KB Output is correct
53 Correct 3534 ms 100880 KB Output is correct
54 Correct 3207 ms 100880 KB Output is correct
55 Correct 3512 ms 100840 KB Output is correct
56 Correct 3188 ms 100800 KB Output is correct
57 Correct 3342 ms 100828 KB Output is correct
58 Correct 3132 ms 100832 KB Output is correct
59 Correct 2721 ms 93204 KB Output is correct
60 Correct 2738 ms 93044 KB Output is correct
61 Correct 2732 ms 93004 KB Output is correct
62 Correct 2504 ms 89160 KB Output is correct
63 Correct 2491 ms 89012 KB Output is correct
64 Correct 2542 ms 89104 KB Output is correct
65 Correct 2279 ms 85304 KB Output is correct
66 Correct 2309 ms 85224 KB Output is correct
67 Correct 2323 ms 85176 KB Output is correct