답안 #253200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253200 2020-07-27T11:49:09 Z rama_pang Rabbit Carrot (LMIO19_triusis) C++14
100 / 100
789 ms 157048 KB
#include <bits/stdc++.h>
using namespace std;

using lint = long long;

struct Node {
  int val = 1e9;
  int lazy = 0;
  int lc = 0;
  int rc = 0;
  Node() {}
  Node(int val) : val(val) {}
} d[int(1e7)];

int NewNode() {
  static int ptd = 2;
  return ptd++;
}

void Apply(int &n, int x) {
  if (n == 0) n = NewNode();
  d[n].val += x;
  d[n].lazy += x;
}

void Push(int &n, int &lc, int &rc) {
  if (d[n].lazy > 0) {
    Apply(lc, d[n].lazy);
    Apply(rc, d[n].lazy);
    d[n].lazy = 0;
  }
}

void Pull(int n, int lc, int rc) {
  d[n].val = min(d[lc].val, d[rc].val);
}

void Update(int &n, lint tl, lint tr, lint p, int x) {
  if (n == 0) n = NewNode();
  if (tl == tr) {
    d[n].val = min(d[n].val, x);
    return;
  }
  lint md = (tl + tr) / 2;
  Push(n, d[n].lc, d[n].rc);
  if (p <= md) {
    Update(d[n].lc, tl, md, p, x);
  } else {
    Update(d[n].rc, md + 1, tr, p, x);
  }
  Pull(n, d[n].lc, d[n].rc);
}

int Query(int n, lint tl, lint tr, lint l, lint r) {
  if (n == 0 || r < tl || tr < l || tl > tr || l > r) return 1e9;
  if (l <= tl && tr <= r) return d[n].val;
  lint md = (tl + tr) / 2;
  Push(n, d[n].lc, d[n].rc);
  return min(Query(d[n].lc, tl, md, l, r), Query(d[n].rc, md + 1, tr, l, r));
}

void Add(int &n, lint tl, lint tr, lint l, lint r, int x) {
  if (r < tl || tr < l || tl > tr || l > r) return;
  if (n == 0) n = NewNode();
  if (l <= tl && tr <= r) return Apply(n, x);
  lint md = (tl + tr) / 2;
  Push(n, d[n].lc, d[n].rc);
  Add(d[n].lc, tl, md, l, r, x);
  Add(d[n].rc, md + 1, tr, l, r, x);
  Pull(n, d[n].lc, d[n].rc);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int N, M;
  cin >> N >> M;

  lint base = 1e11;
  lint inf = 1e12;
  int root = NewNode();
  Update(root, 0, inf, base, 0);

  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    auto v = Query(root, 0, inf, max(a - M, 0) + base, inf);
    base -= M;
    Add(root, 0, inf, base, inf, 1);
    Update(root, 0, inf, base + a, v);
  }
  
  cout << Query(root, 0, inf, base, inf) << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 156920 KB Output is correct
