QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764878#7787. Maximum RatingfosovWA 7ms24304kbC++143.6kb2024-11-20 11:01:042024-11-20 11:01:05

Judging History

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

  • [2024-11-20 11:01:05]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:24304kb
  • [2024-11-20 11:01:04]
  • 提交

answer

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

#define ll long long 
#define lll __int128
#define INF 0x3f3f3f3f
#define LNF 0x3f3f3f3f3f3f3f3fll
#define MOD 998244353
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double
#define fi first
#define se second
#define all(a) a.begin(), a.end()

#define N 400010

struct Modi {
    int i, x, id;
    Modi() {};
    Modi(int i, int x): i(i), x(x) {};
};

struct seg {
    int l, r;
    ll v, f;
    ll eval() {
        return v * (f > 0);
    }
} tr[N<<2];

int z;

int build(int l, int r) {
    int cu = ++ z;
    if (r - l == 1) return cu;
    int m = (l+r)>>1;
    tr[cu].l = build(l, m);
    tr[cu].r = build(m, r);
    return cu;
}

void psu(int u) {
    tr[u].v = tr[tr[u].l].eval() + tr[tr[u].r].eval();
    tr[u].f = tr[tr[u].l].f + tr[tr[u].r].f;
}

void upd(int u, int l, int r, int k, int v, bool x=0) {
    if (r - l == 1) {
        if (x) tr[u].v = v;
        else tr[u].f = v;
        return;
    }
    int m = (l+r)>>1;
    if (k < m) upd(tr[u].l, l, m, k, v, x);
    else upd(tr[u].r, m, r, k, v, x);
    psu(u);
}

pll qry(int u, int l, int r, int ql, int qr) {
    if (ql >= qr) return pll(0, 0);
    if (ql <= l && r <= qr) return pll(tr[u].v, tr[u].f);
    int m = (l+r)>>1;
    pll res(0, 0);
    if (ql<m) {
        auto nxt = qry(tr[u].l, l, m, ql, qr);
        res.fi += nxt.fi, res.se += nxt.se;
    }
    if (qr>m) {
        auto nxt = qry(tr[u].r, m, r, ql, qr);
        res.fi += nxt.fi, res.se += nxt.se;
    }
    return res;
}

int pid[N];

int main() {
#ifdef TEST
    freopen("zz.in", "r+", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, q; cin >> n >> q;

    vector<Modi> md;
    vector<int> rnk;
    unordered_map<int, int> idx;
    for (int i = 1; i <= n; ++ i) {
        int a; cin >> a; md.emplace_back(i, a);
        rnk.emplace_back(a);
    }
    for (int i = 0; i < q; ++ i) {
        int x, v; cin >> x >> v; md.emplace_back(x, v);
        rnk.emplace_back(v);
    }
    sort(all(rnk));

    for (int i = 0; i < rnk.size(); ++ i) {
        if (!idx[rnk[i]]) idx[rnk[i]] = i;
    }
    int ref0 = N, ref1 = N;
    for (int i = rnk.size() - 1; i >= 0; -- i) {
        if (rnk[i] > 0) ref1 = i;
        if (rnk[i] >= 0) ref0 = i;
    }
    for (int i = 0; i < md.size(); ++ i) md[i].id = idx[md[i].x] ++;

    int rt = build(0, N);
    for (int i = 0; i < rnk.size(); ++ i) {
        upd(rt, 0, N, i, rnk[i], 1);
    }
    for (int i = 0; i < n; ++ i) {
        upd(rt, 0, N, md[i].id, 1);
        pid[md[i].i] = md[i].id;
    }

    auto fun = [&]() {
        cout << "have fun\n";
        for (int i = 0; i < rnk.size(); ++ i) {
            cout << i << ": ";
            auto [v0, v1] = qry(rt, 0, N, i, i+1);
            cout << v0 << ' ' << v1 << '\n';
        }
    };

    auto ans = [&]() {
        ll sum = qry(rt, 0, N, 0, N).fi;
        ll mxk = qry(rt, 0, N, ref1, N).se;
        int l = ref0, r = N;    
        while (l < r) {
            int m = (l + r) >> 1;
            auto [cs, cn] = qry(rt, 0, N, ref0, m);
            if (cs >= sum) {
                r = m;
            } else {
                l = m+1;
            }
        }
        return mxk - qry(rt, 0, N, ref0, r).se + 1;
    };
    

    for (int i = n; i < n+q; ++ i) {
        upd(rt, 0, N, pid[md[i].i], 0);
        upd(rt, 0, N, md[i].id, 1);
        pid[md[i].i] = md[i].id;
        cout << ans() << '\n';
    }
}   

// sum - ksum > 0;
// sum > ksum

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 24140kb

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

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

input:

1 1
1000000000
1 1000000000

output:

2

result:

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