QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#42601#4429. Gebyte's GrindantiravelWA 4023ms237592kbC++233.2kb2022-08-02 19:25:452022-08-02 19:25:46

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-02 19:25:46]
  • 评测
  • 测评结果:WA
  • 用时:4023ms
  • 内存:237592kb
  • [2022-08-02 19:25:45]
  • 提交

answer

#include <bits/stdc++.h>
#include <limits>
#include <vector>

constexpr int64_t INF = std::numeric_limits<int64_t>::max() / 4;

struct node_t
{
  int64_t p = 0, h = 0, l = 0;

  node_t() = default;

  node_t(int64_t p, int64_t h, int64_t l) :
      p(std::min(INF, p)), h(std::min(INF, h)), l(std::min(INF, l))
  {
  }
};

node_t join(const node_t &a, const node_t &b)
{
  if (a.h < b.p)
    return {b.p + (a.p + a.l - a.h), b.h, b.l};
  else if (a.h < b.p + b.h)
    return {a.p, b.h, a.l + (b.p + b.l - a.h)};
  else
    return {a.p, b.h + (a.h - b.p - b.l), a.l};
}

struct segment_tree
{
  std::vector<node_t> p;

  segment_tree(int n) : p(4l * n) {}

  void init(int u, int l, int r, const std::vector<node_t> &a)
  {
    if (r - l == 1)
      p[u] = a[l];
    else
    {
      int m = l + (r - l) / 2;
      init(u + u, l, m, a);
      init(u + u + 1, m, r, a);
      p[u] = join(p[u + u], p[u + u + 1]);
    }
  }

  void modify(int u, int l, int r, int pos, const node_t &v)
  {
    if (r - l == 1)
      p[u] = v;
    else
    {
      int m = l + (r - l) / 2;
      if (pos < m)
        modify(u + u, l, m, pos, v);
      else
        modify(u + u + 1, m, r, pos, v);
      p[u] = join(p[u + u], p[u + u + 1]);
    }
  }

  std::pair<node_t, int> lower_bound(
      int u, int l, int r, int pl, const node_t &prev, const auto &pred)
  {
    if (pl <= l)
    {
      auto vv = join(prev, p[u]);
      if (pred(vv))
        return {vv, r};
    }

    if (r - l == 1)
      return {prev, l};
    else
    {
      int m = l + (r - l) / 2;
      if (m <= pl)
      {
        return lower_bound(u + u + 1, m, r, pl, prev, pred);
      }
      else
      {
        auto la = lower_bound(u + u, l, m, pl, prev, pred);
        if (la.second < m)
          return la;
        else
          return lower_bound(u + u + 1, m, r, pl, la.first, pred);
      }
    }
  }
};

int main()
{
  int t;
  scanf("%d", &t);

  for (int i = 0; i < t; i++)
  {
    int n, q;
    scanf("%d%d", &n, &q);
    int64_t h;
    scanf("%" SCNi64, &h);

    auto read_node = [] -> node_t {
      char type;
      scanf(" %c", &type);
      int64_t v;
      scanf("%" SCNi64, &v);

      if (type == 'B')
        return {v + 1, 1, 0};
      else if (type == 'K')
        return {v, v, INF};
      else
        return {0, v, v};
    };

    std::vector<node_t> as(n);
    for (int i = 0; i < n; i++)
      as[i] = read_node();

    segment_tree sgt(n);
    sgt.init(1, 0, n, as);

    for (int i = 0; i < q; i++)
    {
      char opt;
      scanf(" %c", &opt);

      if (opt == 'Z')
      {
        int p;
        scanf("%d", &p);
        p -= 1;
        auto v = read_node();
        sgt.modify(1, 0, n, p, v);
      }
      else
      {
        int pl;
        scanf("%d", &pl);
        pl -= 1;

        // clang-format off
        int pr = sgt.lower_bound(1, 0, n, pl, {0, 0, 0}, [h](const node_t &v) {
          return h >= v.p;
        }).second;
        // clang-format on

        if (pl == pr)
          puts("-1");
        else
          printf("%d\n", pr);
      }
    }
  }

  return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 4023ms
memory: 237592kb

input:

1
2000000 4000000 1000000000000
B 2982992025
B 1226542907
B 2299259203
B 1223702056
B 1407121251
B 340783317
B 1259091208
B 2101980047
B 2611543443
B 2010658889
B 4233714406
B 3112120167
B 2311876255
B 2789960428
B 3008572010
B 1
B 2464951378
B 1364240867
B 2829584762
B 2511437438
B 692948679
B 1113...

output:

830932
237853
1006774
1911620
1482421
995665
912109
594970
1956432
163024
1223632
213896
1606444
541015
578063
1313903
1641662
645995
900259
1008788
1722167
1905273
765136
1767089
993651
134795
142089
422999
379607
188171
556151
1019531
12694
1007201
623107
1143462
887206
856444
173828
1185301
16894...

result:

wrong answer 1st lines differ - expected: '833302', found: '830932'