結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー 👑 obakyanobakyan
提出日時 2021-08-04 23:47:22
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 28 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,460 KB
最終ジャッジ日時 2023-10-14 21:26:34
合計ジャッジ時間 2,545 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 56 ms
4,352 KB
testcase_04 AC 66 ms
4,460 KB
testcase_05 AC 57 ms
4,352 KB
testcase_06 AC 51 ms
4,404 KB
testcase_07 AC 64 ms
4,352 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 38 ms
4,352 KB
testcase_10 AC 66 ms
4,376 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 65 ms
4,376 KB
testcase_13 AC 65 ms
4,456 KB
testcase_14 AC 65 ms
4,456 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 7 ms
4,352 KB
testcase_24 AC 24 ms
4,348 KB
testcase_25 AC 49 ms
4,352 KB
testcase_26 AC 12 ms
4,352 KB
testcase_27 AC 29 ms
4,348 KB
testcase_28 AC 39 ms
4,348 KB
testcase_29 AC 51 ms
4,368 KB
testcase_30 AC 61 ms
4,348 KB
testcase_31 AC 17 ms
4,348 KB
testcase_32 AC 11 ms
4,348 KB
testcase_33 AC 55 ms
4,352 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 1 ms
4,352 KB
testcase_39 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local band = bit.band
local FenwickTree = {}
FenwickTree.create = function(self, n)
  self.n = n
  self.v = {}
  for i = 1, n do self.v[i] = 0 end
end
FenwickTree.add = function(self, pos, val)
  while pos <= self.n do
    self.v[pos] = self.v[pos] + val
    pos = pos + band(pos, -pos)
  end
end
FenwickTree.sum = function(self, r)
  local ret = 0
  while 0 < r do
    ret = ret + self.v[r]
    r = r - band(r, -r)
  end
  return ret
end
FenwickTree.new = function(n)
  local obj = {}
  setmetatable(obj, {__index = FenwickTree})
  obj:create(n)
  return obj
end

local n = io.read("*n")
local t = {}
for i = 1, n do t[i] = 0 end
for i = 1, n do
  local a = io.read("*n")
  t[a] = i
end
local ret = 0
local fw = FenwickTree.new(n)
for i = 1, n do
  local b = io.read("*n")
  b = t[b]
  ret = ret + i - 1 - fw:sum(b)
  fw:add(b, 1)
end
print(ret)
0