結果

問題 No.1493 隣接xor
ユーザー 👑 obakyanobakyan
提出日時 2021-12-04 18:12:18
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 606 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 18,256 KB
最終ジャッジ日時 2024-07-07 00:36:49
合計ジャッジ時間 3,911 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

local mod = 1000000007
local mfl = math.floor
local bxor = bit.bxor

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local asum = {a[1]}
for i = 2, n do
  asum[i] = bxor(asum[i - 1], a[i])
end

local summap = {}
local t = {}
t[0] = 1

local ts = 1

for i = 1, n do
  if summap[asum[i - 1]] then
    ts = bsub(ts, t[summap[asum[i - 1]]])
  end
  t[i] = ts
  ts = badd(ts, t[i])

  if 1 < i then
    summap[asum[i - 1]] = i - 1
  end

end
print(t[n])
0