local mfl, mce, mmi = math.floor, math.ceil, math.min local SegTree = {} SegTree.updateAll = function(self) for i = self.stagenum - 1, 1, -1 do for j = 1, self.cnt[i] do self.stage[i][j] = self.stage[i + 1][j * 2 - 1] + self.stage[i + 1][j * 2] end end end SegTree.create = function(self, n) self.func = func local stagenum, mul = 1, 1 self.cnt, self.stage, self.size = {1}, {{}}, {} while mul < n do mul, stagenum = mul * 2, stagenum + 1 self.cnt[stagenum], self.stage[stagenum] = mul, {} end for i = 1, stagenum do self.size[i] = self.cnt[stagenum + 1 - i] end self.stagenum = stagenum for i = 1, mul do self.stage[stagenum][i] = 0 end self:updateAll() end SegTree.add = function(self, idx, value) self.stage[self.stagenum][idx] = self.stage[self.stagenum][idx] + value for i = self.stagenum - 1, 1, -1 do local dst = mce(idx / 2) local rem = dst * 4 - 1 - idx self.stage[i][dst] = self.stage[i + 1][idx] + self.stage[i + 1][rem] idx = dst end end SegTree.lower_bound = function(self, val) local ret, retpos = 0, 0 local stage, l, r = 1, 1, self.size[1] while true do local sz = self.size[stage] local tmp = 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) local obj = {} setmetatable(obj, {__index = SegTree}) obj:create(n) return obj end local function lltonumber(str) local ret = 0LL for i = 1, #str do ret = ret * 10LL ret = ret + tonumber(str:sub(i, i)) end return ret end local function llprint(llnumber) local str = tostring(llnumber):gsub("LL", "") print(str) end local q, k = io.read("*n", "*n", "*l") local tasks = {} local nums = {} local numuniq = {} for i = 1, q do local str = io.read() if str:sub(1, 1) == "1" then table.insert(tasks, true) local numstr = str:sub(3, #str) local tmp = "" for i = 1, 19 - #numstr do tmp = tmp .. "0" end numstr = tmp .. numstr table.insert(tasks, numstr) if not numuniq[numstr] then table.insert(nums, numstr) numuniq[numstr] = true end else table.insert(tasks, false) end end table.sort(nums) local nummap = {} for i = 1, #nums do nummap[nums[i]] = i end local st = SegTree.new(#nums) local done = 0 local curcnt = 0 while done < #tasks do done = done + 1 if tasks[done] then done = done + 1 local num = tasks[done] local pos = nummap[num] st:add(pos, 1) curcnt = curcnt + 1 else if curcnt < k then print(-1) else local pos = st:lower_bound(k) local llnum = lltonumber(nums[pos]) llprint(llnum) st:add(pos, -1) curcnt = curcnt - 1 end end end