QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#663329#7787. Maximum RatingDoubeecatRE 1ms5740kbC++203.0kb2024-10-21 14:52:002024-10-21 14:52:04

Judging History

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

  • [2024-10-21 14:52:04]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5740kb
  • [2024-10-21 14:52:00]
  • 提交

answer

/*
Undo the destiny.
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
const int N = 4e5 + 10;

vector <int> rk;

struct node {
    int l,r;
    ll sum;
    int cnt;
}tree[N<<2];

void pushup(int p) {
    tree[p].sum = tree[p << 1].sum + tree[p << 1 | 1].sum;
    tree[p].cnt = tree[p << 1].cnt + tree[p << 1 | 1].cnt;
}

void build(int p,int l,int r) {
    tree[p].l = l,tree[p].r =  r;
    if (l == r) {
        return ;
    }
    int mid = (l + r) >> 1;
    build(p<< 1,l,mid);
    build(p << 1 | 1,mid + 1,r);
    pushup(p);
}

void modify(int p,int x,int k) {
    if (tree[p].l == tree[p].r) {
        tree[p].cnt += k;
        tree[p].sum += k*rk[x-1];
        return ;
    }
    int mid = (tree[p].l + tree[p].r) >> 1;
    if (x <= mid) modify(p << 1,x,k);
    else modify(p << 1 | 1,x,k);
    pushup(p);
}

int query(int p,ll x,int res) {
    if (tree[p].l == tree[p].r) {
        return res + (x + (rk[tree[p].l - 1])) / rk[tree[p].l - 1];
    }
    //cerr << tree[p].l << " " << tree[p].r << " " << tree[p].sum << " " << tree[p].cnt << "\n";
    //cerr << tree[p << 1].l << " " << tree[p << 1].r << " " << tree[p << 1].sum << " " << tree[p << 1].cnt << "\n";
    //cerr << tree[p << 1 | 1].l << " " << tree[p << 1 | 1].r << " " << tree[p << 1 | 1].sum << " " << tree[p << 1 | 1].cnt << "\n";
    int mid = (tree[p].l + tree[p].r) >> 1;
    if (tree[p << 1].sum <= x) {
        return query(p << 1 | 1,x - tree[p << 1].sum,res + tree[p << 1].cnt);
    } else {
        return query(p << 1,x,res);
    }
}

vector <pii> queries;

int n,q,a[N],tot;

int getpos(int x) {
    return lower_bound(rk.begin(),rk.end(),x) - rk.begin();
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);//cout.tie(0);
    cin >> n >> q;
    for (int i = 1;i <= n;++i) cin >> a[i];
    for (int i = 1;i <= n;++i)
    if(a[i] > 0)
    rk.push_back(a[i]);
    for (int i = 1;i <= q;++i) {
        int x,v;cin >> x >> v;
        queries.push_back(mp(x,v));
        if (v > 0) rk.push_back(v);
    }
    sort(rk.begin(),rk.end());
    rk.erase(unique(rk.begin(),rk.end()),rk.end());
    ll sum = 0;
    tot = rk.size();
    int cnt = 0;
    build(1,1,tot);
    for (int i = 1;i <= n;++i) {
        if (a[i] <= 0) sum += -a[i];
        else {
            modify(1,getpos(a[i]) + 1,1);++cnt;
        }
    }
    for (auto [x,v] : queries) {
        if (a[x] <= 0) {
            sum += a[x];
        } else {
            modify(1,getpos(a[x]) + 1,-1);--cnt;
        }
        a[x] = v;
        if (v <= 0) sum += -v;
        else {
            modify(1,getpos(v) + 1,1);++cnt;
        }
        if (tree[1].sum <= sum) {
            cout << cnt + 1<< "\n";
            continue;
        }
        int ans = query(1,sum,0);
        //cout << cnt << " " << ans << "\n";
        cout << cnt - (cnt - ans + 1) + 1 << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: -100
Runtime Error

input:

1 1
-1000000000
1 -1000000000

output:


result: