QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291893#7118. Closing Timenhuang6858 95ms50776kbC++205.5kb2023-12-27 12:52:182023-12-27 12:52:19

Judging History

你现在查看的是测评时间为 2023-12-27 12:52:19 的历史记录

  • [2024-04-28 07:59:41]
  • 管理员手动重测本题所有提交记录
  • 测评结果:8
  • 用时:141ms
  • 内存:50508kb
  • [2023-12-27 12:52:19]
  • 评测
  • 测评结果:8
  • 用时:95ms
  • 内存:50776kb
  • [2023-12-27 12:52:18]
  • 提交

answer

/**
 * @file closing.cpp
 * @author n685
 * @brief
 * @date 2023-12-26
 *
 *
 */
#include "closing.h"
#include <bits/stdc++.h>

#ifdef LOCAL
#include "dd/debug.h"
#else
#define dbg(...) 42
#define dbgR(...) 4242
#define dbgP(...) 420
#define dbgRP(...) 420420
void nline() {}
#endif

using LL = long long;

template <class T> struct CC {
  std::vector<T> val;
  void insert(T a) { val.push_back(a); }
  void init() {
    std::sort(val.begin(), val.end());
    val.erase(std::unique(val.begin(), val.end()), val.end());
  }
  int operator[](T a) const {
    return static_cast<int>(std::distance(
        val.begin(), std::lower_bound(val.begin(), val.end(), a)));
  }
  int size() const { return static_cast<int>(val.size()); }
};

CC<int64_t> cc;
template <class T> struct Seg {
  struct Node {
    using RT = T;
    static constexpr RT ID = 0;
    T val = 0;
    int cnt = 0;

    Node() {}
    Node(T v) : val(v) {}

    operator RT() { return val; }
    static RT comb(RT a, RT b) { return a + b; }
    void add(T v) {
      val += v;
      cnt++;
    }
    void rem(T v) {
      val += v;
      cnt--;
    }
    void pull(Node &ll, Node &rr) {
      val = ll.val + rr.val;
      cnt = ll.cnt + rr.cnt;
    }
  };
  using RT = typename Node::RT;
  int sz = 0;
  std::vector<Node> val;

  Seg() {}
  Seg(int _sz) {
    // sz = _sz;
    if (_sz == 1) {
      sz = 1;
    } else {
      sz = (1 << (std::__lg(_sz - 1) + 1));
    }
    val.resize(2 * sz);
  }
  Seg(const std::vector<T> &v) : Seg(static_cast<int>(v.size())) {
    for (int i = 0; i < static_cast<int>(v.size()); ++i) {
      val[i + sz] = v[i];
    }
    build(0, sz - 1);
  }
  void build(int l, int r) {
    l += sz, r += sz;
    l /= 2, r /= 2;
    for (int k = 2; l >= 1; l /= 2, r /= 2, k *= 2) {
      for (int i = l; i <= r; ++i) {
        val[i].pull(val[2 * i], val[2 * i + 1]);
      }
    }
  }
  void upd(int ind, const std::function<void(Node &)> &f) {
    f(val[ind += sz]);
    for (ind /= 2; ind >= 1; ind /= 2) {
      val[ind].pull(val[2 * ind], val[2 * ind + 1]);
    }
  }
  void add(int ind, const T &v) {
    upd(ind, [&v](Node &n) { n.add(v); });
  }
  void rem(int ind, const T &v) {
    upd(ind, [&v](Node &n) { n.rem(v); });
  }
  RT query(int l, int r) {
    RT ll = Node::ID, rr = Node::ID;
    for (l += sz, r += sz; l <= r; l /= 2, r /= 2) {
      if (l % 2 == 1) {
        ll = Node::comb(val[l++], ll);
      }
      if (r % 2 == 0) {
        rr = Node::comb(rr, val[r--]);
      }
    }
    return Node::comb(ll, rr);
  }
  int walk(LL lim, int ind, int l, int r) {
    if (lim < 0) {
      return 0;
    }
    if (l >= cc.size()) {
      return 0;
    }
    if (l == r) {
      if (cc.val[l] == 0) {
        return val[ind].cnt;
      } else {
        return (int)std::min<LL>(val[ind].cnt, lim / cc.val[l]);
      }
    }
    int ll = 0;
    int mid = (l + r) / 2;
    if (val[2 * ind].val <= lim) {
      ll = val[2 * ind].cnt;
      lim -= val[2 * ind].val;
    } else {
      return walk(lim, 2 * ind, l, mid);
    }
    return ll + walk(lim, 2 * ind + 1, mid + 1, r);
  }
  int walk(LL lim) { return walk(lim, 1, 0, sz - 1); }
};

struct Node {
  LL a, b;
};

