結果

問題 No.1876 Xor of Sum
ユーザー obakyan
提出日時 2022-03-16 09:43:04
言語 Lua
(LuaJit 2.1.1774638290)
コンパイル:
luajit -b _filename_ a.out
実行:
luajit _filename_
結果
AC  
実行時間 1,245 ms / 2,000 ms
コード長 1,557 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 91 ms
コンパイル使用メモリ 8,096 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-04-11 11:31:39
合計ジャッジ時間 21,755 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

local mfl, mce = math.floor, math.ceil
local bls, brs = bit.lshift, bit.rshift
local bor, band = bit.bor, bit.band
local bxor = bit.bxor
local TFDP = {}

TFDP.initialize = function(self, lim)
  self.lim = lim
  self.sz = 30
  self.way = true
  self.bcnt = mce((lim + 1) / self.sz)
  self.b1, self.b2 = {1}, {}
  for i = 2, self.bcnt do
    self.b1[i] = 0
    self.b2[i] = 0
  end
  self.curmax = 0
end

TFDP.add = function(self, v, cursum)
  local src = self.way and self.b1 or self.b2
  local dst = self.way and self.b2 or self.b1
  self.way = not self.way
  local bcnt = self.bcnt
  local bc2 = mce((cursum + 1) / self.sz)
  for i = 1, bc2 do
    dst[i] = src[i]
  end
  local sz = self.sz
  local jump, rem = mfl(v / sz), v % sz
  local denom, mul = bls(1, sz - rem), bls(1, rem)
  for i = 1, bcnt - jump do
    local v1 = src[i] % denom
    dst[i + jump] = bxor(dst[i + jump], v1 * mul)
  end
  for i = 1, bcnt - jump - 1 do
    local v2 = brs(src[i], sz - rem)
    dst[i + jump + 1] = bxor(dst[i + jump + 1], v2)
  end
end

TFDP.query = function(self, x)
  local group = mfl(x / self.sz) + 1
  local idx = x - (group - 1) * self.sz
  local tbl = self.way and self.b1 or self.b2
  return band(tbl[group], bls(1, idx)) ~= 0
end

local tf = TFDP
local n = io.read("*n")
local lim = n * 2000
tf:initialize(lim)
local cursum = 0
for i = 1, n do
  local a = io.read("*n")
  tf:add(a, cursum)
  cursum = cursum + a
end
-- print(os.clock())
local ret = 0
for i = 1, lim do
  if tf:query(i) then
    ret = bxor(ret, i)
  end
end
print(ret)
-- print(os.clock())
0