QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768875#7787. Maximum RatingmobbbWA 1ms3828kbC++203.0kb2024-11-21 15:00:142024-11-21 15:00:14

Judging History

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

  • [2024-11-21 15:00:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-11-21 15:00:14]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long

const int N = 4e5 + 7;

int val[N], m;

struct info{
    ll val, t;
};

info operator + (const info &l,const info &r){
    info b = {0, 0};
	if (l.t && r.t){
		b.val = l.val + r.val;
		b.t = l.t + r.t;
	}else if (l.t){
		b = l;
	}else if (r.t){
		b = r;
	}
    return b;
}

struct node{
    info s;
}seg[N * 4];

void update(int id){
    seg[id].s = seg[2 * id].s + seg[2 * id + 1].s;
}

void build(int id,int l,int r){
	if (l > r) {
		return;
	}
    if (l == r){
        seg[id].s = {val[l], 0};
    }else{
        int mid = (l + r) / 2;
        build(id * 2,l,mid);
        build(id * 2 + 1,mid + 1,r);
        update(id);
    }
}

void change(int id,int l,int r,int pos,int t){
	if (l > r) {
		return;
	}
    if (l == r){
        seg[id].s.t = t;
    }else{
        int mid = (l + r) / 2;
        if (pos <= mid) {
            change(2 * id,l,mid,pos,t);
        }
        else{
            change(2 * id + 1,mid + 1,r,pos,t);
        }
        update(id);
    }
}

ll query(int id,int l,int r,ll sum){
	if (l > r) {
		return 0;
	}
    if (l == r){
    	if (sum >= seg[id].s.val){
        	return seg[id].s.t;
    	}else{
    		return 0;
    	}
    }
    int mid = (l + r) / 2;
    ll cur = 0;
    if (seg[id * 2].s.val >= sum){
    	cur += query(id * 2, l, mid, sum);
    }else{
    	cur += seg[id * 2].s.t;
    	sum -= cur;
    	cur += query(id * 2 + 1, mid + 1, r, sum);
    }
    return cur;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n, q;
	std::cin >> n >> q;

	std::vector<int> a(n + 1);
	ll sum = 0;
	std::map<int, std::pair<std::vector<int>, int>> pos;
	for (int i = 1; i <= n; i++){
		std::cin >> a[i];
		if (a[i] > 0){
			val[++m] = a[i];
		}else{
			sum += (-a[i]);
		}
	}
	std::vector<std::pair<int, int>> evt(q); 
	for (int i = 0; i < q; i++){
		int x, v;
		std::cin >> x >> v;
		evt[i] = {x, v};
		if (v > 0){
			val[++m] = v;
		}
	}	
	std::sort(val + 1, val + m + 1);
	for (int i = 1; i <= m; i++){
		pos[val[i]].first.push_back(i);
		pos[val[i]].second = -1;
	}

	build(1, 1, m);
	for (int i = 1; i <= n; i++){
		if (a[i] <= 0) continue;
		int idx = pos[a[i]].first[++pos[a[i]].second];
		change(1, 1, m, idx, 1);
	}
	for (auto [x, v] : evt){
		if (a[x] > 0 && v > 0){
			int curpos = pos[a[x]].first[pos[a[x]].second--];
			change(1, 1, m, curpos, 0);
			// std::cout << seg[1].s.val << ' ';
			int nextpos = pos[v].first[++pos[v].second];
			change(1, 1, m, nextpos, 1);
			a[x] = v;
		}else if (a[x] > 0 && v <= 0){
			int curpos = pos[a[x]].first[pos[a[x]].second--];
			change(1, 1, m, curpos, 0);
			sum += -v;
			a[x] = v;
		}else if (a[x] <= 0 && v > 0){
			sum -= (-a[x]);
			int nextpos = pos[v].first[++pos[v].second];
			change(1, 1, m, nextpos, 1);
			a[x] = v;
		}else if (a[x] <= 0 && v <= 0){
			sum -= (-a[x]);
			sum += (-v);
			a[x] = v;
		}
		std::cout << query(1, 1, m, sum - 1) + 1 << '\n';
	}

	return 0;
}

详细

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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:

945
64
251
409
914
591
982
486
342
898
808
431
585
586
138
463
803
83
475
698
503
148
578
351
374
855
544
165
139
656
567
508
274
709
872
429
536
878
300
1
297
969
922
509
983
641
54
878
940
343
463
787
916
993
570
609
490
441
925
100
985
839
623
612
424
344
815
422
274
220
316
112
385
115
468
259
4...

result:

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