QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#860791#9982. Staircase Museumucup-team987#WA 7ms3712kbC++265.5kb2025-01-18 14:58:212025-01-18 15:02:42

Judging History

This is the latest submission verdict.

  • [2025-01-18 15:02:42]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 3712kb
  • [2025-01-18 14:58:21]
  • Submitted

answer

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

int Op(int x, int y) { return max(x, y); }
int E() { return -INF; }

void Solve() {
  int n;
  IN(n);
  vector<int> l(n), r(n);
  for (int i : Rep(0, n)) {
    IN(l[i], r[i]);
    --l[i];
  }

  int N = 2 * (n + 1);

  vector<pair<int, int>> v;
  for (int i : Rep1(1, n)) {
    if (i == n || l[i - 1] < l[i]) {
      v.emplace_back(2 * i + 1, l[i - 1]);
    }
  }
  for (int i : Rep(0, n)) {
    if (i == 0 || r[i - 1] < r[i]) {
      v.emplace_back(2 * i, r[i]);
    }
  }
  ranges::sort(v, {}, LAMBDA(iv, apply(LAMBDA2(i, v, pair(v, -i)), iv)));

  vector seg(2, atcoder::segtree<int, Op, E>(N));
  for (int i : v | views::keys) {
    int mx = 0;
    SetMax(mx, seg[i & 1].prod(0, i));
    SetMax(mx, seg[~i & 1].prod(0, i) + 1);
    seg[i & 1].set(i, mx + 1);
  }

  int ans = 0;
  SetMax(ans, seg[0].all_prod());
  SetMax(ans, seg[1].all_prod());
  OUT(ans);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;
  IN(t);
  while (t--) {
    Solve();
  }
}

#elif __INCLUDE_LEVEL__ == 1

#include <bits/stdc++.h>

namespace atcoder {

namespace internal {

using std::bit_ceil;

int countr_zero(unsigned int n) {
  return __builtin_ctz(n);
}

constexpr int countr_zero_constexpr(unsigned int n) {
  int x = 0;
  while (!(n & (1 << x))) x++;
  return x;
}

}  // namespace internal

}  // namespace atcoder

namespace atcoder {

template <class S, auto op, auto e> struct segtree {
  static_assert(std::is_convertible_v<decltype(op), std::function<S(S, S)>>,
                "op must work as S(S, S)");
  static_assert(std::is_convertible_v<decltype(e), std::function<S()>>,
                "e must work as S()");

 public:
  segtree() : segtree(0) {}
  explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
  explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {
    size = (int)internal::bit_ceil((unsigned int)(_n));
    log = internal::countr_zero((unsigned int)size);
    d = std::vector<S>(2 * size, e());
    for (int i = 0; i < _n; i++) d[size + i] = v[i];
    for (int i = size - 1; i >= 1; i--) {
      update(i);
    }
  }

  void set(int p, S x) {
    assert(0 <= p && p < _n);
    p += size;
    d[p] = x;
    for (int i = 1; i <= log; i++) update(p >> i);
  }

  S get(int p) const {
    assert(0 <= p && p < _n);
    return d[p + size];
  }

  S prod(int l, int r) const {
    assert(0 <= l && l <= r && r <= _n);
    S sml = e(), smr = e();
    l += size;
    r += size;

    while (l < r) {
      if (l & 1) sml = op(sml, d[l++]);
      if (r & 1) smr = op(d[--r], smr);
      l >>= 1;
      r >>= 1;
    }
    return op(sml, smr);
  }

  S all_prod() const { return d[1]; }

  template <bool (*f)(S)> int max_right(int l) const {
    return max_right(l, [](S x) { return f(x); });
  }
  template <class F> int max_right(int l, F f) const {
    assert(0 <= l && l <= _n);
    assert(f(e()));
    if (l == _n) return _n;
    l += size;
    S sm = e();
    do {
      while (l % 2 == 0) l >>= 1;
      if (!f(op(sm, d[l]))) {
        while (l < size) {
          l = (2 * l);
          if (f(op(sm, d[l]))) {
            sm = op(sm, d[l]);
            l++;
          }
        }
        return l - size;
      }
      sm = op(sm, d[l]);
      l++;
    } while ((l & -l) != l);
    return _n;
  }

  template <bool (*f)(S)> int min_left(int r) const {
    return min_left(r, [](S x) { return f(x); });
  }
  template <class F> int min_left(int r, F f) const {
    assert(0 <= r && r <= _n);
    assert(f(e()));
    if (r == 0) return 0;
    r += size;
    S sm = e();
    do {
      r--;
      while (r > 1 && (r % 2)) r >>= 1;
      if (!f(op(d[r], sm))) {
        while (r < size) {
          r = (2 * r + 1);
          if (f(op(d[r], sm))) {
            sm = op(d[r], sm);
            r--;
          }
        }
        return r + 1 - size;
      }
      sm = op(d[r], sm);
    } while ((r & -r) != r);
    return 0;
  }

 private:
  int _n, size, log;
  std::vector<S> d;

  void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};

}  // namespace atcoder

