J. 2023秋-A-3 Popularity of Education Supermarket Categories

    传统题 400ms 64MiB

2023秋-A-3 Popularity of Education Supermarket Categories

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

题目描述

In PTA, there is the Education Supermarket which collects all kinds of exam/test problem sets. The sets can be found in several categories.

The popularity of a category ii is defined to be ni/n+pi/pn_i/n + p_i/p, where nin_i and pip_i are the number of users who have opened a set and the total payment received in category ii, respectively; nn is the total number of users who have opened a set and pp is the total payment received in the supermarket.

Your job is to calculate the popularity of any given category.

输入格式

Each input file contains one test case.

For each case, the first line contains a positive integer NN (103\le 10^3), which is the total number of problem sets and the categories.

Then NN lines follow, each describes a set or category in the following format:

ID1 ID2 type n p

where ID1 is the index of this set or category, which is a 3-digit number; ID2 is the index of the category that contains ID1 -- a category may have several sub-categories or contains several problem sets, and each set/category may only belong to one supper category; type being 1 means that ID1 is a category, or 0 means it is a problem set; if ID1 is a set, then n is the number of users who have opened it, and p is the total payment received for this set (both are non-negative integers no more than 10510^5); or if ID1 is a category, there will be no n or p following type.

Note: the supermarket itself is the only root category, and its corresponding ID2 will be given as 1-1.

Finally, another positive integer MM (103\le 10^3) is given, and is followed by MM category ID's in the next line.

输出格式

For each query of category, we should print in a line its popularity. However, to avoid the lose of accuracy during float number calculations, let's output nin_i, nn, pip_i and pp instead. It is guaranteed that none of nn or pp is zero. Note: all the numbers in a line must be separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line.

样例

13
001 -1 1
002 001 1
006 002 0 23 45
007 002 0 108 256
005 002 1
003 001 1
011 003 0 0 0
012 003 0 1 5
004 001 1
013 004 0 200 200
008 005 0 35 78
009 005 0 8 26
010 005 0 1130 1516
5
001 002 003 004 005
1505 1505 2126 2126
1304 1505 1921 2126
1 1505 5 2126
200 1505 200 2126
1173 1505 1620 2126

限制

代码长度限制 16 KB Java (javac) 时间限制 700 ms 内存限制 512 MB

其他编译器 时间限制 400 ms 内存限制 64 MB

PAT2023秋季重现赛

未参加
状态
已结束
规则
IOI
题目
11
开始于
2025-8-31 14:00
结束于
2025-8-31 17:30
持续时间
3.5 小时
主持人
参赛人数
37