QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#785590#7787. Maximum RatingNanani#WA 1ms7736kbC++171.8kb2024-11-26 18:24:592024-11-26 18:25:09

Judging History

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

  • [2024-11-26 18:25:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7736kb
  • [2024-11-26 18:24:59]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define int long long 

using namespace std;
const int N = 4e5 + 10;
int n, m, a[N], idx = 0, rt = 0, ls[N << 5], rs[N << 5];
int f1[N << 5], f2[N << 5];
const int mx = 1e9;

void push_up(int rt) {
    f1[rt] =  f1[ls[rt]] + f1[rs[rt]];
    f2[rt] =  f2[ls[rt]] + f2[rs[rt]];
}
void update(int &rt, int l, int r, int x, int w) {
    if(! rt) rt = ++ idx;
    if(l == r)  {
        f1[rt] += w, f2[rt] += w * x;
        return;
    }
    int mid = l + r >> 1;
    if(mid >= x) update(ls[rt], l, mid, x, w);
    else update(rs[rt], mid + 1, r, x, w);
    push_up(rt);
} 
int query(int rt, int l, int r, int k) {
    if(! rt) return 0;
    if(l == r) {
        return k / l + 1;
    }
    int mid = l + r >> 1;
    if(f2[ls[rt]] > k) return query(ls[rt], l, mid, k);
    else return f1[ls[rt]] + query(rs[rt], mid + 1, r, k - f2[ls[rt]]);
}

void sol() {
    cin >> n >> m;
    F(i, 1, n) cin >> a[i];
    int cnt = 0, sum = 0;
    F(i, 1, n) {
        if(a[i] <= 0) sum += a[i];
        else cnt ++, update(rt, 1, mx, a[i], 1);
    }
    F(i, 1, m) {
        int x, v; cin >> x >> v;
        if(a[x] <= 0) sum -= a[x];
        else cnt --, update(rt, 1, mx, a[i], -1);
        a[x] = v;
        if(a[x] <= 0) sum += a[x];
        else cnt ++, update(rt, 1, mx, a[i], 1);
        int now = -1;
        if(f2[rt] > -sum) {
            now = query(rt, 1, mx, -sum);
        }
        int qaq = now == -1 ? 0 : cnt - now + 1;
        // cout << cnt - now + 1 << " " << cnt << "??\n";
        cout << cnt - qaq + 1 << "\n";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t; 
    F(i, 1, t) sol();
    return 0;
}
/*
3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

*/

詳細信息

Test #1:

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

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

input:

3 5
1 2 3
3 4
2 -2
1 3
3 1
2 1

output:

1
2
2
2
1

result:

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