since the 99 in the first row is set to 0 , while the others are not.

Sorry for the unclear description, actually I want to just DROP all the 99s,
I slightly modified you solution, and it works for me too!
t2 = torch.tensor(
    [[99, 2, 1, 3, 4],
     [1, 2, 3, 99, 4],
     [4, 1, 99, 2, 3]]
)

idx = torch.cumsum((t2 == 99), 1)
idx[t2==99] = 2
idx = idx[idx != 2].view(3, -1)

res = (~idx.bool()).long()
print(res)
> tensor([[1, 0, 0, 0, 0],
          [1, 1, 1, 1, 0],
          [1, 1, 1, 0, 0]])

Thanks for your help!