题面
来源:USACO 官网。模型收到的是同一份题面的文字。
Farmer John is looking at his cows in a magical field and wants to take pictures of subsets of his cows.
The field can be seen as a $N \times N$ grid $(1 \leq N \leq 500)$, with a single stationary cow at each location. Farmer John's camera is capable of taking a picture of any $K \times K$ square that is part of the field $(1 \leq K \leq \min(N, 25))$.
At all times, each cow has a beauty value between $0$ and $10^6$. The attractiveness index of a picture is the sum of the beauty values of the cows contained in the picture.
The beauty value for every cow starts out as $0$, so the attractiveness index of any picture in the beginning is $0$.
At $Q$ times $(1 \leq Q \leq 3\cdot 10^{4})$, the beauty of a single cow will increase by a positive integer due to eating the magical grass that is planted on Farmer John's field.
Farmer John wants to know the maximum attractiveness index of a picture he can take after each of the $Q$ updates.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains integers $N$ and $K$.The following line contains an integer $Q$.
Each of the following $Q$ lines contains three integers: $r$, $c$, and $v$, which are the row, column, and new beauty value, respectively ($1 \leq r, c \leq N, 1 \leq v \leq 10^6$). It is guaranteed that the new beauty value is greater than the beauty value at that location before.
OUTPUT FORMAT (print output to the terminal / stdout):
Output $Q$ lines, corresponding to the maximum attractiveness index of a picture after each update.
SAMPLE INPUT:
4 2 3 2 2 11 3 4 3 3 1 100
SAMPLE OUTPUT:
11 11 111
After the first update, a picture with the maximum attractiveness index is the picture with upper left corner $(2, 2)$ and lower right corner $(3, 3)$, which has an attractiveness index of $11 + 0 + 0 + 0 = 11$.
The second update does not affect the maximum attractiveness index.
After the third update, the picture with the maximum attractiveness index changes to the picture with upper left corner $(2, 1)$ and lower right corner $(3, 2)$, which has an attractiveness index of $0 + 11 + 100 + 0 = 111$.
SAMPLE INPUT:
3 1 3 2 2 3 2 2 5 2 2 7
SAMPLE OUTPUT:
3 5 7
There is only one cow with a positive beauty value, so the maximum attractiveness index will always include that cow.
SCORING:
- Inputs 3-6: $N \leq 50, Q \leq 100$
- Inputs 7-10: $N \leq 50$
- Inputs 11-18: No additional constraints.
Problem credits: Brian Law and Cici Liu
结果
Kimi K3.1 ProKimi
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 1.9k平均输出 token(含思考) ↓
- 28.5输出速度 tokens/s ↑
- 69 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 4Pylint 问题 ↓
- 8.86Pylint 得分 ↑
- 8圈复杂度 ↓
- 64.2可维护性指数 ↑
DeepSeek Flash V4.1-1017DeepSeek
0/1
解出的采样 ↑
- 66.7采样 1 · 超时
- 15.8k平均输出 token(含思考) ↓
- 216.2输出速度 tokens/s ↑
- 74 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 18Pylint 问题 ↓
- 7.91Pylint 得分 ↑
- 31圈复杂度 ↓
- 42.7可维护性指数 ↑
MiniMax M3.1 FlashMiniMax
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 6.5k平均输出 token(含思考) ↓
- 152.6输出速度 tokens/s ↑
- 43 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 4Pylint 问题 ↓
- 8.75Pylint 得分 ↑
- 9圈复杂度 ↓
- 67.5可维护性指数 ↑
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
import sys def main(): data = list(map(int, sys.stdin.buffer.read().split())) if not data: return n, k = data[0], data[1] q = data[2] pos = 3 beauty = [[0] * n for _ in range(n)] # sums[i][j] is the sum of the K x K square with upper-left corner (i, j). m = n - k + 1 sums = [[0] * m for _ in range(m)] best = 0 answers = [] for _ in range(q): r = data[pos] - 1 c = data[pos + 1] - 1 value = data[pos + 2] pos += 3 delta = value - beauty[r][c] beauty[r][c] = value # Only squares containing (r, c) change. Since every update is # positive, the global maximum can never decrease. i_start = max(0, r - k + 1) i_end = min(r, m - 1) j_start = max(0, c - k + 1) j_end = min(c, m - 1) for i in range(i_start, i_end + 1): row = sums[i] for j in range(j_start, j_end + 1): new_sum = row[j] + delta row[j] = new_sum if new_sum > best: best = new_sum answers.append(str(best)) sys.stdout.write("\n".join(answers)) if __name__ == "__main__": main()
import sys def solve() -> None: data = list(map(int, sys.stdin.buffer.read().split())) it = iter(data) N = next(it) K = next(it) Q = next(it) W = N - K + 1 B = 24 BR = (W + B - 1) // B # val[i][j] is the window sum excluding its block's lazy value. val = [[0] * W for _ in range(W)] lazy = [[0] * BR for _ in range(BR)] bmax = [[0] * BR for _ in range(BR)] cows = [[0] * N for _ in range(N)] global_max = 0 answers = [] for _ in range(Q): r = next(it) - 1 c = next(it) - 1 v = next(it) old = cows[r][c] delta = v - old cows[r][c] = v if delta: r1 = r - K + 1 if r1 < 0: r1 = 0 r2 = r if r2 >= W: r2 = W - 1 c1 = c - K + 1 if c1 < 0: c1 = 0 c2 = c if c2 >= W: c2 = W - 1 br1 = r1 // B br2 = r2 // B bc1 = c1 // B bc2 = c2 // B for bi in range(br1, br2 + 1): i_start = bi * B i_end = i_start + B - 1 if i_end >= W: i_end = W - 1 ir1 = r1 if r1 > i_start else i_start ir2 = r2 if r2 < i_end else i_end if ir1 > ir2: continue lazy_row = lazy[bi] bmax_row = bmax[bi] for bj in range(bc1, bc2 + 1): j_start = bj * B j_end = j_start + B - 1 if j_end >= W: j_end = W - 1 jc1 = c1 if c1 > j_start else j_start jc2 = c2 if c2 < j_end else j_end if jc1 > jc2: continue if ( i_start >= r1 and i_end <= r2 and j_start >= c1 and j_end <= c2 ): # Whole block is covered. lazy_row[bj] += delta bm = bmax_row[bj] + delta bmax_row[bj] = bm if bm > global_max: global_max = bm else: # Only part of the block is covered. lz = lazy_row[bj] max_new = -1 for i in range(ir1, ir2 + 1): row = val[i] for j in range(jc1, jc2 + 1): nv = row[j] + delta row[j] = nv actual = nv + lz if actual > max_new: max_new = actual bm = bmax_row[bj] if max_new > bm: bm = max_new bmax_row[bj] = bm if bm > global_max: global_max = bm answers.append(str(global_max)) sys.stdout.write("\n".join(answers)) if __name__ == "__main__": solve()
import sys def solve(): data = list(map(int, sys.stdin.buffer.read().split())) if not data: return n, k, q = data[0], data[1], data[2] width = n - k + 1 beauty = [[0] * n for _ in range(n)] # picture_sums[rr][cc] is the sum of the K x K picture whose # upper-left corner is (rr, cc). picture_sums = [[0] * width for _ in range(width)] # For each row/column, the possible upper-left coordinates of # pictures containing that row/column. valid_starts = [ tuple(range(max(0, x - k + 1), min(x, width - 1) + 1)) for x in range(n) ] best = 0 answers = [] pos = 3 for _ in range(q): r = data[pos] - 1 c = data[pos + 1] - 1 v = data[pos + 2] pos += 3 delta = v - beauty[r][c] beauty[r][c] = v columns = valid_starts[c] for rr in valid_starts[r]: picture_row = picture_sums[rr] for cc in columns: new_sum = picture_row[cc] + delta picture_row[cc] = new_sum if new_sum > best: best = new_sum answers.append(str(best)) sys.stdout.write("\n".join(answers) + "\n") if __name__ == "__main__": solve()