結果
問題 |
No.1115 二つの数列 / Two Sequences
|
ユーザー |
👑 |
提出日時 | 2021-08-04 23:47:22 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 847 bytes |
コンパイル時間 | 50 ms |
コンパイル使用メモリ | 5,376 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 15:11:49 |
合計ジャッジ時間 | 2,431 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
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)