Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
5.5 kB
3
Indexable
Never
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.

The initial number of subscribers of 10 streamers is given as in [Fig. 1].



[Fig. 1]

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

 

[Table 1]

(Order 1) 10 streamers and their number of subscribers are given. The result of the function call is as in [Fig. 1].

(Order 2) 250, which is the total number of subscribers of Streamers 1 to 5, is returned.

(Order 3) The number of subscribers of Streamer 3 increases by 20. 120, which is the updated number of subscribers of Streamer 3, is returned.
The result of the function call is as in [Fig. 2].



[Fig. 2]

(Order 4) 270, which is the total number of subscribers of Streamers 1 to 5, is returned.

(Order 5) The number of subscribers of Streamer 8 decreases by 100. 300, which is the updated number of subscribers of Streamer 8, is returned.
The result of the function call is as in [Fig. 3].



[Fig. 3]

(Order 6) 1080, which is the total number of subscribers of Streamers 7 to 9, is returned.

(Order 7) The number of subscribers of Streamer 9 increases by 200. 950, which is the updated number of subscribers of Streamer 9, is returned.
The result of the function call is as in [Fig. 4].



 [Fig. 4]

(Order 8) The number of subscribers of Streamer 4 increases by 50. 70, which is the updated number of subscribers of Streamer 4, is returned.
The result of the function call is as in [Fig. 5].



 [Fig. 5]

(Order 9) 920, which is the difference between the maximum and the minimum number of subscribers among the number of subscribers of Streamers 1 to 10, is returned.

 

[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