From 72f34f14980a1fcc958382a81d7711033c14aca3 Mon Sep 17 00:00:00 2001 From: hitonanode <32937551+hitonanode@users.noreply.github.com> Date: Sun, 29 Mar 2026 15:21:46 +0900 Subject: [PATCH] abc451 binary trie fix --- data_structure/binary_trie.hpp | 2 ++ data_structure/binary_trie.md | 1 + number/primitive_root.hpp | 4 ++-- number/test/binary_gcd.stress.test.cpp | 4 ++-- number/test/zeta_moebius_transform.test.cpp | 5 +++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/data_structure/binary_trie.hpp b/data_structure/binary_trie.hpp index 92c48723..9e59fa1c 100644 --- a/data_structure/binary_trie.hpp +++ b/data_structure/binary_trie.hpp @@ -85,6 +85,8 @@ template struct BinaryTrie { // Count elements y such that x ^ y < thres Count count_less_xor(Int x, Int thres) const { + if (thres <= 0) return Count(); + if ((thres >> maxD) > 0) return subtree_sum[0]; Count ret = Count(); int now = 0; diff --git a/data_structure/binary_trie.md b/data_structure/binary_trie.md index b0d44138..500bd424 100644 --- a/data_structure/binary_trie.md +++ b/data_structure/binary_trie.md @@ -26,3 +26,4 @@ Key v = bt.xor_min(t); // t ^ x (x は現在存在する値)の最小値を - [Library Checker: Set Xor-Min](https://judge.yosupo.jp/problem/set_xor_min) - [No.2977 Kth Xor Pair - yukicoder](https://yukicoder.me/problems/no/2977) +- [AtCoder Beginner Contest 451 G - Minimum XOR Walk](https://atcoder.jp/contests/abc451/tasks/abc451_g) diff --git a/number/primitive_root.hpp b/number/primitive_root.hpp index 5acda913..8f5a66b8 100644 --- a/number/primitive_root.hpp +++ b/number/primitive_root.hpp @@ -16,7 +16,7 @@ // - 163577857 ( = (39 << 22) + 1 ) -> 23 // - 2 -> 1 // - 1 -> -1 -long long find_smallest_primitive_root(long long n) { +inline long long find_smallest_primitive_root(long long n) { std::vector fac; const long long phi = FactorizeLonglong.euler_phi(n); for (long long q : FactorizeLonglong(phi)) { @@ -24,7 +24,7 @@ long long find_smallest_primitive_root(long long n) { } for (long long g = 1; g < n; g++) { - if (std::__gcd(n, g) != 1) continue; + if (std::gcd(n, g) != 1) continue; if (pow_mod(g, phi, n) != 1) return -1; bool ok = true; for (auto pp : fac) { diff --git a/number/test/binary_gcd.stress.test.cpp b/number/test/binary_gcd.stress.test.cpp index 8625acc0..17cda2cf 100644 --- a/number/test/binary_gcd.stress.test.cpp +++ b/number/test/binary_gcd.stress.test.cpp @@ -1,13 +1,13 @@ #define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A" // DUMMY #include "../binary_gcd.hpp" -#include // __gcd #include +#include using namespace std; template void test_binary_gcd(Int lo, Int hi) { for (Int x = lo; x <= hi; x++) { for (Int y = lo; y <= hi; y++) { - auto g = __gcd(x, y); + auto g = gcd(x, y); if (g < 0) g = -g; if (binary_gcd(x, y) != g) { cerr << "Did not match : (x, y) = " << x << ',' << y << ')' << endl; diff --git a/number/test/zeta_moebius_transform.test.cpp b/number/test/zeta_moebius_transform.test.cpp index 60ea2365..01db6981 100644 --- a/number/test/zeta_moebius_transform.test.cpp +++ b/number/test/zeta_moebius_transform.test.cpp @@ -3,6 +3,7 @@ #include "../../modint.hpp" #include #include +#include #include using namespace std; @@ -77,7 +78,7 @@ void test_gcdconv() { vector x = vecgen(n), y = vecgen(n), z(n + 1); auto conv = gcdconv(x, y); for (int i = 1; i <= n; ++i) { - for (int j = 1; j <= n; ++j) z[__gcd(i, j)] += x[i] * y[j]; + for (int j = 1; j <= n; ++j) z[gcd(i, j)] += x[i] * y[j]; } assert(conv == z); } @@ -91,7 +92,7 @@ void test_lcmconv() { auto conv = lcmconv(x, y); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { - int l = i * j / __gcd(i, j); + int l = i * j / gcd(i, j); if (l <= n) z[l] += x[i] * y[j]; } }