int max_score(int N, int X, int Y, long long K, std::vector<int> U,
              std::vector<int> V, std::vector<int> W) {
  using ll = long long;
  int n = N, x = X, y = Y; // lowercase better
  ll k = K;
  std::vector<std::vector<std::pair<ll, int>>> adj(N);
  for (int i = 0; i < n - 1; ++i) {
    adj[U[i]].emplace_back(W[i], V[i]);
    adj[V[i]].emplace_back(W[i], U[i]);
  }

  std::vector<ll> dx(n, (ll)4e18), dy(n, (ll)4e18);
  std::vector<bool> cx(n, (ll)4e18), cy(n, (ll)4e18);
  cx[x] = 0;
  cy[y] = 0;
  dx[x] = 0;
  dy[y] = 0;
  auto dfs = [&](auto &self, int node, int par, std::vector<ll> &dist) -> void {
    for (auto [w, i] : adj[node]) {
      if (i == par) {
        continue;
      }
      dist[i] = dist[node] + w;
      cy[i] = cy[node] + dist[node] + w;
      self(self, i, node, dist);
    }
  };
  dfs(dfs, x, -1, dx);
  dfs(dfs, y, -1, dy);

  int ans1 = 0;
  {
    ll kk = k;
    std::vector<int> ind(n);
    std::iota(ind.begin(), ind.end(), 0);
    std::sort(ind.begin(), ind.end(), [&](int a, int b) {
      return std::min(dx[a], dy[a]) < std::min(dx[b], dy[b]);
    });
    for (int i = 0; i < n; ++i) {
      kk -= std::min(dx[ind[i]], dy[ind[i]]);
      if (kk < 0) {
        break;
      }
      ans1++;
    }
  }

  std::vector<int> s;
  int st = 0;
  std::vector<Node> v(n);
  for (int i = 0; i < n; ++i) {
    if (dx[i] + dy[i] != dx[y]) {
      v[i].a = std::min(dx[i], dy[i]);
      v[i].b = std::max(dx[i], dy[i]);
    } else {
      st++;
      k -= std::min(dx[i], dy[i]);
      v[i].a = std::max(dx[i], dy[i]) - std::min(dx[i], dy[i]);
      v[i].b = (int64_t)4e18;
    }
    cc.insert(v[i].a);
    cc.insert(v[i].b - v[i].a);
  }
  if (k < 0) {
    return ans1;
  }
  cc.init();
  std::sort(v.begin(), v.end(), [](const Node &a, const Node &b) {
    return a.b == b.b ? a.a < b.a : a.b < b.b;
  });

  Seg<int64_t> seg(cc.size());
  for (int i = 0; i < n; ++i) {
    seg.add(cc[v[i].a], v[i].a);
  }
  int ans = seg.walk(k);
  for (int i = 0; i < n; ++i) {
    k -= v[i].a;
    seg.rem(cc[v[i].a], v[i].a);
    seg.add(cc[v[i].b - v[i].a], v[i].b - v[i].a);
    if (k < 0) {
      break;
    }
    ans = std::max(ans, i + 1 + seg.walk(k));
  }
  return std::max(ans1, st + ans);
}

詳細信息

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 85ms
memory: 42420kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 31011 61157 8517583098
31011 129396 964383
1655 129396 331139
1655 191487 566483
110385 191487 865248
43212 110385 542661
43212 81682 13766
81682 91774 546589
91774 124706 780638
124706 175650 118706
10421 175650 615314
10421 151953 436270
140430 151...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
451

result:

ok 

Test #2:

score: 0
Accepted
time: 95ms
memory: 50776kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 97133 170892 35489415917
114511 170892 730058
34783 114511 435023
34783 47301 562314
47301 162600 457629
44856 162600 365133
44856 133801 83016
117539 133801 124222
117539 128719 199821
77871 128719 703141
77871 133155 624331
7211 133155 138691
7211 ...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
650

result:

ok 

Test #3:

score: 0
Accepted
time: 55ms
memory: 11940kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
200
1000 611 992 5736784
504 611 954658
504 936 219278
502 936 632439
393 502 177662
267 393 570266
267 291 941365
291 310 168052
310 765 253098
635 765 724932
274 635 842125
274 799 848645
39 799 433118
39 940 705598
553 940 564063
553 960 69665
917 960 6904...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
126
38
69
34
52
33
42
32
39
41
38
36
45
84
40
44
50
42
47
34
38
47
38
37
39
37
44
39
32
33
38
54
25
36
46
33
37
35
28
36
45
43
44
49
37
33
43
44
53
42
33
30
50
41
37
40
37
44
207
31
37
45
36
43
35
40
41
39
135
53
40
32
31
37
34
38
51
48
36
40
48
42
43
43
3...

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 3732kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
50 23 25 382806473
0 1 375710
1 2 898637
2 3 10402
3 4 536577
4 5 385023
5 6 71075
6 7 543368
7 8 301497
8 9 174394
9 10 711312
10 11 923006
11 12 675532
12 13 838667
13 14 565729
14 15 979816
15 16 862618
16 17 576015
17 18 177751
18 19 306989
19 20 881492...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
95

result:

wrong answer 1st lines differ - on the 1st token, expected: '96', found: '95'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #36:

score: 9
Accepted
time: 0ms
memory: 3780kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
4 0 1 9
0 2 2
1 2 3
2 3 3

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
6

result:

ok 

Test #37:

score: 0
Accepted
time: 0ms
memory: 4028kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
4 0 1 8
0 2 2
1 2 3
2 3 100

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
5

result:

ok 

Test #38:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
8 0 4 84
0 1 1
1 2 29
2 3 29
3 4 1
4 5 20
2 6 20
3 7 1

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
9

result:

ok 

Test #39:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
18 14 15 221112
8 10 15984
3 8 2664
6 10 5328
9 10 13320
5 10 23976
1 10 13320
3 4 5328
3 7 26640
3 11 23976
4 15 23976
6 17 18648
12 17 5328
11 13 13320
0 11 7992
15 16 5328
2 16 5328
13 14 2664

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
14

result:

ok 

Test #40:

score: -9
Wrong Answer
time: 0ms
memory: 3764kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
19 3 9 11232111
13 14 174955
0 13 69982
10 14 209946
14 15 209946
12 14 104973
0 11 314919
0 3 314919
0 7 139964
5 10 209946
10 16 69982
4 10 104973
9 11 279928
9 17 349910
1 4 104973
3 18 209946
6 18 174955
7 8 314919
2 7 104973

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
27

result:

wrong answer 1st lines differ - on the 1st token, expected: '28', found: '27'

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #4:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%