Untitled
N online streamers and their number of subscribers are given. Each streamer has an ID value that ranges from 1 to N. Each streamer's number of subscribers either increases or decreases. Given the range of streamer ID value, you want to calculate either the total number of subscribers or the difference between the maximum and the minimum number of subscribers. Given that the streamer ID value ranges from 1 to 5, the total number of subscribers is 250. (50 + 35 + 100 + 20 + 45 = 250) Given that the streamer ID value ranges from 6 to 10, the difference between the maximum and the minimum number of subscribers is 720. (Maximum : 750, Minimum : 30, Difference : 750 - 30 = 720) Implement each required function by referring to the following API description. ※ The function signature below is based on C/C++. As for other languages, refer to the provided Main and User Code. The following is the description of API to be written in the User Code. void init(int N, int mSubscriber[]) This function is called in the beginning of each test case. N streamers are given. Each streamer has an ID value that ranges from 1 to N. The number of subscribers of N streamers is given in the form of mSubscriber array. Parameters N: Number of streamers ( 10 ≤ N ≤ 200,000 ) For every i (0 ≤ i < N), mSubscriber[i]: Number of subscribers of Streamer i+1. ( 1 ≤ mSubscriber[i] ≤ 10,000 ) int subscribe(int mId, int mNum) This function increases the number of subscribers of Streamer mId by mNum and returns the updated number of subscribers of Streamer mId. Parameters mId: Streamer ID ( 1 ≤ mId ≤ N ) mNum: Number of subscribers increased ( 1 ≤ mNum ≤ 10,000 ) Returns The updated number of subscribers of Streamer mId is returned. int unsubscribe(int mId, int mNum) This function decreases the number of subscribers of Streamer mId by mNum and returns the updated number of subscribers of Streamer mId. There is no case in which the number of subscribers decreases below 0. Parameters mId: Streamer ID ( 1 ≤ mId ≤ N ) mNum: Number of subscribers decreased ( 1 ≤ mNum ≤ 10,000 ) Returns The updated number of subscribers of Streamer mId is returned. int count(int sId, int eId) This function returns the total number of subscribers of Streamers sId to eId. Parameters sId: Smallest streamer ID in the range ( 1 ≤ sId < N ) eId: Largest streamer ID in the range ( sId < eId ≤ N ) Returns The total number of subscribers of Streamers sId to eId is returned. int calculate(int sId, int eId) This function returns the difference between the maximum and the minimum number of subscribers among the number of subscribers of Streamers sId to eId. Parameters sId: Smallest streamer ID in the range ( 1 ≤ sId < N ) eId: Largest streamer ID in the range ( sId < eId ≤ N ) Returns The difference between the maximum and the minimum number of subscribers among the number of subscribers of Streamers sId to eId is returned. [Example] Think of the following case in [Table 1]. Order Function return Figure 1 init(10, {50,35,100,20,45,210,30,400,750,70}) Fig. 1 2 count(1, 5) 250 3 subscribe(3, 20) 120 Fig. 2 4 count(1, 5) 270 5 unsubscribe(8, 100) 300 Fig. 3 6 count(7, 9) 1080 7 subscribe(9, 200) 950 Fig. 4 8 subscribe(4, 50) 70 Fig. 5 9 calculate(1, 10) 920 [Constraints] 1. init() is called in the beginning of each test case. 2. For each test case, subscribe() is called up to 15,000 times. 3. For each test case, unsubscribe() is called up to 15,000 times. 4. For each test case, count() is called up to 15,000 times. 5. For each test case, calculate() is called up to 15,000 times.
Leave a Comment