Hashiryo's Library

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub hashiryo/Library

:heavy_check_mark: test/yukicoder/2294.UFPU.test.cpp

Depends on

Code

// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/2294
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
#include <iostream>
#include <vector>
#include <array>
#include "src/DataStructure/UnionFind_Potentialized_Undoable.hpp"
#include "src/Math/ModInt.hpp"
#include "src/Math/Nimber.hpp"
using namespace std;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
 using Mint= ModInt<998244353>;
 Nimber::init();
 int N, X, Q;
 cin >> N >> X >> Q;
 UnionFind_Potentialized_Undoable<Nimber> uf(N);
 vector<array<int, 30>> cnt(N);
 while (Q--) {
  int t;
  cin >> t;
  if (t == 1) {
   int v, w;
   cin >> v >> w;
   int a= uf.leader(X), b= uf.leader(v);
   int as= uf.size(X), bs= uf.size(v);
   w^= uf.diff(v, X).val();
   uf.unite(a, b, w);
   if (a != uf.leader(a)) swap(a, b), swap(as, bs);
   for (int i= 30; i--;) {
    if ((w >> i) & 1) cnt[a][i]+= bs - cnt[b][i];
    else cnt[a][i]+= cnt[b][i];
   }
  } else if (t == 2) {
   int u, v;
   cin >> u >> v;
   if (uf.connected(u, v)) {
    int ans= uf.diff(u, v).val();
    cout << ans << '\n';
    X+= ans;
    X%= N;
   } else cout << -1 << '\n';
  } else if (t == 3) {
   int v;
   cin >> v;
   v= uf.leader(v);
   Mint ans= 0;
   for (int i= 30; i--;) ans+= Mint(cnt[v][i]) * (uf.size(v) - cnt[v][i]) * (1 << i);
   cout << ans << '\n';
  } else {
   int value;
   cin >> value;
   X+= value;
   X%= N;
  }
 }
 return 0;
}
#line 1 "test/yukicoder/2294.UFPU.test.cpp"
// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/2294
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
#include <iostream>
#include <vector>
#include <array>
#line 3 "src/DataStructure/UnionFind_Potentialized_Undoable.hpp"
#include <algorithm>
#include <cassert>
template <class weight_t> class UnionFind_Potentialized_Undoable {
 std::vector<int> par;
 std::vector<weight_t> val;
 std::vector<std::tuple<int, int, weight_t, int>> his;
 int cur;
public:
 UnionFind_Potentialized_Undoable(int n): par(n, -1), val(n), his{{-1, -1, weight_t(), 1}}, cur(0) { his.reserve(n + 1); }
 int leader(int u) const { return par[u] < 0 ? u : leader(par[u]); }
 //  -p(v) + p(u) = w
 bool unite(int u, int v, weight_t w) {
  if constexpr (std::is_same_v<weight_t, bool>) w^= potential(v) ^ potential(u);
  else w= potential(v) + w - potential(u);
  if (++cur; (u= leader(u)) == (v= leader(v))) return ++std::get<3>(his.back()), w == weight_t();
  if (par[v] > par[u]) std::swap(u, v), w= -w;
  return his.emplace_back(u, par[u], val[u], 1), par[v]+= par[u], par[u]= v, val[u]= w, true;
 }
 bool connected(int u, int v) { return leader(u) == leader(v); }
 int size(int u) { return -par[leader(u)]; }
 weight_t potential(int u) {
  if (par[u] < 0) return val[u];
  if constexpr (std::is_same_v<weight_t, bool>) return potential(par[u]) ^ val[u];
  else return potential(par[u]) + val[u];
 }
 //  -p(v) + p(u)
 weight_t diff(int u, int v) {
  if constexpr (std::is_same_v<weight_t, bool>) return potential(u) ^ potential(v);
  else return -potential(v) + potential(u);
 }
 int time() const { return cur; }
 void undo() {
  if (assert(cur > 0), --cur; --std::get<3>(his.back()) == 0) {
   auto [u, p, v, _]= his.back();
   par[par[u]]-= p, par[u]= p, val[u]= v, his.pop_back();
  }
 }
 void rollback(int t) {
  assert(0 <= t), assert(t <= cur);
  if (t == cur) return;
  for (;;) {
   auto &[u, p, v, i]= his.back();
   if (cur-= i; cur < t) {
    i= t - cur, cur= t;
    break;
   }
   par[par[u]]-= p, par[u]= p, val[u]= v, his.pop_back();
  }
 }
};
#line 2 "src/Math/mod_inv.hpp"
#include <utility>
#include <type_traits>
#line 5 "src/Math/mod_inv.hpp"
template <class Uint> constexpr inline Uint mod_inv(Uint a, Uint mod) {
 std::make_signed_t<Uint> x= 1, y= 0, z= 0;
 for (Uint q= 0, b= mod, c= 0; b;) z= x, x= y, y= z - y * (q= a / b), c= a, a= b, b= c - b * q;
 return assert(a == 1), x < 0 ? mod - (-x) % mod : x % mod;
}
#line 2 "src/Internal/Remainder.hpp"
namespace math_internal {
using namespace std;
using u8= unsigned char;
using u32= unsigned;
using i64= long long;
using u64= unsigned long long;
using u128= __uint128_t;
struct MP_Na {  // mod < 2^32
 u32 mod;
 constexpr MP_Na(): mod(0) {}
 constexpr MP_Na(u32 m): mod(m) {}
 constexpr inline u32 mul(u32 l, u32 r) const { return u64(l) * r % mod; }
 constexpr inline u32 set(u32 n) const { return n; }
 constexpr inline u32 get(u32 n) const { return n; }
 constexpr inline u32 norm(u32 n) const { return n; }
 constexpr inline u32 plus(u64 l, u32 r) const { return l+= r, l < mod ? l : l - mod; }
 constexpr inline u32 diff(u64 l, u32 r) const { return l-= r, l >> 63 ? l + mod : l; }
};
template <class u_t, class du_t, u8 B> struct MP_Mo {  // mod < 2^32, mod < 2^62
 u_t mod;
 constexpr MP_Mo(): mod(0), iv(0), r2(0) {}
 constexpr MP_Mo(u_t m): mod(m), iv(inv(m)), r2(-du_t(mod) % mod) {}
 constexpr inline u_t mul(u_t l, u_t r) const { return reduce(du_t(l) * r); }
 constexpr inline u_t set(u_t n) const { return mul(n, r2); }
 constexpr inline u_t get(u_t n) const { return n= reduce(n), n >= mod ? n - mod : n; }
 constexpr inline u_t norm(u_t n) const { return n >= mod ? n - mod : n; }
 constexpr inline u_t plus(u_t l, u_t r) const { return l+= r, l < (mod << 1) ? l : l - (mod << 1); }
 constexpr inline u_t diff(u_t l, u_t r) const { return l-= r, l >> (B - 1) ? l + (mod << 1) : l; }
private:
 u_t iv, r2;
 static constexpr u_t inv(u_t n, int e= 6, u_t x= 1) { return e ? inv(n, e - 1, x * (2 - x * n)) : x; }
 constexpr inline u_t reduce(const du_t &w) const { return u_t(w >> B) + mod - ((du_t(u_t(w) * iv) * mod) >> B); }
};
using MP_Mo32= MP_Mo<u32, u64, 32>;
using MP_Mo64= MP_Mo<u64, u128, 64>;
struct MP_Br {  // 2^20 < mod <= 2^41
 u64 mod;
 constexpr MP_Br(): mod(0), x(0) {}
 constexpr MP_Br(u64 m): mod(m), x((u128(1) << 84) / m) {}
 constexpr inline u64 mul(u64 l, u64 r) const { return rem(u128(l) * r); }
 static constexpr inline u64 set(u64 n) { return n; }
 constexpr inline u64 get(u64 n) const { return n >= mod ? n - mod : n; }
 constexpr inline u64 norm(u64 n) const { return n >= mod ? n - mod : n; }
 constexpr inline u64 plus(u64 l, u64 r) const { return l+= r, l < (mod << 1) ? l : l - (mod << 1); }
 constexpr inline u64 diff(u64 l, u64 r) const { return l-= r, l >> 63 ? l + (mod << 1) : l; }
private:
 u64 x;
 constexpr inline u128 quo(const u128 &n) const { return (n * x) >> 84; }
 constexpr inline u64 rem(const u128 &n) const { return n - quo(n) * mod; }
};
template <class du_t, u8 B> struct MP_D2B1 {  // mod < 2^63, mod < 2^64
 u64 mod;
 constexpr MP_D2B1(): mod(0), s(0), d(0), v(0) {}
 constexpr MP_D2B1(u64 m): mod(m), s(__builtin_clzll(m)), d(m << s), v(u128(-1) / d) {}
 constexpr inline u64 mul(u64 l, u64 r) const { return rem((u128(l) * r) << s) >> s; }
 constexpr inline u64 set(u64 n) const { return n; }
 constexpr inline u64 get(u64 n) const { return n; }
 constexpr inline u64 norm(u64 n) const { return n; }
 constexpr inline u64 plus(du_t l, u64 r) const { return l+= r, l < mod ? l : l - mod; }
 constexpr inline u64 diff(du_t l, u64 r) const { return l-= r, l >> B ? l + mod : l; }
private:
 u8 s;
 u64 d, v;
 constexpr inline u64 rem(const u128 &u) const {
  u128 q= (u >> 64) * v + u;
  u64 r= u64(u) - (q >> 64) * d - d;
  if (r > u64(q)) r+= d;
  if (r >= d) r-= d;
  return r;
 }
};
using MP_D2B1_1= MP_D2B1<u64, 63>;
using MP_D2B1_2= MP_D2B1<u128, 127>;
template <class u_t, class MP> constexpr u_t pow(u_t x, u64 k, const MP &md) {
 for (u_t ret= md.set(1);; x= md.mul(x, x))
  if (k & 1 ? ret= md.mul(ret, x) : 0; !(k>>= 1)) return ret;
}
}
#line 3 "src/Internal/modint_traits.hpp"
namespace math_internal {
struct m_b {};
struct s_b: m_b {};
}
template <class mod_t> constexpr bool is_modint_v= std::is_base_of_v<math_internal::m_b, mod_t>;
template <class mod_t> constexpr bool is_staticmodint_v= std::is_base_of_v<math_internal::s_b, mod_t>;
#line 6 "src/Math/ModInt.hpp"
namespace math_internal {
template <class MP, u64 MOD> struct SB: s_b {
protected:
 static constexpr MP md= MP(MOD);
};
template <class U, class B> struct MInt: public B {
 using Uint= U;
 static constexpr inline auto mod() { return B::md.mod; }
 constexpr MInt(): x(0) {}
 template <class T, typename= enable_if_t<is_modint_v<T> && !is_same_v<T, MInt>>> constexpr MInt(T v): x(B::md.set(v.val() % B::md.mod)) {}
 constexpr MInt(__int128_t n): x(B::md.set((n < 0 ? ((n= (-n) % B::md.mod) ? B::md.mod - n : n) : n % B::md.mod))) {}
 constexpr MInt operator-() const { return MInt() - *this; }
#define FUNC(name, op) \
 constexpr MInt name const { \
  MInt ret; \
  return ret.x= op, ret; \
 }
 FUNC(operator+(const MInt & r), B::md.plus(x, r.x))
 FUNC(operator-(const MInt & r), B::md.diff(x, r.x))
 FUNC(operator*(const MInt & r), B::md.mul(x, r.x))
 FUNC(pow(u64 k), math_internal::pow(x, k, B::md))
#undef FUNC
 constexpr MInt operator/(const MInt &r) const { return *this * r.inv(); }
 constexpr MInt &operator+=(const MInt &r) { return *this= *this + r; }
 constexpr MInt &operator-=(const MInt &r) { return *this= *this - r; }
 constexpr MInt &operator*=(const MInt &r) { return *this= *this * r; }
 constexpr MInt &operator/=(const MInt &r) { return *this= *this / r; }
 constexpr bool operator==(const MInt &r) const { return B::md.norm(x) == B::md.norm(r.x); }
 constexpr bool operator!=(const MInt &r) const { return !(*this == r); }
 constexpr bool operator<(const MInt &r) const { return B::md.norm(x) < B::md.norm(r.x); }
 constexpr inline MInt inv() const { return mod_inv<U>(val(), B::md.mod); }
 constexpr inline Uint val() const { return B::md.get(x); }
 friend ostream &operator<<(ostream &os, const MInt &r) { return os << r.val(); }
 friend istream &operator>>(istream &is, MInt &r) {
  i64 v;
  return is >> v, r= MInt(v), is;
 }
private:
 Uint x;
};
template <u64 MOD> using MP_B= conditional_t < (MOD < (1 << 30)) & MOD, MP_Mo32, conditional_t < MOD < (1ull << 32), MP_Na, conditional_t<(MOD < (1ull << 62)) & MOD, MP_Mo64, conditional_t<MOD<(1ull << 41), MP_Br, conditional_t<MOD<(1ull << 63), MP_D2B1_1, MP_D2B1_2>>>>>;
template <u64 MOD> using ModInt= MInt < conditional_t<MOD<(1 << 30), u32, u64>, SB<MP_B<MOD>, MOD>>;
}
using math_internal::ModInt;
#line 2 "src/Math/Nimber.hpp"
#include <numeric>
#line 5 "src/Math/Nimber.hpp"
class Nimber {
 using u64= unsigned long long;
 using u32= unsigned;
 using u16= unsigned short;
 static inline u16 pw[65536], ln[65536];
 template <u16 h= 3> static inline u16 half(u16 A) { return A ? pw[(ln[A] + h) % 65535] : 0; }
 template <u16 h= 0> static inline u16 mul(u16 A, u16 B) { return A && B ? pw[(ln[A] + ln[B] + h) % 65535] : 0; }
 template <u16 h= 0> static inline u16 mul(u16 A, u16 B, u16 C) { return A && B && C ? pw[(ln[A] + ln[B] + ln[C] + h) % 65535] : 0; }
 static inline u16 inv(u16 A) { return assert(A), pw[65535 - ln[A]]; }
 static inline u16 sqrt(u16 A) { return A ? pw[u16((65537 * u32(ln[A])) >> 1)] : 0; }
 static inline u64 mul(u64 A, u64 B) {
  u16 a0= u16(A), a1= u16(A >> 16), a2= u16(A >> 32), a3= A >> 48, b0= u16(B), b1= u16(B >> 16), b2= u16(B >> 32), b3= B >> 48, x0= a1 ^ a0, x1= a3 ^ a2, y0= b1 ^ b0, y1= b3 ^ b2, c0= mul(a0, b0), c1= mul(x0, y0) ^ c0, c2= mul<0>(a2 ^ a0, b2 ^ b0), c3= mul<0>(x0 ^ x1, y0 ^ y1) ^ c2 ^ c1;
  return c2^= (c0^= mul<3>(a1, b1)) ^ mul<3>(u16(a3 ^ a1), u16(b3 ^ b1)), c1^= mul<6>(a3, b3) ^ mul<3>(x1, y1), c0^= mul<6>(a2, b2) ^ mul<6>(x1, y1), (u64(c3) << 48) | (u64(c2) << 32) | (u32(c1) << 16) | c0;
 }
 static inline u64 inv(u64 A) {
  u16 a0= u16(A), a1= u16(A >> 16), a2= u16(A >> 32), a3= A >> 48, x= a2 ^ a3, y= a1 ^ a3, w= a0 ^ a2, v= a0 ^ a1, b3= mul(a1, a2, a1 ^ x), b2= mul(a0, a2, a0 ^ x), b1= mul(a0, a1, a0 ^ y), b0= mul(a0, v, w), t= mul<3>(w, x, x);
  return b0^= b1 ^ b2, b1^= b3, b2^= b3, b0^= b3^= mul(a0, a0, a3), b1^= t ^ mul<3>(a1, y, y), b0^= t ^ mul<3>(v, y, y), b3^= t= mul<3>(a1, a3, y) ^ mul<3>(a2, x, x), b2^= t ^ mul<3>(a0, a3, a3) ^ mul<3>(a1, a1, a2), b3^= mul<6>(a3, a3, x), b2^= mul<6>(a3, x, x), b1^= mul<6>(a3, a3, y ^ w), b0^= mul<6>(y, x, x), b2^= mul<9>(a3, a3, a3), b0^= mul<9>(a3, a3, y), t= mul<6>(x, b3) ^ mul<6>(a3, b2) ^ mul<3>(a1, b1) ^ mul(a0, b0), t= inv(t), (u64(mul(b3, t)) << 48) | (u64(mul(b2, t)) << 32) | (u32(mul(b1, t)) << 16) | mul(b0, t);
 }
 static inline u64 square(u64 A) {
  u16 a0= u16(A), a1= u16(A >> 16), a2= u16(A >> 32), a3= A >> 48;
  return a3= mul(a3, a3), a2= mul(a2, a2), a1= mul(a1, a1), a0= mul(a0, a0), a0^= half(a1) ^ half<6>(a3), a2^= half(a3), a1^= half(a3 ^ a2), (u64(a3) << 48) | (u64(a2) << 32) | (u32(a1) << 16) | a0;
 }
 static inline u64 pow(u64 A, u64 k) {
  for (u64 ret= 1;; A= square(A))
   if (k & 1 ? ret= mul(ret, A) : 0; !(k>>= 1)) return ret;
 }
 template <int mod> static inline int mdif(int a, int b) { return a+= mod & -((a-= b) < 0); }
 template <int mod> static inline int mmul(int a, int b) { return u64(a) * b % mod; }
 static inline int log16(u16 A, u16 B) {
  int a= ln[A], b= ln[B], x= 1;
  if (a == 0) return b == 0 ? 1 : -1;
  for (int q, z, u, y= 0, t= 65535; t;) z= x, u= a, x= y, y= z - y * (q= a / t), a= t, t= u - t * q;
  return b % a ? -1 : u32(b / a) * (x < 0 ? 65535 + x : x) % 65535;
 }
 template <int period, int size> static inline int bsgs(u64 x, u64 y) {
  static constexpr int mask= size - 1;
  std::pair<u64, int> vs[size];
  int os[size + 1]= {};
  u64 so[size], big= 1;
  for (int i= 0; i < size; ++i, big= mul(big, x)) ++os[(so[i]= big) & mask];
  for (int i= 0; i < size; ++i) os[i + 1]+= os[i];
  for (int i= 0; i < size; ++i) vs[--os[so[i] & mask]]= {so[i], i};
  for (int t= 0; t < period; t+= size, y= mul(y, big))
   for (int m= (y & mask), i= os[m], ret; i < os[m + 1]; ++i)
    if (y == vs[i].first) return (ret= vs[i].second - t) < 0 ? ret + period : ret;
  return -1;
 }
 static inline u64 log(u64 A, u64 B) {
  if (B == 1) return 0;
  if (!A && !B) return 1;
  if (!A || !B) return u64(-1);
  static constexpr int P0= 641, P1= 65535, P2= 65537, P3= 6700417, iv10= 40691, iv21= 32768, iv20= 45242, iv32= 3317441, iv31= 3350208, iv30= 3883315;
  int a0= bsgs<P0, 16>(pow(A, 0x663d80ff99c27f), pow(B, 0x663d80ff99c27f));
  if (a0 == -1) return u64(-1);
  int a1= log16(pow(A, 0x1000100010001), pow(B, 0x1000100010001));
  if (a1 == -1) return u64(-1);
  int a2= bsgs<P2, 256>(pow(A, 0xffff0000ffff), pow(B, 0xffff0000ffff));
  if (a2 == -1) return u64(-1);
  int a3= bsgs<P3, 2048>(pow(A, 0x280fffffd7f), pow(B, 0x280fffffd7f));
  if (a3 == -1) return u64(-1);
  int x1= mmul<P1>(mdif<P1>(a1, a0), iv10), x2= mdif<P2>(mmul<P2>(mdif<P2>(a2, a0), iv20), mmul<P2>(x1, iv21)), x3= mdif<P3>(mdif<P3>(mmul<P3>(mdif<P3>(a3, a0), iv30), mmul<P3>(x1, iv31)), mmul<P3>(x2, iv32));
  return u64(P0) * (u64(P1) * (u64(P2) * x3 + x2) + x1) + a0;
 }
 u64 x;
public:
 static inline void init(u32 x= 0, u32 y= 0) {
  constexpr u16 f2n[16]= {0x0001u, 0x2827u, 0x392bu, 0x8000u, 0x20fdu, 0x4d1du, 0xde4au, 0x0a17u, 0x3464u, 0xe3a9u, 0x6d8du, 0x34bcu, 0xa921u, 0xa173u, 0x0ebcu, 0x0e69u};
  for (int i= pw[0]= pw[65535]= 1; i < 65535; ++i) pw[i]= (pw[i - 1] << 1) ^ (0x1681fu & (-(pw[i - 1] >= 0x8000u)));
  for (int i= 1; i < 65535; ln[pw[i]= y]= i, i++)
   for (x= pw[i], y= 0; x; x&= x - 1) y^= f2n[__builtin_ctz(x)];
 }
 Nimber(u64 x_= 0): x(x_) {}
 Nimber &operator+=(const Nimber &r) { return x^= r.x, *this; }
 Nimber &operator-=(const Nimber &r) { return x^= r.x, *this; }
 Nimber &operator*=(const Nimber &r) { return x= mul(x, r.x), *this; }
 Nimber &operator/=(const Nimber &r) { return x= mul(x, inv(r.x)), *this; }
 Nimber operator+(const Nimber &r) const { return Nimber(x ^ r.x); }
 Nimber operator-(const Nimber &r) const { return Nimber(x ^ r.x); }
 Nimber operator*(const Nimber &r) const { return Nimber(mul(x, r.x)); }
 Nimber operator/(const Nimber &r) const { return Nimber(mul(x, inv(r.x))); }
 Nimber operator-() const { return *this; }
 Nimber inv() const { return Nimber(inv(x)); }
 Nimber square() const { return Nimber(square(x)); }
 Nimber sqrt() const {
  u16 a0= u16(x), a1= u16(x >> 16), a2= u16(x >> 32), a3= x >> 48;
  return a1^= half(a3 ^ a2), a2^= half(a3), a0^= half(a1) ^ half<6>(a3), Nimber((u64(sqrt(a3)) << 48) | (u64(sqrt(a2)) << 32) | (u32(sqrt(a1)) << 16) | sqrt(a0));
 }
 u64 val() const { return x; }
 Nimber pow(u64 k) const { return Nimber(pow(x, k)); }
 u64 log(const Nimber &r) const { return log(x, r.x); }
 bool operator==(const Nimber &r) const { return x == r.x; }
 bool operator!=(const Nimber &r) const { return x != r.x; }
 bool operator<(const Nimber &r) const { return x < r.x; }
 bool operator>(const Nimber &r) const { return x > r.x; }
 bool operator<=(const Nimber &r) const { return x <= r.x; }
 bool operator>=(const Nimber &r) const { return x >= r.x; }
 friend std::ostream &operator<<(std::ostream &os, const Nimber &r) { return os << r.x; }
 friend std::istream &operator>>(std::istream &is, Nimber &r) { return is >> r.x, is; }
};
#line 10 "test/yukicoder/2294.UFPU.test.cpp"
using namespace std;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
 using Mint= ModInt<998244353>;
 Nimber::init();
 int N, X, Q;
 cin >> N >> X >> Q;
 UnionFind_Potentialized_Undoable<Nimber> uf(N);
 vector<array<int, 30>> cnt(N);
 while (Q--) {
  int t;
  cin >> t;
  if (t == 1) {
   int v, w;
   cin >> v >> w;
   int a= uf.leader(X), b= uf.leader(v);
   int as= uf.size(X), bs= uf.size(v);
   w^= uf.diff(v, X).val();
   uf.unite(a, b, w);
   if (a != uf.leader(a)) swap(a, b), swap(as, bs);
   for (int i= 30; i--;) {
    if ((w >> i) & 1) cnt[a][i]+= bs - cnt[b][i];
    else cnt[a][i]+= cnt[b][i];
   }
  } else if (t == 2) {
   int u, v;
   cin >> u >> v;
   if (uf.connected(u, v)) {
    int ans= uf.diff(u, v).val();
    cout << ans << '\n';
    X+= ans;
    X%= N;
   } else cout << -1 << '\n';
  } else if (t == 3) {
   int v;
   cin >> v;
   v= uf.leader(v);
   Mint ans= 0;
   for (int i= 30; i--;) ans+= Mint(cnt[v][i]) * (uf.size(v) - cnt[v][i]) * (1 << i);
   cout << ans << '\n';
  } else {
   int value;
   cin >> value;
   X+= value;
   X%= N;
  }
 }
 return 0;
}