template <class T> concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T> concept Tuple = std::__is_tuple_like<T>::value && !Range<T>;

namespace std {

istream& operator>>(istream& is, Range auto&& r) {
  for (auto&& e : r) is >> e;
  return is;
}
istream& operator>>(istream& is, Tuple auto&& t) {
  apply([&](auto&... xs) { (is >> ... >> xs); }, t);
  return is;
}

ostream& operator<<(ostream& os, Range auto&& r) {
  auto sep = "";
  for (auto&& e : r) os << exchange(sep, " ") << e;
  return os;
}
ostream& operator<<(ostream& os, Tuple auto&& t) {
  auto sep = "";
  apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
  return os;
}

}  // namespace std

using namespace std;

#define LAMBDA(x, ...) ([&](auto&& x) -> decltype(auto) { return __VA_ARGS__; })
#define LAMBDA2(x, y, ...) ([&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; })
#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define Rep1(...) [](int l, int r) { return Rep(l, r + 1); }(__VA_ARGS__)
#define SetMax(...) LAMBDA2(x, y, x < y && (x = y, 1))(__VA_ARGS__)
#define INF (INT_MAX / 2)
#define IN(...) (cin >> forward_as_tuple(__VA_ARGS__))
#define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n')

#endif  // __INCLUDE_LEVEL__ == 1

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

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

output:

2
3
3
4

result:

ok 4 number(s): "2 3 3 4"

Test #2:

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

input:

1
1
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 3584kb

input:

9653
1
1 1
2
1 1
1 1
3
1 1
1 1
1 1
4
1 1
1 1
1 1
1 1
5
1 1
1 1
1 1
1 1
1 1
6
1 1
1 1
1 1
1 1
1 1
1 1
6
1 2
1 2
1 2
1 2
1 2
2 2
6
1 1
1 1
1 1
1 1
1 1
1 2
6
1 2
1 2
1 2
1 2
1 2
2 3
5
1 2
1 2
1 2
1 2
2 2
6
1 2
1 2
1 2
1 2
2 2
2 2
6
1 3
1 3
1 3
1 3
2 3
3 3
6
1 2
1 2
1 2
1 2
2 2
2 3
6
1 3
1 3
1 3
1 3
2 3...

output:

1
1
1
1
1
1
2
2
2
2
2
3
3
3
2
2
2
3
3
2
3
2
2
3
3
3
3
3
2
2
2
3
3
3
3
3
4
4
4
3
3
3
4
4
3
4
3
3
4
4
4
4
4
2
2
2
2
3
3
2
3
3
3
2
2
3
3
3
3
3
3
3
3
3
3
4
4
3
3
4
4
3
4
3
3
3
4
4
3
3
4
4
3
4
2
2
3
3
3
3
3
3
4
4
3
4
2
2
2
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
3
3
3
4
4
3
3
4
4
3
4
3
3
4
4
4
4
4
4
4
4
4
3
3
4
...

result:

wrong answer 218th numbers differ - expected: '4', found: '3'