2 Correct 75 ms 156920 KB Output is correct
3 Correct 81 ms 156920 KB Output is correct
4 Correct 75 ms 156920 KB Output is correct
5 Correct 81 ms 156920 KB Output is correct
6 Correct 79 ms 156920 KB Output is correct
7 Correct 80 ms 156920 KB Output is correct
8 Correct 85 ms 156920 KB Output is correct
9 Correct 81 ms 156920 KB Output is correct
10 Correct 84 ms 156920 KB Output is correct
11 Correct 87 ms 156920 KB Output is correct
12 Correct 78 ms 156920 KB Output is correct
13 Correct 78 ms 156920 KB Output is correct
14 Correct 81 ms 156920 KB Output is correct
15 Correct 78 ms 156920 KB Output is correct
16 Correct 76 ms 156920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 156920 KB Output is correct
2 Correct 75 ms 156920 KB Output is correct
3 Correct 82 ms 156920 KB Output is correct
4 Correct 90 ms 156920 KB Output is correct
5 Correct 93 ms 156920 KB Output is correct
6 Correct 85 ms 156920 KB Output is correct
7 Correct 100 ms 157048 KB Output is correct
8 Correct 99 ms 156920 KB Output is correct
9 Correct 99 ms 156920 KB Output is correct
10 Correct 93 ms 157048 KB Output is correct
11 Correct 85 ms 156920 KB Output is correct
12 Correct 91 ms 156920 KB Output is correct
13 Correct 87 ms 157048 KB Output is correct
14 Correct 90 ms 156944 KB Output is correct
15 Correct 88 ms 156920 KB Output is correct
16 Correct 92 ms 156924 KB Output is correct
17 Correct 86 ms 156920 KB Output is correct
18 Correct 77 ms 156920 KB Output is correct
19 Correct 75 ms 156920 KB Output is correct
20 Correct 81 ms 156920 KB Output is correct
21 Correct 75 ms 156920 KB Output is correct
22 Correct 81 ms 156920 KB Output is correct
23 Correct 79 ms 156920 KB Output is correct
24 Correct 80 ms 156920 KB Output is correct
25 Correct 85 ms 156920 KB Output is correct
26 Correct 81 ms 156920 KB Output is correct
27 Correct 84 ms 156920 KB Output is correct
28 Correct 87 ms 156920 KB Output is correct
29 Correct 78 ms 156920 KB Output is correct
30 Correct 78 ms 156920 KB Output is correct
31 Correct 81 ms 156920 KB Output is correct
32 Correct 78 ms 156920 KB Output is correct
33 Correct 76 ms 156920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 156956 KB Output is correct
2 Correct 91 ms 156920 KB Output is correct
3 Correct 89 ms 156920 KB Output is correct
4 Correct 87 ms 156816 KB Output is correct
5 Correct 86 ms 156920 KB Output is correct
6 Correct 86 ms 156928 KB Output is correct
7 Correct 90 ms 156924 KB Output is correct
8 Correct 91 ms 156876 KB Output is correct
9 Correct 91 ms 156924 KB Output is correct
10 Correct 91 ms 156844 KB Output is correct
11 Correct 81 ms 156920 KB Output is correct
12 Correct 75 ms 156920 KB Output is correct
13 Correct 82 ms 156920 KB Output is correct
14 Correct 90 ms 156920 KB Output is correct
15 Correct 93 ms 156920 KB Output is correct
16 Correct 85 ms 156920 KB Output is correct
17 Correct 100 ms 157048 KB Output is correct
18 Correct 99 ms 156920 KB Output is correct
19 Correct 99 ms 156920 KB Output is correct
20 Correct 93 ms 157048 KB Output is correct
21 Correct 85 ms 156920 KB Output is correct
22 Correct 91 ms 156920 KB Output is correct
23 Correct 87 ms 157048 KB Output is correct
24 Correct 90 ms 156944 KB Output is correct
25 Correct 88 ms 156920 KB Output is correct
26 Correct 92 ms 156924 KB Output is correct
27 Correct 86 ms 156920 KB Output is correct
28 Correct 77 ms 156920 KB Output is correct
29 Correct 75 ms 156920 KB Output is correct
30 Correct 81 ms 156920 KB Output is correct
31 Correct 75 ms 156920 KB Output is correct
32 Correct 81 ms 156920 KB Output is correct
33 Correct 79 ms 156920 KB Output is correct
34 Correct 80 ms 156920 KB Output is correct
35 Correct 85 ms 156920 KB Output is correct
36 Correct 81 ms 156920 KB Output is correct
37 Correct 84 ms 156920 KB Output is correct
38 Correct 87 ms 156920 KB Output is correct
39 Correct 78 ms 156920 KB Output is correct
40 Correct 78 ms 156920 KB Output is correct
41 Correct 81 ms 156920 KB Output is correct
42 Correct 78 ms 156920 KB Output is correct
43 Correct 76 ms 156920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 156956 KB Output is correct
2 Correct 91 ms 156920 KB Output is correct
3 Correct 89 ms 156920 KB Output is correct
4 Correct 87 ms 156816 KB Output is correct
5 Correct 86 ms 156920 KB Output is correct
6 Correct 86 ms 156928 KB Output is correct
7 Correct 90 ms 156924 KB Output is correct
8 Correct 91 ms 156876 KB Output is correct
9 Correct 91 ms 156924 KB Output is correct
10 Correct 91 ms 156844 KB Output is correct
11 Correct 81 ms 156920 KB Output is correct
12 Correct 75 ms 156920 KB Output is correct
13 Correct 82 ms 156920 KB Output is correct
14 Correct 90 ms 156920 KB Output is correct
15 Correct 93 ms 156920 KB Output is correct
16 Correct 85 ms 156920 KB Output is correct
17 Correct 100 ms 157048 KB Output is correct
18 Correct 99 ms 156920 KB Output is correct
19 Correct 99 ms 156920 KB Output is correct
20 Correct 93 ms 157048 KB Output is correct
21 Correct 85 ms 156920 KB Output is correct
22 Correct 91 ms 156920 KB Output is correct
23 Correct 87 ms 157048 KB Output is correct
24 Correct 90 ms 156944 KB Output is correct
25 Correct 88 ms 156920 KB Output is correct
26 Correct 92 ms 156924 KB Output is correct
27 Correct 86 ms 156920 KB Output is correct
28 Correct 457 ms 156940 KB Output is correct
29 Correct 691 ms 156920 KB Output is correct
30 Correct 743 ms 156968 KB Output is correct
31 Correct 789 ms 156920 KB Output is correct
32 Correct 502 ms 156920 KB Output is correct
33 Correct 545 ms 157048 KB Output is correct
34 Correct 541 ms 157048 KB Output is correct
35 Correct 550 ms 157048 KB Output is correct
36 Correct 473 ms 157048 KB Output is correct
37 Correct 485 ms 157048 KB Output is correct
38 Correct 538 ms 157048 KB Output is correct
39 Correct 529 ms 156924 KB Output is correct
40 Correct 77 ms 156920 KB Output is correct
41 Correct 75 ms 156920 KB Output is correct
42 Correct 81 ms 156920 KB Output is correct
43 Correct 75 ms 156920 KB Output is correct
44 Correct 81 ms 156920 KB Output is correct
45 Correct 79 ms 156920 KB Output is correct
46 Correct 80 ms 156920 KB Output is correct
47 Correct 85 ms 156920 KB Output is correct
48 Correct 81 ms 156920 KB Output is correct
49 Correct 84 ms 156920 KB Output is correct
50 Correct 87 ms 156920 KB Output is correct
51 Correct 78 ms 156920 KB Output is correct
52 Correct 78 ms 156920 KB Output is correct
53 Correct 81 ms 156920 KB Output is correct
54 Correct 78 ms 156920 KB Output is correct
55 Correct 76 ms 156920 KB Output is correct