結果

問題 No.3258 Xor Division Game
コンテスト
ユーザー Kude
提出日時 2025-09-06 00:08:15
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,757 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,348 ms
コンパイル使用メモリ 347,456 KB
最終ジャッジ日時 2026-07-14 17:05:41
合計ジャッジ時間 3,366 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:54:26: error: class template argument deduction failed:
   54 |   value_compression vc = f;
      |                          ^
main.cpp:54:26: error: call of overloaded 'value_compression({anonymous}::VI&)' is ambiguous
main.cpp:54:26: note: there are 3 candidates
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/vector:68,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/functional:66,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:55,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_vector.h:631:7: note: candidate 1: 'value_compression(const std::vector<_Tp>&) -> {anonymous}::value_compression<_Tp> [with S = int]'
  631 |       vector(const vector& __x)
      |       ^~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_vector.h:458:11: note: candidate 2: 'value_compression(std::vector<_Tp>) -> {anonymous}::value_compression<_Tp> [with S = int]'
  458 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
main.cpp:26:3: note: candidate 3: 'value_compression(std::vector<_Tp>) -> {anonymous}::value_compression<S> [with S = int]'
   26 |   value_compression(vector<S> v) : vector<S>(move(v)) {}
      |   ^~~~~~~~~~~~~~~~~
main.cpp:54:26: note: explicit deduction guides not considered for copy-initialization
   54 |   value_compression vc = f;
      |                          ^

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

template <class S>
struct value_compression : vector<S> {
  bool built = false;
  using VS = vector<S>;
  using VS::VS;
  value_compression(vector<S> v) : vector<S>(move(v)) {}
  void build() {
    sort(this->begin(), this->end());
    this->erase(unique(this->begin(), this->end()), this->end());
    built = true;
  }
  template <class T>
  void convert(T first, T last) {
    assert(built);
    for (; first != last; ++first) *first = (*this)(*first);
  }
  int operator()(S x) {
    assert(built);
    return lower_bound(this->begin(), this->end(), x) - this->begin();
  }
  void clear() {
    this->clear();
    built = false;
  }
};

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI f(n);
  rep(i, n) cin >> f[i];
  value_compression vc = f;
  vc.build();
  vc.convert(all(f));
  int sz = vc.size();
  VVI pos(sz);
  rep(i, n) pos[f[i]].emplace_back(i);
  VI cnt(sz);
  vector<list<int>::iterator> v2it(sz);
  list<int> v_ok;
  auto add = [&](int i) {
    int v = f[i];
    if (cnt[v] == 0) {
      v_ok.emplace_front(v);
      v2it[v] = v_ok.begin();
    } else if (cnt[v] == 1) v_ok.erase(v2it[v]);
    cnt[v]++;
  };
  auto rmv = [&](int i) {
    int v = f[i];
    cnt[v]--;
    if (cnt[v] == 0) v_ok.erase(v2it[v]);
    else if (cnt[v] == 1) {
      v_ok.emplace_front(v);
      v2it[v] = v_ok.begin();
    }
  };
  rep(i, n) add(i);
  int ans = 0;
  auto dfs = [&](auto&& self, int l, int r) {
    if (v_ok.empty()) {
      for (int i = l; i < r; i++) rmv(i);
      return;
    }
    int v = v_ok.front();
    int c = *ranges::lower_bound(pos[v], l);
    rmv(c);
    ans++;
    if (c - l < r - (c + 1)) {
      for (int i = l; i < c; i++) rmv(i);
      self(self, c + 1, r);
      for (int i = l; i < c; i++) add(i);
      self(self, l, c);
    } else {
      for (int i = c + 1; i < r; i++) rmv(i);
      self(self, l, c);
      for (int i = c + 1; i < r; i++) add(i);
      self(self, c + 1, r);
    }
  };
  dfs(dfs, 0, n);
  cout << (ans % 2 ? "Alice" : "Bob") << '\n';
}
0