2026_11_13_NOIP

2026.11.13 NOIP

难度:蓝 绿 紫 紫/黑

T1:期望得分 100pts | 实际得分 15pts

:::info[赛时思路]
容易转化成每次 Julia 以及剩下的最大值中 \(\lceil \frac{cnt}{2} \rceil\) 个被减一,多少次后 Julia 会被超过。

对于最大值有 \(cnt\) 个的情况,需要 \(\lfloor \log_2 cnt\rfloor + 1\) 次操作会全部减 1。

\(cnt\) 只会修改 \(n\) 次,分段考虑即可。

由于不知道的原因,前前后后花费 1.5h,难说。
:::
:::error[错因]

#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define gc() unlocked_getchar()
#define gc() getchar()
inline int rd(int c = 0, int res = 0, int f = 1)
{
    c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) res = res * 10 + (c ^ 48);
    return res * f;
}

#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define urep(i, r, l) for(int i = (r); i >= (l); i--)
constexpr int mod = 998244353, inf = 0x3f3f3f3f3f3f3f3f, _ = 1000005;

int lg[_];
int n, p[_], pmx;
set <int> s;
unordered_map <int, int> mp;

signed main()
{
    // freopen("lead.in", "r", stdin);
    // freopen("lead.out", "w", stdout);

    lg[0] = 0, lg[1] = 1;
    rep(i, 2, _-1) lg[i] = lg[i >> 1] + 1;

    n = rd();
    pmx = rd();
    rep(i, 2, n) p[i] = rd();

    // 每次最大值中 (x + 1) / 2 的数 -1
    // x | y -> 0 | x+y 需要的次数为 lg[x]

    rep(i, 2, n) s.insert(p[i]), mp[p[i]]++;
    s.insert(-inf);

    int ans = 0;
    while(*prev(s.end()) <= pmx - ans)
    {
        int mx = *prev(s.end()); 
        s.erase(mx);
        int mxx = *prev(s.end());

        int cnt = mp[mx];
        int tims = lg[cnt];

        // cerr << cnt << " " << tims << " " << ans << "\n";

        if(cnt > 1 && mx > pmx - ans)
        {
            cout << ans - 1; exit(0);
        }
        else if(cnt > 1 && mx > pmx - ans - (tims + 1))
        {
            int t = pmx - ans - mx;
            if(pmx - ans - (t+1) < mx - ((t+1) >= tims)) cout << ans + t;
            else cout << ans + t + 1;
            exit(0);
        }
        else if(mxx <= pmx - ans - __int128(mx - mxx) * tims)
        {
            ans += (mx - mxx) * tims;
            mp[mxx] += mp[mx], mp[mx] = 0;
        }
        else
        {
            int t = (pmx - ans - mx) / (tims - 1);
            ans += t * tims, mp[mx - t] += mp[mx], mp[mx] = 0, s.insert(mx - t);
        }
    }
    return 0;
}

这里考虑的是 \(mx\) 不变化的情况,所以应为 \(tims-1\),后面直接输出 \(pmx-x\) 即可。

赛时写了这个特判误以为是对的。

hack:

3 
4 4 2

:::

T2
对于均值套路的考虑分数规划,单调队列可以容易的 \(O(n)\) 判断答案,赛时写了假算 \(95pts\)。

posted @ 2026-11-20 16:44  lovely_kitten  阅读(20)  评论(0)    收藏  举报