QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#724927#7787. Maximum RatingLeft0807WA 1ms3812kbC++202.0kb2024-11-08 15:35:082024-11-08 15:35:08

Judging History

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

  • [2024-11-08 15:35:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3812kb
  • [2024-11-08 15:35:08]
  • 提交

answer

#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

void solve(){
    int n, q;
    cin >> n >> q;
    vector<int> a(n+1);
    vector<int> d;

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        d.push_back(a[i]);
    }
    vector<pair<int, int> > upd(q);
    for(auto& [x, v] : upd){
        cin >> x >> v;
        d.push_back(v);
    }
    d.push_back(0);

    sort(all(d));
    d.erase(unique(all(d)), d.end());

    auto find = [&](int x)->int{
        return lower_bound(all(d), x) - d.begin() + 1;
    };

    vector<int> sBIT(d.size() + 1);
    vector<int> cBIT(d.size() + 1);

    auto add = [&](vector<int>& BIT, int x, int val)->void{
        for(int i = x; i <= d.size(); i += i&-i) BIT[i] += val;
    };

    auto qry = [&](vector<int>& BIT, int x){
        int res = 0;
        for(int i = x; i > 0; i -= i&-i) res += BIT[i];
        return res;
    };

    for(int i = 1; i <= n; i++){
        add(sBIT, find(a[i]), a[i]);
        add(cBIT, find(a[i]), 1);
    }

    auto f = [&](int x)->bool{
        int neg = qry(sBIT, find(0));
        int xthpos = qry(sBIT, x);
        int rmpos = qry(sBIT, d.size()) - xthpos;
        xthpos -= neg;

        return rmpos >= rmpos + neg + xthpos;
    };

    for(auto [x, v] : upd){
        add(sBIT, find(a[x]), -a[x]);
        add(cBIT, find(a[x]), -1);
        a[x] = v;
        add(sBIT, find(a[x]), a[x]);
        add(cBIT, find(a[x]), 1);

        int i = find(0);
        for(int j = d.size(); j > 0; j /= 2){
            while(i+j <= d.size() && f(i+j)) i += j;
        }

        int min_k = qry(cBIT, d.size()) - qry(cBIT, i);
        int max_k = qry(cBIT, d.size()) - qry(cBIT, find(0));

        cout << max_k - min_k + 1 << '\n'; 
    }
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int tt = 1;
    // cin >> tt;
    while(tt--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3716kb

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'