Code is not complete and will not compile. Also it makes no sense. You read a value from analog pin A0 into distance_cm. Then you map that into duration_us. Then you write distance_cm to the servo. And only then do you check the ultrasonic sensor.
Steve