This code might work:
B, H, W, C = 2, 3, 3, 4
N = 5
x = torch.randn(B, H, W, C)
I = torch.randint(0, H, (B, N, 2))
S = torch.ones(B, N, C)

x[torch.arange(B).unsqueeze(1),
  I[torch.arange(B), :, 0],
  I[torch.arange(B), :, 1]] = S

Could you please double check it using your manual approach with the for loop?
PS: Please don’t create double posts, as other users might answer the same question