题面
来源:USACO 官网。模型收到的是同一份题面的文字。
There are $N$ ($1\le N\le 2\cdot 10^5$) buckets in a stack where the $i$-th bucket from the top has capacity $a_i$ gallons ($1\le a_i\le 10^9$). A tap above the top bucket sends one gallon of milk per second into the first bucket per second. There is also a pool below bucket $N$.
When a bucket reaches its capacity after $t$ seconds, at the start of the $t+1$th second it flips to dump its contents into either the bucket below if it is not the last bucket or the pool otherwise (it reverts back to filling at the end of the $t+1$th second). A bucket cannot collect milk while it is flipped; any milk arriving at the bucket above during this second is lost. Additionally, any amount of milk exceeding the capacity of the bucket below is lost.
Handle $Q$ ($1\le Q\le 3\cdot 10^5$) queries, each specified by three integers $i$, $v$, and $t$:
- First, set $a_i=v$ ($1\le i\le N, 1\le v \le 10^9$).
- Then answer the following question: Suppose that at time $0$, all buckets as well as the pool are empty. Determine the number of gallons of milk in the pool after $t$ seconds ($1\le t\le 10^{18}$).
The $a_i=v$ updates persist through later queries.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains $N$.The second line contains $a_1\dots a_N$.
The next line contains $Q$.
Then the following $Q$ lines contain three integers $i$, $v$, and $t$. This means that you should set $a_i=v$ and then answer the question for $t$.
OUTPUT FORMAT (print output to the terminal / stdout):
Output the answer to each question on a separate line.SAMPLE INPUT:
3 1 1 1 30 1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 2 1 1 2 2 1 2 3 1 2 4 1 2 5 1 2 6 1 2 7 1 2 8 1 2 9 1 2 10 2 2 1 2 2 2 2 2 3 2 2 4 2 2 5 2 2 6 2 2 7 2 2 8 2 2 9 2 2 10
SAMPLE OUTPUT:
0 0 0 1 1 2 2 3 3 4 0 0 0 0 1 1 1 2 2 2 0 0 0 0 1 1 1 2 2 2
When $a=[1, 1, 1]$,
- Bucket $1$ flips at times $2,4,6,\dots$
- Bucket $2$ flips at times $3,5,7,\dots$
- Bucket $3$ flips at times $4,6,8,\dots$
When $a=[2, 1, 1]$,
- Bucket $1$ flips at times $3,6,9,\dots$
- Bucket $2$ flips at times $4,7,10,\dots$
- Bucket $3$ flips at times $5,8,11,\dots$
When $a=[2, 2, 1]$,
- Bucket $1$ flips at times $3,6,9,\dots$
- Bucket $2$ flips at times $4,7,10,\dots$
- Bucket $3$ flips at times $5,8,11,\dots$
SAMPLE INPUT:
2 1 2 10 1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10
SAMPLE OUTPUT:
0 0 0 0 2 2 2 2 4 4
SAMPLE INPUT:
3 1 1 1 1 1 1 1000000000000000000
SAMPLE OUTPUT:
499999999999999999
SCORING:
- Inputs 4-5: $N \le 10, Q\le 100$, and all $t\le 10^4$
- Inputs 6-11: $N\le 10^3, Q\le 10^4$
- Inputs 12-23: No additional constraints.
Problem credits: Akshaj Arora
结果
Kimi K3.1 ProKimi
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 12.1k平均输出 token(含思考) ↓
- 30.9输出速度 tokens/s ↑
- 393 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 6Pylint 问题 ↓
- 8.95Pylint 得分 ↑
- 12圈复杂度 ↓
- 49.3可维护性指数 ↑
DeepSeek Flash V4.1-1017DeepSeek
0/1
解出的采样 ↑
- 73.9采样 1 · 超时
- 15.5k平均输出 token(含思考) ↓
- 211.4输出速度 tokens/s ↑
- 74 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 7Pylint 问题 ↓
- 8.60Pylint 得分 ↑
- 12圈复杂度 ↓
- 55.4可维护性指数 ↑
MiniMax M3.1 FlashMiniMax
0/1
解出的采样 ↑
- 47.8采样 1 · 超时
- 44.1k平均输出 token(含思考) ↓
- 168.3输出速度 tokens/s ↑
- 263 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 5Pylint 问题 ↓
- 9.02Pylint 得分 ↑
- 12圈复杂度 ↓
- 56.7可维护性指数 ↑
↑ 越大越好,↓ 越小越好。得分 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 = data[0] a = data[1:n + 1] q = data[n + 1] # P = (a[0] + 1) * product(ceil(a[i] / a[i-1]), i >= 1). # Products larger than 10^18 can be saturated, since they always give 0. LIMIT = 10**18 + 1 size = 1 while size < n: size <<= 1 seg = [1] * (2 * size) seg[size] = a[0] + 1 for i in range(1, n): seg[size + i] = (a[i] + a[i - 1] - 1) // a[i - 1] for i in range(size - 1, 0, -1): product = seg[2 * i] * seg[2 * i + 1] seg[i] = product if product <= LIMIT else LIMIT def update(pos, value, seg=seg, size=size, limit=LIMIT): node = size + pos if seg[node] == value: return seg[node] = value node >>= 1 while node: product = seg[2 * node] * seg[2 * node + 1] if product > limit: product = limit if seg[node] == product: break seg[node] = product node >>= 1 answers = [] ptr = n + 2 for _ in range(q): pos = data[ptr] - 1 v = data[ptr + 1] t = data[ptr + 2] ptr += 3 if a[pos] != v: a[pos] = v if pos == 0: update(0, v + 1) else: update(pos, (v + a[pos - 1] - 1) // a[pos - 1]) if pos + 1 < n: update(pos + 1, (a[pos + 1] + v - 1) // v) x = t - n + 1 if x > 0: dumps = x // seg[1] if dumps: answers.append(str(dumps * a[-1])) continue answers.append("0") 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) a = [0] + [next(it) for _ in range(N)] Q = next(it) CAP = 10**18 + 1 # Segment tree over factors: # factor[i] = ceil(a_i / a_{i-1}) for i = 2..N size = 1 while size < N - 1: size <<= 1 tree = [1] * (2 * size) for i in range(2, N + 1): pos = i - 2 tree[size + pos] = (a[i] + a[i - 1] - 1) // a[i - 1] for p in range(size - 1, 0, -1): val = tree[p << 1] * tree[p << 1 | 1] tree[p] = CAP if val > CAP else val def update(pos: int, value: int) -> None: idx = size + pos tree[idx] = value idx >>= 1 while idx: val = tree[idx << 1] * tree[idx << 1 | 1] tree[idx] = CAP if val > CAP else val idx >>= 1 base = a[1] + 1 answers = [] for _ in range(Q): i = next(it) v = next(it) t = next(it) a[i] = v if i == 1: base = a[1] + 1 if N >= 2: update(0, (a[2] + a[1] - 1) // a[1]) else: # Update factor i: ceil(a_i / a_{i-1}) update(i - 2, (a[i] + a[i - 1] - 1) // a[i - 1]) # Update factor i+1 if it exists if i + 1 <= N: update(i - 1, (a[i + 1] + a[i] - 1) // a[i]) period = base * tree[1] if period > CAP: period = CAP x = t - N + 1 if x <= 0: answers.append("0") else: answers.append(str(a[N] * (x // period))) sys.stdout.write("\n".join(answers)) if __name__ == "__main__": solve()
import sys from math import prod def solve(): data = list(map(int, sys.stdin.buffer.read().split())) if not data: return n = data[0] a = data[1:n + 1] q = data[n + 1] ptr = n + 2 LIMIT = 10**18 # active[j] stores ceil(a[j + 1] / a[j]) when that factor is > 1. # Factors equal to 1 are omitted because they do not affect the product. active = {} for j in range(n - 1): factor = (a[j + 1] + a[j] - 1) // a[j] if factor > 1: active[j] = factor def change_factor(j, new_factor): old_factor = active.get(j, 1) if old_factor == new_factor: return if new_factor == 1: active.pop(j, None) else: active[j] = new_factor answers = [] for _ in range(q): idx = data[ptr] - 1 value = data[ptr + 1] t = data[ptr + 2] ptr += 3 if a[idx] != value: a[idx] = value if idx == 0: # Changing a[0] affects the factor from bucket 1 to bucket 2. if n > 1: change_factor(0, (a[1] + value - 1) // value) else: # Factor from bucket idx to bucket idx + 1. change_factor( idx - 1, (value + a[idx - 1] - 1) // a[idx - 1] ) # Factor from bucket idx + 1 to bucket idx + 2. if idx + 1 < n: change_factor( idx, (a[idx + 1] + value - 1) // value ) if len(active) >= 60: answers.append("0") continue period = (a[0] + 1) * prod(active.values()) if period > LIMIT: answers.append("0") continue dumps = (t - n + 1) // period if dumps < 0: dumps = 0 answers.append(str(dumps * a[-1])) sys.stdout.write("\n".join(answers)) if __name__ == "__main__": solve()