QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#778950#7787. Maximum Rating4eyebirdWA 3ms7860kbC++174.2kb2024-11-24 16:52:482024-11-24 16:52:49

Judging History

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

  • [2024-11-24 16:52:49]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7860kb
  • [2024-11-24 16:52:48]
  • 提交

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

int idx;
struct node
{
    int l, r;
    int ct, lzc;
    ll sm, lz;
} tr[7000000];

map<int, int> Ct;

constexpr int MX = 1000000010;

void update(int l, int r, ll x, int L = 0, int R = MX, int p = 1)
{
    if (x > 0)
        tr[p].ct += (r - l + 1);
    else if (x < 0)
        tr[p].ct -= (r - l + 1);
    tr[p].sm += x * (r - l + 1);
    if (l <= L && R <= r)
    {
        if (x > 0)
            tr[p].lzc++;
        else if (x < 0)
            tr[p].lzc--;
        tr[p].lz += x;
        return;
    }
    int mid = (L + R) >> 1;
    if (l <= mid)
    {
        if (tr[p].l == 0)
            tr[p].l = idx++;
        update(l, min(mid, r), x, L, mid, tr[p].l);
    }
    if (r > mid)
    {
        if (tr[p].r == 0)
            tr[p].r = idx++;
        update(max(l, mid + 1), r, x, mid + 1, R, tr[p].r);
    }
}

int query(int px, int L = 0, int R = MX, int p = 1)
{
    if (L == px && R == px)
        return p;
    int mid = (L + R) >> 1;
    if (tr[p].lz > 0 || tr[p].lzc != 0)
    {
        if (tr[p].l == 0)
            tr[p].l = idx++;
        if (tr[p].r == 0)
            tr[p].r = idx++;

        tr[tr[p].l].sm += tr[p].lz * (mid - L + 1);
        tr[tr[p].r].sm += tr[p].lz * (R - mid);
        tr[tr[p].l].lz += tr[p].lz;
        tr[tr[p].r].lz += tr[p].lz;
        tr[p].lz = 0;

        tr[tr[p].l].ct += tr[p].lzc * (mid - L + 1);
        tr[tr[p].r].ct += tr[p].lzc * (R - mid);
        tr[tr[p].l].lzc += tr[p].lzc;
        tr[tr[p].r].lzc += tr[p].lzc;
        tr[p].lzc = 0;
    }
    if (px <= mid)
    {
        if (tr[p].l == 0)
        {
            return -1;
        }
        return query(px, L, mid, tr[p].l);
    }
    else if (px > mid)
    {
        if (tr[p].r == 0)
        {
            return -1;
        }
        return query(px, mid + 1, R, tr[p].r);
    }
}

ll a[200010];

void solve()
{
    idx = 2;
    int n, q;
    cin >> n >> q;
    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]]++;
            update(a[i], MX, a[i]);
        }
    }

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

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

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

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

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

        int l = 0, r = MX;
        while (l < r)
        {
            int mid = (l + r) >> 1;
            if (check(mid))
                r = mid;
            else
                l = mid + 1;
        }
        int qy = query(l);
        int mxc = tr[qy].ct;
        ll ca = tr[qy].sm + Sf;
        int cty = Ct[l];
        while (cty-- && ca > 0)
        {
            ca -= l;
            mxc--;
        }
        int ans = mxc + 1;
        cout << ans << '\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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5752kb

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: 1ms
memory: 5632kb

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: 0ms
memory: 5712kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 5712kb

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
298
970
923
510
984
642
55
879
941
344
464
788
917
994
571
610
491
442
926
101
986
840
624
613
425
345
816
423
275
221
317
113
386
116
469
260
4...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 1ms
memory: 5712kb

input:

1000 1000
1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...

output:

500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
...

result:

ok 1000 numbers

Test #7:

score: -100
Wrong Answer
time: 3ms
memory: 7860kb

input:

1000 1000
-485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...

output:

2
3
4
5
6
7
8
9
10
11
12
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
51
52
53
54
55
56
57
58
59
60
60
61
62
63
64
65
65
66
67
68
69
70
71
72
73
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
88
89
90
91
92
92
93
94
95
96...

result:

wrong answer 764th numbers differ - expected: '505', found: '504'