QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#624571#7787. Maximum RatingMEshooter#WA 2ms3696kbC++201.5kb2024-10-09 16:08:522024-10-09 16:08:52

Judging History

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

  • [2024-10-09 16:08:52]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3696kb
  • [2024-10-09 16:08:52]
  • 提交

answer

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

#define int long long
const int SIZE = 2e5+10;
int a[SIZE];
multiset<int> pos1, pos2;

signed main(){
    //freopen("out.txt", "w", stdout);
    ios :: sync_with_stdio(false);
    int n, q, cnt_neg = 0, s_neg = 0, s_pos = 0;
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] <= 0) cnt_neg++, s_neg += a[i];
        else pos1.insert(a[i]), s_pos += a[i];
    }
    while(pos1.size() && s_neg+s_pos > 0){
        int x = *(--pos1.end());
        pos2.insert(x);
        s_pos -= x;
        pos1.erase(--pos1.end());
    }
    for(int i = 1; i <= q; i++){
        int x, y;
        cin >> x >> y;
        if(a[x] <= 0) s_neg -= a[x];
        else{
            if(pos1.count(a[x])) s_pos -= a[x], pos1.erase(a[x]);
            else pos2.erase(a[x]);
        }
        if(y <= 0) s_neg += y;
        else{
            if(pos1.size() && y <= *(--pos1.end())) pos1.insert(y), s_pos += y;
            else pos2.insert(y);
        }
        while(pos2.size() && s_neg+s_pos+*pos2.begin() <= 0){
            int x = *pos2.begin();
            pos1.insert(x);
            s_pos += x;
            pos2.erase(pos2.begin());
        }
        while(pos1.size() && s_neg+s_pos > 0){
            int x = *(--pos1.end());
            pos2.insert(x);
            s_pos -= x;
            pos1.erase(--pos1.end());
        }
        a[x] = y;
        cout << pos1.size()+1 << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3584kb

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: 3640kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 3632kb

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:

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
1
1
1
1
1
...

result:

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