销售系统问题


---

**Question**

A distributor distributes energy drinks in 34 oz cans to customers who each have a unique ID. It distributes the drinks according to the demand for them. It developed a system that handles all the transaction queries of the store. The system will handle two types of queries (i.e., query 1 and query 2). The first query determines if the customer's ID has already been logged, and, if so, it adds the quantity of the new sale to the previous quantity and updates the record. If the customer's ID has not been logged in before, then it will make a fresh entry. Query 2 retrieves the number of cans purchased by customers in the given range of customer ID. At the end of the day, the distributor must submit a report for all the type 2 queries.

Write an algorithm to help the distributor find the answer for all the type 2 queries.

**Input**
- The first line of the input consists of an integer `numOfCustomer`, representing the number of customers (C).
- The second line consists of two space-separated integers - `numOfQueries` and `queryDesc` representing the number of queries (Q) and the description of queries (queryDesc = 3 always), respectively.
- The next Q lines consist of three space-separated integers, wherein the first integer represents the type of the query and can only be 1 or 2. If the first integer is 1, then it is a type 1 query and the second and third integers represent the customer ID and the quantity of drinks purchased, respectively. If the first integer is 2, then it is a type 2 query, and the second and third integers represent the starting and ending customer ID range (both inclusive).

**Output**
Print space-separated integers representing the answer to all the type 2 queries. If no type 2 query is present, then do not print anything in the output.

**Constraints**
- \( 0 \leq numOfCustomer \leq 10^5 \)
- \( 0 \leq numOfQueries \leq 10^5 \)
- queryDesc = 3

**Example**
Input: 
4 
5 3 
1 3 12 
2 0 2 
1 1 4 
1 3 2 
2 1 4

问题

一个分销商以34盎司的罐装向每位拥有唯一ID的客户分发能量饮料。它根据需求分发饮料。它开发了一个处理商店所有交易查询的系统。该系统将处理两种类型的查询(即查询1和查询2)。第一个查询确定客户的ID是否已经被记录,如果是,则将新销售的量添加到之前的数量并更新记录。如果客户的ID之前没有被记录过,则会创建一个新条目。查询2检索给定客户ID范围内购买的罐数。在一天结束时,分销商必须提交所有类型2查询的报告。

编写一个算法来帮助分销商找到所有类型2查询的答案。

输入

  • 输入的第一行包含一个整数numOfCustomer,代表客户数量(C)。

  • 第二行包含两个空格分隔的整数 - numOfQueriesqueryDesc,分别代表查询数量(Q)和查询描述(queryDesc始终为3)。

  • 接下来的Q行包含三个空格分隔的整数,其中第一个整数代表查询类型,只能是1或2。如果第一个整数是1,则它是类型1查询,第二和第三个整数分别代表客户ID和购买的饮料数量。如果第一个整数是2,则它是类型2查询,第二和第三个整数代表起始和结束客户ID范围(两者都包括在内)。

输出

打印代表所有类型2查询答案的空格分隔整数。如果没有类型2查询,则不在输出中打印任何内容。

约束条件

  • ( 0 \leq numOfCustomer \leq 10^5 )

  • ( 0 \leq numOfQueries \leq 10^5 )

  • queryDesc = 3

示例


如果您需要进一步的帮助,请随时提问!

Last updated