結果
問題 | No.1439 Let's Compare!!!! |
ユーザー | 👑 obakyan |
提出日時 | 2021-05-28 11:27:40 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 424 ms / 2,000 ms |
コード長 | 3,373 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 5,504 KB |
実行使用メモリ | 33,044 KB |
最終ジャッジ日時 | 2024-11-07 01:54:50 |
合計ジャッジ時間 | 5,321 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 3 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 7 ms
5,248 KB |
testcase_08 | AC | 11 ms
5,248 KB |
testcase_09 | AC | 6 ms
5,248 KB |
testcase_10 | AC | 316 ms
25,120 KB |
testcase_11 | AC | 424 ms
33,044 KB |
testcase_12 | AC | 385 ms
28,928 KB |
testcase_13 | AC | 316 ms
25,120 KB |
testcase_14 | AC | 318 ms
25,252 KB |
testcase_15 | AC | 312 ms
24,336 KB |
testcase_16 | AC | 227 ms
15,360 KB |
testcase_17 | AC | 221 ms
15,360 KB |
testcase_18 | AC | 184 ms
15,232 KB |
ソースコード
local mfl, mce = math.floor, math.ceil local mmi, mma = math.min, math.max local bls, brs = bit.lshift, bit.rshift local SegTree = {} SegTree.updateAll = function(self) for i = self.stagenum - 1, 1, -1 do local cnt = bls(1, i - 1) for j = 1, cnt do self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2]) end end end SegTree.create = function(self, n, func, emptyvalue) self.func, self.emptyvalue = func, emptyvalue local stagenum, mul = 1, 1 self.stage = {{}} while mul < n do mul, stagenum = mul * 2, stagenum + 1 self.stage[stagenum] = {} end self.stagenum = stagenum self.left_stage = {} for i = 1, n do local sp, sz = 1, bls(1, stagenum - 1) while(i - 1) % sz ~= 0 do sp, sz = sp + 1, brs(sz, 1) end self.left_stage[i] = sp end self.sz_stage = {} local tmp, sp = 1, stagenum for i = 1, n do if tmp * 2 == i then tmp, sp = tmp * 2, sp - 1 end self.sz_stage[i] = sp end for i = 1, mul do self.stage[stagenum][i] = emptyvalue end self:updateAll() end SegTree.getRange = function(self, left, right) if left == right then return self.stage[self.stagenum][left] end local stagenum = self.stagenum local ret = self.emptyvalue while left <= right do local stage = mma(self.left_stage[left], self.sz_stage[right - left + 1]) local sz = bls(1, stagenum - stage) ret = self.func(ret, self.stage[stage][1 + brs(left - 1, stagenum - stage)]) left = left + sz end return ret end SegTree.update = function(self, idx) for i = self.stagenum - 1, 1, -1 do local dst = brs(idx + 1, 1) local rem = dst * 4 - 1 - idx self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem]) idx = dst end end SegTree.setValue = function(self, idx, value, silent) self.stage[self.stagenum][idx] = value if not silent then self:update(idx) end end SegTree.lower_bound = function(self, val) local ret, retpos = self.emptyvalue, 0 local stagenum = self.stagenum local stage, l, r = 1, 1, bls(1, stagenum - 1) while true do local sz = bls(1, stagenum - stage) local tmp = self.func(ret, self.stage[stage][mce(l / sz)]) if tmp < val then ret, retpos = tmp, l + sz - 1 if l + sz <= r then stage, l = stage + 1, l + sz else break end else if sz ~= 1 then stage, r = stage + 1, l + sz - 2 else break end end end return retpos + 1 end SegTree.new = function(n, func, emptyvalue) local obj = {} setmetatable(obj, {__index = SegTree}) obj:create(n, func, emptyvalue) return obj end local n = io.read("*n", "*l") local s_str = io.read() local t_str = io.read() local s = {} local t = {} for i = 1, n do s[i] = s_str:byte(i) t[i] = t_str:byte(i) end local st = SegTree.new(n, bit.bor, 0) for i = 1, n do if s[i] ~= t[i] then st:setValue(i, 1, true) end end st:updateAll() local q = io.read("*n", "*l") for iq = 1, q do local tp, pos, val = io.read():match("(%w) (%d+) (%d+)") pos = tonumber(pos) if tp == "S" then s[pos] = val:byte() else t[pos] = val:byte() end if s[pos] == t[pos] then st:setValue(pos, 0) else st:setValue(pos, 1) end local lb = st:lower_bound(1) if n < lb then print("=") else if s[lb] < t[lb] then print("<") else print(">") end end end