QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#777189#7787. Maximum RatingdongfangwuqingWA 1ms3604kbC++142.2kb2024-11-23 23:29:512024-11-23 23:29:51

Judging History

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

  • [2024-11-23 23:29:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3604kb
  • [2024-11-23 23:29:51]
  • 提交

answer

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

struct Node {
    int l, r;
    int cnt;
    long long sum;
} tr[32 * 201010];

int n, q, a[201010], cnt, root, tot = 1;
long long zheng, fu;

void update(int l, int r, int& p, int num, int ad) {
    if (p == 0) { p = tot++; }
    
    if (l == r) {
        tr[p].cnt += ad;
        tr[p].sum += 1LL * num * ad;
        return;
    }
    int m = (l + r) / 2;
    if (num <= m) { update(l, m, tr[p].l, num, ad); }
    else { update(m + 1, r, tr[p].r, num, ad); }
    tr[p].cnt = tr[tr[p].l].cnt + tr[tr[p].r].cnt;
    tr[p].sum = tr[tr[p].l].sum + tr[tr[p].r].sum;
}

int find(int l, int r, int p, long long he) {
    if (l == r) { return tr[p].cnt; }

    int res = 0;
    int m = (l + r) / 2;
    if (tr[tr[p].l].sum <= he) { 
        res += tr[tr[p].l].cnt; 
        he -= tr[tr[p].l].sum;
        res += find(m + 1, r, tr[p].r, he);
    } else {
        return find(l, m, tr[p].l, he);
    }
    return res;
}

int main() {
    cin >> n >> q;
    for (int i = 1; i <= n; i++) { cin >> a[i]; }
    for (int i = 1; i <= n; i++) {
        if (a[i] < 0) { fu -= a[i]; }
        if (a[i] > 0) { 
            zheng += a[i], cnt++;
            update(1, 1e9, root, a[i], 1); 
        }
    }

    while (q--) {
        int x, v;
        cin >> x >> v;
        if (a[x] > 0) {
            update(1, 1e9, root, a[x], -1);
            zheng -= a[x];
            cnt--;
            if (v < 0) { fu -= v; }
            else if (v > 0) { zheng += v; update(1, 1e9, root, v, 1); cnt++; }
        } else if (a[x] < 0) {
            fu += a[x];
            if (v < 0) { fu -= v; }
            else if (v > 0) { zheng += v; update(1, 1e9, root, v, 1); cnt++; }
        } else {
            if (v < 0) { fu -= v; }
            else if (v > 0) { zheng += v; update(1, 1e9, root, v, 1); cnt++; }
        }
        a[x] = v;
        if (zheng <= fu) { 
            cout << cnt + 1 << "\n"; 
        }
        else {
            int ma = cnt;
            int tp = find(1, 1e9, root, fu);
            int mi = cnt - tp + 1;
            cout << ma - mi + 1 << "\n";
        }
    }
    



    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3564kb

input:

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

output:

1
2
1
2
2

result:

wrong answer 5th numbers differ - expected: '1', found: '2'