QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#665943#7787. Maximum RatingKIRITO1211WA 4ms3652kbC++233.0kb2024-10-22 15:58:142024-10-22 15:58:15

Judging History

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

  • [2024-10-22 15:58:15]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3652kb
  • [2024-10-22 15:58:14]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
//#define int long long
using ll = long long;
using i64 = long long;
const int mod = 1e9 + 7;
// #define DEBUG

struct Node {
    ll l, r, val, lazy;
    Node *left, *right;

    Node(ll l, ll r): l(l), r(r), val(0), lazy(0), left(nullptr), right(nullptr) {}

    void push_down() {
        if (!left) {
            ll m = (l + r) >> 1;
            left = new Node(l, m);
            right = new Node(m + 1, r);
        }
        if (lazy) {
            left->val += lazy * (left->r - left->l + 1);
            right->val += lazy * (right->r - right->l + 1);
            left->lazy += lazy;
            right->lazy += lazy;
            lazy = 0;
        }
    }

    void update(ll ql, ll qr, ll delta) {
        if (ql > r || qr < l) return;
        if (ql <= l && r <= qr) {
            val += delta * (r - l + 1);
            lazy += delta;
            return;
        }
        push_down();
        left->update(ql, qr, delta);
        right->update(ql, qr, delta);
        val = left->val + right->val;
    }

    ll query(ll ql, ll qr) {
        if (ql > r || qr < l) return 0;
        if (ql <= l && r <= qr) return val;
        push_down();
        return left->query(ql, qr) + right->query(ql, qr);
    }
};




void solve() {


    int n,q;std::cin>>n>>q;
    std::vector<int> a(n + 2);
    for(int i = 1;i <= n;i++) {
        std::cin>>a[i];
    }



    Node tree(0,1e9 + 1),itree(0,1e9 + 1);
    int sum = 0;
    int cnt = 0;
    for(int i = 1;i <= n;i++) {
        if(a[i] >= 0)
            tree.update(a[i],a[i],a[i]),cnt++, itree.update(a[i],a[i],1);
        else sum += a[i];
    }
    //std::cerr<<tree.query(1,1e9)<<'\n';

    while(q--){
        int x,v;std::cin>>x>>v;
        if(a[x] >= 0){
            int val = a[x];
            tree.update(val, val, -val), cnt--, itree.update(val,val,-1);
            a[x] = v;
            if (a[x] < 0) sum += a[x];
            else tree.update(a[x], a[x], a[x]), cnt++,itree.update(a[x],a[x],1);
        }
        else{
            int val = a[x];
            sum -= a[x];
            a[x] = v;
            if(a[x] < 0)sum += a[x];
            else tree.update(a[x], a[x], a[x]), cnt++, itree.update(a[x],a[x],1);
        }
        int res = 0;
        int l = 0,r = 1e9;
        while(l <= r){
            int mid = (l + r) / 2;
            if(tree.query(0,mid) < -sum) l = mid + 1;
            else res = mid, r = mid - 1;
        }
        std::cout<<cnt - itree.query(r, 1e9) + 1<<'\n';
    }

}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout<<std::fixed<<std::setprecision(10);
    int t = 1;
    // int res = 0;
    // for(int i = 1;i <= 1145;i++) res |= i;
    // std::cerr<<res<<'\n';
    //std::cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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

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

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: 4ms
memory: 3588kb

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'