QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#778840#7787. Maximum Rating4eyebirdWA 29ms331408kbC++174.1kb2024-11-24 16:30:382024-11-24 16:30:38

Judging History

你现在查看的是最新测评结果

  • [2024-11-24 16:30:38]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:331408kb
  • [2024-11-24 16:30:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define Buff ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
//#define int long long

constexpr int MX = 1e9 + 10;

class DST
{
public:
    DST()
    {
        idx = 1;
        Mxn = MX;
        lc.assign(7e6, 0);
        rc.assign(7e6, 0);
        sg.assign(7e6, 0);
        stm.assign(7e6, 0);
    }

    void update(int p, ll x)
    {
        int rt = 1;
        _update(p, p, x, 0, Mxn, rt);
    }

    void update(int l, int r, ll x)
    {
        int rt = 1;
        _update(l, r, x, 0, Mxn, rt);
    }

    ll query(int p)
    {
        return _query(p, 0, Mxn, 1);
    }

private:
    int idx, Mxn;
    vector<ll> stm, sg;
    vector<int> lc, rc;

    void _update(ll L, ll R, ll x, ll l, ll r, int &pt)
    {
        if (!pt)
            pt = ++idx;
        int p = pt;
        stm[p] += x * (R - L + 1);
        if (L <= l && r <= R)
        {
            sg[p] += x;
            return;
        }
        ll mid = (l + r) >> 1;
        if (R <= mid)
            _update(L, R, x, l, mid, lc[p]);
        else if (L > mid)
            _update(L, R, x, mid + 1, r, rc[p]);
        else
        {
            _update(L, mid, x, l, mid, lc[p]);
            _update(mid + 1, R, x, mid + 1, r, rc[p]);
        }
    }

    ll _query(ll px, ll l, ll r, int p)
    {
        if (!p) return 0;
        if (l == px && r == px)
            return stm[p];
        ll mid = (l + r) >> 1;
        ll ret = sg[p];
        if (px <= mid)
            ret += _query(px, l, mid, lc[p]);
        else if (px > mid)
            ret += _query(px, mid + 1, r, rc[p]);
        return ret;
    }
};

map<int, int> Ct;

ll a[200010];
void solve()
{
    int n, q;
    cin >> n >> q;

    DST T1, T2;

    ll Sf = 0, Sz = 0, Cz = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] < 0)
            Sf += a[i];
        else if (a[i] > 0)
        {
            Cz++;
            Sz += a[i];
            Ct[a[i]]++;
            T1.update(a[i], MX, a[i]);
            T2.update(a[i], MX, 1);
        }
    }

    while (q--)
    {
        int p;
        ll x;
        cin >> p >> x;

        if (a[p] < 0)
        {
            Sf -= a[p];
            a[p] = x;
        }
        else
        {
            Cz--;
            Sz -= a[p];
            Ct[a[p]]--;
            T1.update(a[p], MX, -a[p]);
            T2.update(a[p], MX, -1);
            a[p] = x;
        }

        if (x <= 0)
            Sf += x;
        else
        {
            Cz++;
            Sz += x;
            Ct[x]++;
            T1.update(x, MX, x);
            T2.update(x, MX, 1);
        }

        if (Sf == 0)
        {
            cout << "1\n";
            continue;
        }
        if (Sz + Sf <= 0)
        {
            cout << Cz + 1 << '\n';
            continue;
        }

        auto check = [&](int px) -> bool
        {
            if (T1.query(px) + Sf >= 0)
                return true;
            else
                return false;
        };

        int l = 1, r = MX;
        while (l < r)
        {
            int mid = (l + r) >> 1;
            if (check(mid))
                r = mid;
            else
                l = mid + 1;
        }
        l--;
        ll mxc = T2.query(l);
        ll ca = -Sf - T1.query(l);
        if (ca > 0)
            mxc += ca / (l + 1);
        cout << mxc + 1 << '\n';

        //        ll mxc = T2.query(l);
        //        ll ca = T1.query(l) + Sf;
        //        if (ca > 0)
        //        {
        //            ll cs = ca / l + (ca % l == 0 ? 0 : 1);
        //            cs = min(cs, (ll)Ct[l]);
        //            mxc -= cs;
        //        }
        //        cout << mxc + 1 << '\n';
    }
}

signed main()
{
#ifdef YGYYYGJ
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    Buff;
    int _T_ = 1;
    while (_T_--)
    {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 24ms
memory: 331100kb

input:

3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

output:

1
2
2
2
3

result:

ok 5 number(s): "1 2 2 2 3"

Test #2:

score: 0
Accepted
time: 29ms
memory: 331300kb

input:

3 5
1 2 3
3 4
2 -2
1 3
3 1
2 1

output:

1
2
1
2
1

result:

ok 5 number(s): "1 2 1 2 1"

Test #3:

score: 0
Accepted
time: 24ms
memory: 331408kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 19ms
memory: 331160kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 24ms
memory: 331264kb

input:

1000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

946
65
252
410
915
592
983
487
343
899
809
432
586
587
139
464
804
84
476
699
504
149
579
352
375
856
545
166
140
657
568
509
275
710
873
430
537
879
301
1
297
969
922
509
983
641
54
878
940
343
463
787
916
993
570
609
490
441
925
100
985
839
623
612
424
344
815
422
274
220
316
112
385
115
468
259
4...

result:

wrong answer 41st numbers differ - expected: '298', found: '297'