题面
来源:USACO 官网。模型收到的是同一份题面的文字。
$N$ contestants participated in a contest, each placing a distinct rank from $1$ to $N$. There are $C$ criteria used to invite contestants to participate in the final round, and the $i$th-ranked contestant satisfies a specified $n_i$ of them ($1\le n_i\le C$).
The invitation process runs as follows. First, the top $f_1$ students who satisfy the $1$st criteria will be invited. Then, out of all students who haven't yet been invited, the top $f_2$ (or all remaining if there are fewer than $f_2$ remaining) students who satisfy the $2$nd criterion will be invited. This process repeats, for each $i$ from $1$ to $C$ ($1\le f_i\le N$).
However, some contestants will decline to participate in the final round, in which case they will be ignored when determining who to invite.
You are given a permutation $p_1, p_2, \dots, p_N$ of $1\dots N$. For each $i$ from $0$ to $N-1$, determine the sum of the ranks of the contestants who will be invited if the participants with ranks given by the first $i$ elements of $p$ decline to attend.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains $N$ and $C$ ($1\le N,C\le 10^5$).The next line contains $f_1,f_2, \dots, f_C$.
The next line contains $p_1, \dots, p_N$.
The next $N$ lines each contain $n_i$ ($1\le n_i\le C$), followed by $n_i$ distinct integers in $[1, C]$, representing the criteria that the $i$th-ranked contestant satisfies. It is guaranteed that $\sum n_i\le 10^6$.
OUTPUT FORMAT (print output to the terminal / stdout):
Output $N$ lines, the sum of ranks of invitees before each declination.SAMPLE INPUT:
5 1 3 5 1 3 2 4 1 1 1 1 1 1 1 1 1 1
SAMPLE OUTPUT:
6 6 9 6 4
There is only one criterion. The top three remaining contestants who have not declined will be invited.
SAMPLE INPUT:
5 4 1 1 1 1 1 2 3 4 5 1 1 2 1 2 2 2 3 2 3 4 1 4
SAMPLE OUTPUT:
10 14 12 9 5
Initially, the $i$th contestant gets invited under criterion $i$ for all $1\le i\le 4$.
After the first declination, the $i+1$th contestant gets invited under criterion $i$ for all $1\le i\le 4$.
SAMPLE INPUT:
6 10 5 6 4 1 3 3 3 6 5 3 1 4 6 5 2 3 1 9 5 4 3 9 5 10 10 6 2 10 1 7 8 3 9 4 5 10 4 5 3 1 2 9 10 6 7 8 2 3 1 8 1 9 7 4 3 10 6 2
SAMPLE OUTPUT:
21 20 16 10 5 3
SCORING:
- Inputs 4-6: $N, C \le 10^3, \sum n_i \le 10^4$
- Inputs 7-8: $C=1$
- Inputs 9-10: $C=2$
- Inputs 11-16: No additional constraints.
Problem credits: Benjamin Qi
结果
Kimi K3.1 ProKimi
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 15.0k平均输出 token(含思考) ↓
- 28.0输出速度 tokens/s ↑
- 538 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 6Pylint 问题 ↓
- 9.23Pylint 得分 ↑
- 25圈复杂度 ↓
- 46.8可维护性指数 ↑
DeepSeek Flash V4.1-1017DeepSeek
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 27.4k平均输出 token(含思考) ↓
- 178.1输出速度 tokens/s ↑
- 155 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 8Pylint 问题 ↓
- 8.77Pylint 得分 ↑
- 18圈复杂度 ↓
- 48.5可维护性指数 ↑
MiniMax M3.1 FlashMiniMax
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 61.7k平均输出 token(含思考) ↓
- 124.6输出速度 tokens/s ↑
- 496 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 7Pylint 问题 ↓
- 8.94Pylint 得分 ↑
- 18圈复杂度 ↓
- 65.7可维护性指数 ↑
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
import sys def read_ints(): data = sys.stdin.buffer.read() i = 0 length = len(data) while i < length: while i < length and data[i] <= 32: i += 1 if i >= length: break value = 0 while i < length and data[i] > 32: value = value * 10 + data[i] - 48 i += 1 yield value def main(): it = read_ints() n = next(it) c = next(it) f = [0] * (c + 1) for i in range(1, c + 1): f[i] = next(it) order = [next(it) for _ in range(n)] criteria = [[] for _ in range(c + 1)] for rank in range(1, n + 1): count = next(it) for _ in range(count): criteria[next(it)].append(rank) del it # state[r] = 0: uninvited, -1: declined, otherwise invitation criterion. state = [0] * (n + 1) pointers = [0] * (c + 1) answer = 0 for q in range(1, c + 1): contestants = criteria[q] index = 0 chosen = 0 limit = f[q] length = len(contestants) while chosen < limit and index < length: rank = contestants[index] index += 1 if state[rank] == 0: state[rank] = q answer += rank chosen += 1 pointers[q] = index output = [str(answer)] for i in range(n - 1): declined = order[i] q = state[declined] state[declined] = -1 if q > 0: answer -= declined # Fill the vacancy. If the replacement was invited at a later # criterion, that criterion in turn receives a vacancy. while True: contestants = criteria[q] index = pointers[q] length = len(contestants) replacement = 0 while index < length: rank = contestants[index] index += 1 old_criterion = state[rank] if old_criterion == 0 or old_criterion > q: replacement = rank break pointers[q] = index if replacement == 0: break old_criterion = state[replacement] state[replacement] = q if old_criterion == 0: answer += replacement break q = old_criterion output.append(str(answer)) sys.stdout.write("\n".join(output)) if __name__ == "__main__": main()
import sys import heapq def main(): data = list(map(int, sys.stdin.buffer.read().split())) idx = 0 N = data[idx] C = data[idx + 1] idx += 2 f = data[idx:idx + C] idx += C p = data[idx:idx + N] idx += N heaps = [[] for _ in range(C + 1)] for contestant in range(1, N + 1): n = data[idx] idx += 1 for _ in range(n): c = data[idx] idx += 1 heaps[c].append(contestant) del data assigned = [0] * (N + 1) total = 0 heappop = heapq.heappop # Initial invitation process. for c in range(1, C + 1): h = heaps[c] limit = f[c - 1] cnt = 0 while cnt < limit and h: x = heappop(h) if assigned[x] == 0: assigned[x] = c total += x cnt += 1 active = bytearray(b'\x01') * (N + 1) answers = [str(total)] # Process the first N-1 declinations. for i in range(N - 1): x = p[i] if active[x] and assigned[x] != 0: old = assigned[x] active[x] = 0 total -= x v = old while True: h = heaps[v] while h: y = h[0] if active[y] and (assigned[y] == 0 or assigned[y] > v): break heappop(h) if not h: break y = heappop(h) old_y = assigned[y] if old_y == 0: assigned[y] = v total += y break else: assigned[y] = v v = old_y else: active[x] = 0 answers.append(str(total)) sys.stdout.write("\n".join(answers)) if __name__ == "__main__": main()
import sys from itertools import islice def solve(): data = map(int, sys.stdin.buffer.read().split()) try: N = next(data) except StopIteration: return C = next(data) f = [0] + list(islice(data, C)) p = list(islice(data, N)) # Initially, pool[c] contains everyone satisfying criterion c. # Since ranks are read in increasing order, every pool is rank-sorted. pool = [[] for _ in range(C + 1)] for rank in range(1, N + 1): k = next(data) for _ in range(k): criterion = next(data) pool[criterion].append(rank) del data # assigned[rank]: # 0 -> not currently invited # >0 -> criterion that currently invites this contestant # -1 -> has declined assigned = [0] * (N + 1) total = 0 # Simulate the original process. # Afterwards, pool[c] contains the contestants who satisfy c but were # not selected by c or by any earlier criterion. for criterion in range(1, C + 1): slots = f[criterion] candidates = [] for rank in pool[criterion]: if assigned[rank] == 0: if slots: assigned[rank] = criterion slots -= 1 total += rank else: candidates.append(rank) pool[criterion] = candidates # Each replacement pool is static and sorted, so use a moving head. head = [0] * (C + 1) answer = [] for position, declined in enumerate(p): # Exactly p[:position] have declined at this point. answer.append(str(total)) # The last requested state has N-1 declinations. if position == N - 1: break vacancy = assigned[declined] assigned[declined] = -1 if vacancy == 0: # Removing a contestant who was not invited creates no vacancy. continue total -= declined # Repair the vacancy and any vacancy it creates. while vacancy: candidates = pool[vacancy] pos = head[vacancy] size = len(candidates) # A candidate is usable if it is still uninvited, or is currently # invited by a later criterion. Candidates selected by an earlier # criterion can never become usable again. while pos < size: candidate = candidates[pos] state = assigned[candidate] if state == 0 or state > vacancy: break pos += 1 head[vacancy] = pos if pos == size: break candidate = candidates[pos] head[vacancy] = pos + 1 previous = assigned[candidate] assigned[candidate] = vacancy if previous == 0: # Previously uninvited contestant is now invited. total += candidate break # The contestant was promoted from a later criterion, which now # has a vacancy of its own. vacancy = previous sys.stdout.write("\n".join(answer) + "\n") if __name__ == "__main__": solve()