From dd8d4cb398df10750eb908e3e718422d280f76a3 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 21 Oct 2025 16:44:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(P4087):=20=E4=BF=AE=E5=A4=8D=E5=A5=B6?= =?UTF-8?q?=E7=89=9B=E8=AE=A1=E6=95=B0=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正判断条件,确保在奶牛数量变化时正确计算答案。移除冗余变量just_one_was_max,使用wasmaxcnt和ismaxcnt更精确地跟踪数量变化。 --- src/10/20/P4087.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/10/20/P4087.cpp b/src/10/20/P4087.cpp index 0160678..d5f0fc2 100644 --- a/src/10/20/P4087.cpp +++ b/src/10/20/P4087.cpp @@ -32,10 +32,9 @@ int main() { for (ll i = 1; i <= n; i++) { ll max_num_before = num_cowcount.rbegin()->first; - bool just_one_was_max = num_cowcount.rbegin()->second==1; ll old_cownum = cow_num[c[i].c]; - + ll wasmaxcnt = num_cowcount[old_cownum]; bool was_top = (old_cownum == max_num_before); num_cowcount[old_cownum]--; @@ -47,12 +46,12 @@ int main() { cow_num[c[i].c] = new_cownum; num_cowcount[new_cownum]++; - + ll ismaxcnt = num_cowcount[new_cownum]; ll max_num_after = num_cowcount.rbegin()->first; bool is_top = (new_cownum == max_num_after); - if ((max_num_before != max_num_after && !just_one_was_max) || (was_top != is_top)) { + if ((was_top != is_top)||(was_top&is_top && wasmaxcnt!=ismaxcnt)) { ans++; } }