QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#120291#6608. Descent of DragonsKHINRE 0ms0kbC++143.5kb2023-07-06 16:27:002023-07-06 16:27:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 16:27:00]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-07-06 16:27:00]
  • 提交

answer

// # define NDEBUG

# include <bits/stdc++.h>

using namespace std;

namespace debt {
  // auto& cin(std::cin);
  // auto& cout(std::cout);
  ifstream cin("debt.in");
  ofstream cout("debt.out");
  constexpr uint N(500'000);
  struct segment_tree {
    struct node {
      map<double, double, greater<double>> s;
      map<double, double, greater<double>> t;
    };
    node v[4 * N];
    bool modify(uint u, uint l, uint r, uint tl, uint tr, double a, double b) {
      assert(v[u].s.size() <= r - l);
      assert(v[u].t.size() <= r - l);
      if (v[u].s.empty()) v[u].s.emplace(0, 0);
      if (v[u].t.empty()) v[u].t.emplace(0, 0);
      if (tr <= l || r <= tl) return false;
      auto const ta(v[u].t.find(a));
      if (ta == v[u].t.end()) return false;
      if (tl <= l && r <= tr && v[u].t.find(b) == v[u].t.end()) {
        v[u].t.emplace(b, ta->second);
        v[u].s.at(ta->second) = b;
        v[u].t.erase(ta);
        assert(v[u].s.size() <= r - l);
        assert(v[u].t.size() <= r - l);
        return true;
      } else {
        auto const emp(v[u].t.emplace(b, -1));
        auto const tb(emp.first);
        if (tb->second < 0) {
          double const sl(next(tb) == v[u].t.end() ? 0 : next(tb)->second);
          double const sr(tb == v[u].t.begin() ? 1e36 : prev(tb)->second);
          assert(sl < sr), tb->second = min((sl + sr) / 2, sl + 1e18);
          // fprintf(stderr, "generate %f\n", min((sl + sr) / 2, sl + 1e18));
        }
        bool const ll(modify(u << 1 | 0, l, (l + r) / 2, tl, tr, ta->second, tb->second));
        bool const rr(modify(u << 1 | 1, (l + r) / 2, r, tl, tr, ta->second, tb->second));
        if (!ll && !rr && emp.second) {
          v[u].t.erase(b);
          assert(v[u].s.size() <= r - l);
          assert(v[u].t.size() <= r - l);
        } else {
          if (tl <= l && r <= tl) assert(ll || rr);
          v[u].s.emplace(tb->second, b);
          auto const la(v[u << 1 | 0].t.find(ta->second));
          auto const ra(v[u << 1 | 1].t.find(ta->second));
          if (la == v[u << 1 | 0].t.end())
            if (ra == v[u << 1 | 1].t.end())
              v[u].s.erase(ta->second), v[u].t.erase(ta);
          assert(v[u].s.size() <= r - l);
          assert(v[u].t.size() <= r - l);
        }
        assert(v[u].s.size() <= r - l);
        assert(v[u].t.size() <= r - l);
        return ll || rr;
      }
    }
    double query(uint u, uint l, uint r, uint tl, uint tr) const {
      if (tr <= l || r <= tl) return -1;
      if (v[u].s.empty() || v[u].t.empty()) return 0;
      if (tl <= l && r <= tr) return v[u].t.begin()->first;
      double ll(query(u << 1 | 0, l, (l + r) / 2, tl, tr));
      double rr(query(u << 1 | 1, (l + r) / 2, r, tl, tr));
      assert(ll < 0 || v[u].s.find(ll) != v[u].s.end());
      assert(rr < 0 || v[u].s.find(rr) != v[u].s.end());
      if (ll >= 0) ll = v[u].s.find(ll)->second;
      if (rr >= 0) rr = v[u].s.find(rr)->second;
      return max(ll, rr);
    }
  };
  uint n, q;
  segment_tree seg;
  void main() {
    cin >> n >> q;
    for (uint i(1); i <= q; ++i) {
      uint o, l, r, x;
      cin >> o >> l >> r, --l;
      switch (o) {
        case 1:
          cin >> x;
          seg.modify(1, 0, n, l, r, x, x + 1);
          break;
        case 2:
          cout << round(seg.query(1, 0, n, l, r)) << '\n';
          break;
      }
    }
    cout.flush();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  debt::cin.tie(nullptr);
  debt::main();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

5 5
1 3 5 0
1 1 4 1
1 1 5 2
2 2 2
2 4 5

output:


result: