This is an advanced version of http://acm.cs.nthu.edu.tw/problem/11447/
Notice, this time, first and last is [first, last].
Hint: std::map<std::string,...>
lower_bound and upper_bound can help you.
The input consist of series of command. Each commands is insert, sum, range output, range erase or output.
insert: inserts a integer (0<=val<65536) with a string (key) to map. If the key has already existed, insert the val at the begining of integer (the val which the key belongs).
For example,
insert a 10
insert b 20
The map should contain 10, 20.
insert a 20
The map should contain 20 10, 20.
sum: sums up the integer with the key. Sum is 0 if a key is not existed. Output a newline character ('\n') after printing the sum.
For example,
insert a 10
insert b 20
The map should contain 10, 20.
insert a 20
The map should contain 20 10, 20.
sum a
It should output 30 (because 20 + 10).
range output: outputs the integer from key (first) to key (last). Output a space character (' ') after printing an element. Output a newline character ('\n') after printing all elements (even first key equals to last key).
For example,
insert a 10
insert b 20
The map should contain 10, 20.
insert a 20
The map should contain 20 10, 20.
range output a b
It should output 2010 20.
range erase: erase the integer from key (first) to key (last).
output: outputs all integer in map. From the smallest key to biggest key. Output a space character (' ') after printing an element. Output a newline character ('\n') after printing all elements (even map is empty).
insert a 10
insert b 20
The map should contain 10, 20.
insert a 20
The map should contain 20 10, 20.
output
It should output 2010 20.
Complete the above operations.