QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#674103#7787. Maximum RatingCalculatelove#WA 1ms5924kbC++141.6kb2024-10-25 13:53:012024-10-25 13:53:02

Judging History

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

  • [2024-10-25 13:53:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5924kb
  • [2024-10-25 13:53:01]
  • 提交

answer

#include <bits/stdc++.h>

typedef long long s64;

const int N = 200100;
const int sz = 1e9;

int n, Q;
int a[N];

s64 sum;

namespace SGT {
    const int pond = 10001000;

    int nClock, root;
    struct node {
        int lc, rc;
        int cnt;
        s64 sum;
    } t[pond];

    void insert(int &p, int l, int r, int x, int type) {
        if (!p) p = ++ nClock;
        t[p].cnt += type, t[p].sum += x * type;
        if (l == r) return;
        int mid = (l + r) >> 1;
        if (x <= mid)
            insert(t[p].lc, l, mid, x, type);
        else
            insert(t[p].rc, mid + 1, r, x, type);
    }

    int ask(int p, int l, int r, s64 k) {
        if (l == r) return std::min((s64)t[p].cnt, k / l);
        int mid = (l + r) >> 1;
        if (k <= t[t[p].rc].sum)
            return ask(t[p].rc, mid + 1, r, k);
        else
            return ask(t[p].lc, l, mid, k - t[t[p].rc].sum) + t[t[p].rc].cnt;
    }
}

void add(int x) {
    if (!x) return;

    sum += x;

    if (x > 0) SGT::insert(SGT::root, -sz, sz, x, +1);
}

void dec(int x) {
    if (!x) return;

    sum -= x;

    if (x > 0) SGT::insert(SGT::root, -sz, sz, x, -1);
}

int main() {
    scanf("%d%d", &n, &Q);

    for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);

    for (int i = 1; i <= n; i ++) add(a[i]);

    while (Q --) {
        int x, v;
        scanf("%d%d", &x, &v);
        dec(a[x]), add(a[x] = v);

        printf("%d\n", SGT::t[SGT::root].cnt - SGT::ask(SGT::root, -sz, sz, sum - 1) + (sum <= 0));
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3872kb

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3812kb

input:

1 1
-1000000000
1 -1000000000

output:

2

result:

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