Test cases

Env Name Status Elapsed Memory
g++-13 00_sample01.txt :heavy_check_mark: AC 7 ms 4 MB
g++-13 00_sample02.txt :heavy_check_mark: AC 6 ms 4 MB
g++-13 00_sample03.txt :heavy_check_mark: AC 6 ms 4 MB
g++-13 01_test01.txt :heavy_check_mark: AC 119 ms 34 MB
g++-13 01_test02.txt :heavy_check_mark: AC 115 ms 21 MB
g++-13 01_test03.txt :heavy_check_mark: AC 111 ms 19 MB
g++-13 01_test04.txt :heavy_check_mark: AC 91 ms 34 MB
g++-13 01_test05.txt :heavy_check_mark: AC 93 ms 34 MB
g++-13 01_test06.txt :heavy_check_mark: AC 142 ms 34 MB
g++-13 01_test07.txt :heavy_check_mark: AC 144 ms 34 MB
g++-13 01_test08.txt :heavy_check_mark: AC 93 ms 34 MB
g++-13 01_test09.txt :heavy_check_mark: AC 92 ms 34 MB
g++-13 01_test10.txt :heavy_check_mark: AC 93 ms 34 MB
g++-13 01_test11.txt :heavy_check_mark: AC 125 ms 34 MB
g++-13 02_binary01.txt :heavy_check_mark: AC 72 ms 32 MB
g++-13 02_binary02.txt :heavy_check_mark: AC 71 ms 34 MB
g++-13 02_binary03.txt :heavy_check_mark: AC 98 ms 32 MB
g++-13 02_binary04.txt :heavy_check_mark: AC 70 ms 34 MB
g++-13 02_binary05.txt :heavy_check_mark: AC 78 ms 34 MB
g++-13 02_binary06.txt :heavy_check_mark: AC 85 ms 34 MB
g++-13 02_binary07.txt :heavy_check_mark: AC 89 ms 32 MB
g++-13 02_binary08.txt :heavy_check_mark: AC 90 ms 32 MB
g++-13 02_binary09.txt :heavy_check_mark: AC 104 ms 34 MB
g++-13 02_binary10.txt :heavy_check_mark: AC 78 ms 34 MB
g++-13 02_binary11.txt :heavy_check_mark: AC 75 ms 34 MB
g++-13 03_small01.txt :heavy_check_mark: AC 7 ms 4 MB
g++-13 03_small02.txt :heavy_check_mark: AC 6 ms 4 MB
g++-13 03_small03.txt :heavy_check_mark: AC 6 ms 4 MB
g++-13 04_rand1.txt :heavy_check_mark: AC 109 ms 5 MB
g++-13 04_rand10.txt :heavy_check_mark: AC 116 ms 19 MB
g++-13 04_rand11.txt :heavy_check_mark: AC 119 ms 20 MB
g++-13 04_rand12.txt :heavy_check_mark: AC 118 ms 22 MB
g++-13 04_rand13.txt :heavy_check_mark: AC 123 ms 24 MB
g++-13 04_rand14.txt :heavy_check_mark: AC 120 ms 24 MB
g++-13 04_rand15.txt :heavy_check_mark: AC 125 ms 26 MB
g++-13 04_rand16.txt :heavy_check_mark: AC 121 ms 28 MB
g++-13 04_rand17.txt :heavy_check_mark: AC 122 ms 29 MB
g++-13 04_rand18.txt :heavy_check_mark: AC 121 ms 30 MB
g++-13 04_rand19.txt :heavy_check_mark: AC 121 ms 32 MB
g++-13 04_rand2.txt :heavy_check_mark: AC 123 ms 7 MB
g++-13 04_rand20.txt :heavy_check_mark: AC 123 ms 34 MB
g++-13 04_rand3.txt :heavy_check_mark: AC 113 ms 8 MB
g++-13 04_rand4.txt :heavy_check_mark: AC 113 ms 10 MB
g++-13 04_rand5.txt :heavy_check_mark: AC 119 ms 11 MB
g++-13 04_rand6.txt :heavy_check_mark: AC 114 ms 13 MB
g++-13 04_rand7.txt :heavy_check_mark: AC 117 ms 14 MB
g++-13 04_rand8.txt :heavy_check_mark: AC 121 ms 16 MB
g++-13 04_rand9.txt :heavy_check_mark: AC 118 ms 17 MB
g++-13 05_overflow01.txt :heavy_check_mark: AC 64 ms 34 MB
clang++-18 00_sample01.txt :heavy_check_mark: AC 6 ms 4 MB
clang++-18 00_sample02.txt :heavy_check_mark: AC 6 ms 4 MB
clang++-18 00_sample03.txt :heavy_check_mark: AC 6 ms 4 MB
clang++-18 01_test01.txt :heavy_check_mark: AC 110 ms 34 MB
clang++-18 01_test02.txt :heavy_check_mark: AC 110 ms 21 MB
clang++-18 01_test03.txt :heavy_check_mark: AC 109 ms 19 MB
clang++-18 01_test04.txt :heavy_check_mark: AC 92 ms 34 MB
clang++-18 01_test05.txt :heavy_check_mark: AC 94 ms 34 MB
clang++-18 01_test06.txt :heavy_check_mark: AC 141 ms 34 MB
clang++-18 01_test07.txt :heavy_check_mark: AC 140 ms 34 MB
clang++-18 01_test08.txt :heavy_check_mark: AC 94 ms 34 MB
clang++-18 01_test09.txt :heavy_check_mark: AC 93 ms 34 MB
clang++-18 01_test10.txt :heavy_check_mark: AC 93 ms 34 MB
clang++-18 01_test11.txt :heavy_check_mark: AC 123 ms 34 MB
clang++-18 02_binary01.txt :heavy_check_mark: AC 71 ms 34 MB
clang++-18 02_binary02.txt :heavy_check_mark: AC 67 ms 34 MB
clang++-18 02_binary03.txt :heavy_check_mark: AC 112 ms 32 MB
clang++-18 02_binary04.txt :heavy_check_mark: AC 71 ms 34 MB
clang++-18 02_binary05.txt :heavy_check_mark: AC 79 ms 34 MB
clang++-18 02_binary06.txt :heavy_check_mark: AC 88 ms 34 MB
clang++-18 02_binary07.txt :heavy_check_mark: AC 94 ms 32 MB
clang++-18 02_binary08.txt :heavy_check_mark: AC 96 ms 32 MB
clang++-18 02_binary09.txt :heavy_check_mark: AC 105 ms 34 MB
clang++-18 02_binary10.txt :heavy_check_mark: AC 76 ms 34 MB
clang++-18 02_binary11.txt :heavy_check_mark: AC 76 ms 34 MB
clang++-18 03_small01.txt :heavy_check_mark: AC 6 ms 4 MB
clang++-18 03_small02.txt :heavy_check_mark: AC 6 ms 4 MB
clang++-18 03_small03.txt :heavy_check_mark: AC 6 ms 4 MB
clang++-18 04_rand1.txt :heavy_check_mark: AC 108 ms 5 MB
clang++-18 04_rand10.txt :heavy_check_mark: AC 116 ms 19 MB
clang++-18 04_rand11.txt :heavy_check_mark: AC 118 ms 20 MB
clang++-18 04_rand12.txt :heavy_check_mark: AC 119 ms 22 MB
clang++-18 04_rand13.txt :heavy_check_mark: AC 119 ms 23 MB
clang++-18 04_rand14.txt :heavy_check_mark: AC 118 ms 24 MB
clang++-18 04_rand15.txt :heavy_check_mark: AC 121 ms 27 MB
clang++-18 04_rand16.txt :heavy_check_mark: AC 124 ms 28 MB
clang++-18 04_rand17.txt :heavy_check_mark: AC 123 ms 29 MB
clang++-18 04_rand18.txt :heavy_check_mark: AC 124 ms 30 MB
clang++-18 04_rand19.txt :heavy_check_mark: AC 123 ms 32 MB
clang++-18 04_rand2.txt :heavy_check_mark: AC 114 ms 7 MB
clang++-18 04_rand20.txt :heavy_check_mark: AC 120 ms 34 MB
clang++-18 04_rand3.txt :heavy_check_mark: AC 116 ms 8 MB
clang++-18 04_rand4.txt :heavy_check_mark: AC 112 ms 10 MB
clang++-18 04_rand5.txt :heavy_check_mark: AC 115 ms 11 MB
clang++-18 04_rand6.txt :heavy_check_mark: AC 115 ms 13 MB
clang++-18 04_rand7.txt :heavy_check_mark: AC 123 ms 14 MB
clang++-18 04_rand8.txt :heavy_check_mark: AC 116 ms 16 MB
clang++-18 04_rand9.txt :heavy_check_mark: AC 119 ms 17 MB
clang++-18 05_overflow01.txt :heavy_check_mark: AC 121 ms 34 MB
Back to top page