QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#802442#9871. Just another Sorting Problemucup-team987#WA 0ms3860kbC++234.8kb2024-12-07 13:43:042024-12-07 13:43:07

Judging History

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

  • [2024-12-07 13:43:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3860kb
  • [2024-12-07 13:43:04]
  • 提交

answer

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

void Solve() {
  int n;
  IN(n);
  string s;
  IN(s);
  atcoder::fenwick_tree<int> f(n);
  int parity = 0;
  for (int _ : Rep(0, n)) {
    int p;
    IN(p);
    --p;
    parity ^= f.sum(p, n) & 1;
    f.add(p, 1);
  }
  if (n == 2) {
    OUT("Alice");
    return;
  }
  parity ^= s == "Bob";
  OUT(parity ? "Alice" : "Bob");
}

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 {

template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;

template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;

template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;

template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;

template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;

template <class T> using to_unsigned_t = typename to_unsigned<T>::type;

}  // namespace internal

}  // namespace atcoder

namespace atcoder {

template <class T> struct fenwick_tree {
  using U = internal::to_unsigned_t<T>;

 public:
  fenwick_tree() : _n(0) {}
  explicit fenwick_tree(int n) : _n(n), data(n) {}

  void add(int p, T x) {
    assert(0 <= p && p < _n);
    p++;
    while (p <= _n) {
      data[p - 1] += U(x);
      p += p & -p;
    }
  }

  T sum(int l, int r) {
    assert(0 <= l && l <= r && r <= _n);
    return sum(r) - sum(l);
  }

 private:
  int _n;
  std::vector<U> data;

  U sum(int r) {
    U s = 0;
    while (r > 0) {
      s += data[r - 1];
      r -= r & -r;
    }
    return s;
  }
};

}  // 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 _ _ [[maybe_unused]]
#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define IN(...) (cin >> forward_as_tuple(__VA_ARGS__))
#define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n')

#endif  // __INCLUDE_LEVEL__ == 1

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

3
2 Alice
2 1
3 Bob
1 3 2
10 Bob
1 2 3 4 5 6 7 8 10 9

output:

Alice
Bob
Bob

result:

ok 3 lines

Test #2:

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

input:

2
2 Alice
2 1
2 Bob
2 1

output:

Alice
Alice

result:

ok 2 lines

Test #3:

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

input:

10
3 Bob
2 3 1
3 Alice
3 1 2
3 Bob
3 1 2
3 Alice
1 3 2
3 Alice
3 2 1
3 Bob
2 1 3
3 Bob
1 3 2
3 Alice
2 1 3
3 Alice
2 3 1
3 Bob
3 2 1

output:

Alice
Bob
Alice
Alice
Alice
Bob
Bob
Alice
Bob
Bob

result:

ok 10 lines

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3560kb

input:

46
4 Alice
4 1 3 2
4 Bob
4 1 3 2
4 Bob
3 2 4 1
4 Bob
2 4 1 3
4 Bob
1 4 3 2
4 Bob
4 1 2 3
4 Alice
1 2 4 3
4 Alice
3 2 1 4
4 Bob
2 1 4 3
4 Bob
4 3 1 2
4 Alice
1 3 2 4
4 Bob
3 1 4 2
4 Bob
1 3 2 4
4 Alice
2 4 1 3
4 Bob
2 1 3 4
4 Alice
2 1 3 4
4 Bob
4 2 3 1
4 Bob
3 4 2 1
4 Alice
4 1 2 3
4 Bob
2 4 3 1
4 B...

output:

Bob
Alice
Alice
Bob
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Bob
Bob
Alice
Bob
Alice
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Alice
Alice
Bob
Alice
Bob
Bob
Bob
Alice
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Alice
Bob
Alice
Alice
Bob
Alice
Bob
Alice

result:

wrong answer 2nd lines differ - expected: 'Bob', found: 'Alice'