Collection
InterviewTime limit5sMemory limit1024 MB
Given up to 10 test cases, add x coins to each type in a range, clear all coins in a range, and print the total value of the collection on each query.
- Level
Medium6 of 10
- Topics
- Segment tree, Prefix sum
- Solved
- No attempts yet
Problem
You are collecting coins! You want to know how much your coins are worth.
From time to time, you pick up bags of coins and add them to your collection. Because you want to know exactly how many coins of each type you have, you keep all coins of a given type together. You may also lose all of your coins of several types.
At every moment, you want to be able to determine the total value of your coins quickly.
Input
The first line contains , the number of test cases. is at most 10.
The next line contains two positive integers and , where and . The value of coin type is .
Each of the next lines has one of the following forms: "1 a b x", "2 a b", or "3".
For the form "1 a b x", you gain coins of every type from to inclusive.
For the form "2 a b", you lose all of your coins of every type from to inclusive.
For the form "3", compute the total value of all your coins.
You start with no coins. You may assume and .
Output
For every line of the form "3", print the total value of all your coins on a separate line.