change vector values for many index ranges efficiently

Imaging I have a long vector

vec = 1:1E8

and a data frame

d = data.frame(pos_start=1:1E7, 
               pos_end=(1:1E7) + sample(1:10, 1E7, replace=TRUE), 
               val=runif(1E7))

I want to achive the following goal:

for(i in 1:nrow(d)) 
  vec[d[i, 'pos_start']:d[i, 'pos_end']] = d[i, 'val']

what could be an efficient way to do that?