The read() function here is used to increase the speed of the input. The first thing in the read function is getchar() which helps to take input character by character. Then the number is created in an integer format using bitwise operators, also considering the negative sign.
Then the program just takes in the test cases and does as the question demands it to. If you have any issues regarding the logic, please refer to the well written editorial here,