inf = 1 << 20 #頂点は1-index,下段は0-index class LazySegTree: #単位元と結合と作用をここで定義 Xunit = (-1,-inf,-inf,0,0,0) Aunit = (0,0) def Xf(self,x,y): return max(x,y) #Xf = max def Af(self,a,b): return (a[0]+b[0],a[1]+b[1]) #AのXへの作用 def operate(self,x,a): i,j,k,l,r,m = x return (i-a[0],j-a[1],k,l,r,m) def __init__(self,N): self.N = N self.X = [self.Xunit] * (N + N) self.A = [self.Aunit] * (N + N) def build(self,seq): for i,x in enumerate(seq,self.N): self.X[i] = x for i in range(self.N-1,0,-1): self.X[i] = self.Xf(self.X[i<<1],self.X[i<<1 | 1]) def eval_at(self,i): return self.operate(self.X[i],self.A[i]) def propagate_at(self,i): self.X[i] = self.eval_at(i) self.A[i<<1] = self.Af(self.A[i<<1],self.A[i]) self.A[i<<1 | 1] = self.Af(self.A[i<<1 | 1],self.A[i]) self.A[i] = self.Aunit def propagate_above(self,i): H = i.bit_length() - 1 for h in range(H,0,-1): self.propagate_at(i >> h) def recalc_above(self,i): while i > 1: i >>= 1 self.X[i] = self.Xf(self.eval_at(i << 1),self.eval_at(i << 1 | 1)) def update(self,i,x): i += self.N self.propagate_above(i) self.X[i] = x self.A[i] = self.Aunit self.recalc_above(i) def fold(self,L = 0,R = -1): if R == -1:R = self.N L += self.N R += self.N self.propagate_above(L // (L & -L)) self.propagate_above(R // (R & -R) -1) vL = self.Xunit vR = self.Xunit while L < R: if L & 1: vL = self.Xf(vL,self.eval_at(L)) L += 1 if R & 1: R -= 1 vR = self.Xf(self.eval_at(R),vR) L >>= 1 R >>= 1 return self.Xf(vL,vR) def operate_range(self,L,R,x): #区間全体に作用させる L += self.N R += self.N L0 = L // (L & -L) R0 = R // (R & -R) - 1 self.propagate_above(L0) self.propagate_above(R0) while L < R: if L & 1: self.A[L] = self.Af(self.A[L],x) L += 1 if R & 1: R -= 1 self.A[R] = self.Af(self.A[R],x) L >>= 1 R >>= 1 self.recalc_above(L0) self.recalc_above(R0) def write(self): print(self.X) def change(self,Xf,Xunit,Af,Aunit,operate): self.Xf = Xf self.Xunit = Xunit self.Af = Af self.Aunit = Aunit self.operate = operate N,K = map(int,input().split()) from collections import defaultdict d = defaultdict(list) dd = defaultdict(lambda :[0] * 2) for _ in range(N): s,p,u = map(int,input().split()) d[u].append((s,0,-p,_+1)) now = 0 seq = [] nowi = 0 for u in d: dd[u][0] = now dd[u][1] = now + len(d[u]) now += len(d[u]) for s,num,p,index in d[u]: seq.append((s,num,p,index,nowi,u)) nowi += 1 seg = LazySegTree(N) seg.build(seq) ans = [] for _ in range(K): s,num,p,index,pos,u = seg.fold() ans.append(index-1) seg.operate_range(dd[u][0],dd[u][1],(0,1)) seg.operate_range(pos,pos+1,(inf,0)) print(*ans,sep = "\n")