QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#462819#3101. Event Hopping 2nhuang6850 71ms16596kbC++203.2kb2024-07-04 06:05:502024-07-04 06:05:51

Judging History

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

  • [2024-07-04 06:05:51]
  • 评测
  • 测评结果:0
  • 用时:71ms
  • 内存:16596kb
  • [2024-07-04 06:05:50]
  • 提交

answer

/**
 * @file qoj3101-1.cpp
 * @author n685
 * @brief
 * @date 2024-07-03
 *
 *
 */
#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() {}
void bar() {}
#endif

namespace rs = std::ranges;
namespace rv = std::views;

constexpr int MX = 100000;
constexpr int LG = std::__lg(2 * MX - 1);

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()); }
};

struct Event {
  int val, i, type;
};

int main() {
#ifndef LOCAL
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif

  int n, k;
  std::cin >> n >> k;
  ++n;
  ++k;

  std::vector<int> l(n), r(n);
  CC<int> cc;
  cc.insert(0);
  for (const int i : rv::iota(1, n)) {
    std::cin >> l[i] >> r[i];
    cc.insert(l[i]);
    cc.insert(r[i]);
  }
  cc.init();
  const int m = cc.size();
  for (int &i : l) {
    i = cc[i];
  }
  for (int &i : r) {
    i = cc[i];
  }
  std::vector lift(LG, std::vector<int>(n + 1, n));
  {
    std::vector<Event> ev;
    for (const int i : rv::iota(0, n)) {
      ev.emplace_back(l[i], i, 0);
      ev.emplace_back(r[i], i, 1);
    }
    std::ranges::sort(ev, std::greater<>(),
                      [](const Event &e) { return e.val; });
    int miR = m, mi = n;
    for (const auto &[val, i, type] : ev) {
      if (type == 0) {
        if (miR > r[i]) {
          miR = r[i];
          mi = i;
        }
      } else {
        lift[0][i] = mi;
      }
    }
    for (const int i : rv::iota(1, LG)) {
      for (const int j : rv::iota(0, n)) {
        lift[i][j] = lift[i - 1][lift[i - 1][j]];
      }
    }
  }
  auto count = [&](int i, int rb) -> int {
    int ans = 0;
    for (int j : rv::iota(0, LG) | rv::reverse) {
      int nxt = lift[j][i];
      if (nxt != n and r[nxt] <= rb) {
        ans or_eq (1 << j);
        i = nxt;
      }
    }
    return ans;
  };
  std::set<std::pair<int, int>> in;
  in.emplace(0, 0);
  int cnt = count(0, n);
  for (const int i : rv::iota(1, n)) {
    const auto it = in.lower_bound({r[i], 0});
    if ((it != in.end() and l[it->second] < r[i]) or
        std::prev(it)->first > l[i]) {
      continue;
    }
    const int rb = (it == in.end() ? n : l[it->second]),
              li = std::prev(it)->second;
    int lcnt = cnt - count(li, rb);
    lcnt += count(li, l[i]);
    lcnt += 1;
    lcnt += count(i, rb);
    if (lcnt >= k) {
      in.emplace(r[i], i);
    }
    if (std::ssize(in) >= k) {
      break;
    }
  }
  if (std::ssize(in) < k) {
    std::cout << "-1\n";
  } else {
    std::vector<int> ans;
    ans.reserve(k);
    for (const auto &[a, i] : in | rv::drop(1)) {
      ans.push_back(i);
    }
    std::ranges::sort(ans);
    for (const int i : ans) {
      std::cout << i << '\n';
    }
  }
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 1ms
memory: 3488kb

input:

1 1
1 3

output:

1

result:

ok single line: '1'

Test #2:

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

input:

2 1
2 4
3 7

output:

1

result:

ok single line: '1'

Test #3:

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

input:

3 1
2 5
3 5
4 7

output:

1

result:

ok single line: '1'

Test #4:

score: -7
Wrong Answer
time: 58ms
memory: 15716kb

input:

99999 93097
40044 40749
44538 45365
46530 47401
52845 53481
59519 60065
86226 87059
88353 88992
95665 96502
95669 96575
100446 100968
121870 122544
130836 131540
146294 147230
151177 151970
160381 161376
164174 165119
166582 167438
169062 169687
173200 173849
177329 178217
189213 189811
249372 25029...

output:

-1

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #47:

score: 1
Accepted
time: 0ms
memory: 3604kb

input:

1 1
134842099 137944073

output:

1

result:

ok single line: '1'

Test #48:

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

input:

2 2
4015595 884953730
519508315 726912949

output:

-1

result:

ok single line: '-1'

Test #49:

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

input:

3 2
551691302 800582045
14063803 52897269
153641504 567834643

output:

1
2

result:

ok 2 lines

Test #50:

score: -1
Wrong Answer
time: 0ms
memory: 3600kb

input:

18 3
157893686 958635898
790021767 976682032
534783017 706987897
216566011 510148270
288661613 856715472
81126924 420966670
9734253 823219818
77427078 241270378
182953794 928971032
65710916 937359407
159217847 343023570
266169092 635952191
94867522 407392584
298640819 490028599
281580042 514089998
6...

output:

-1

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #74:

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

input:

3000 57
226083340 261990234
392684356 462929590
468018811 841719892
495096853 606046097
196983814 256423598
331199122 967656486
802593662 931108452
74501453 679054962
294344294 752837262
295708332 547261648
265421699 652708933
272959087 727136240
165667761 846917534
61770748 157663302
608516043 8492...

output:

-1

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #111:

score: 0
Wrong Answer
time: 71ms
memory: 16596kb

input:

100000 361
136798318 785362988
255943758 535488232
175203444 266819907
766993466 893575347
67274251 589651108
662289594 883406317
830803801 849703610
729398668 798198453
202605534 677648797
66407931 925909114
174421361 601553812
522629146 701284080
136544340 295925673
299796891 499869765
736583725 8...

output:

-1

result:

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