QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634876#7787. Maximum Ratingstudy_to_deathWA 1ms8056kbC++143.2kb2024-10-12 18:15:432024-10-12 18:15:56

Judging History

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

  • [2024-10-12 18:15:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8056kb
  • [2024-10-12 18:15:43]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define int long long

using namespace std;

const int N = 4e5 + 5, INF = 1e9 + 5;
const ll MaxN = 1e16;

int n, q;
int a[N];
struct node
{
	int l, r;
	ll sum, v, cnt; 
}tr[N * 4];
struct option
{
	int x, v;
}op[N];
ll sum; //负数的和 
vector<int> nums;

int find(int x)
{
	return lower_bound(nums.begin(), nums.end(), x) - nums.begin();
}

void pushup(int p)
{
	tr[p].cnt = tr[p * 2].cnt + tr[p * 2 + 1].cnt;
	tr[p].sum = tr[p * 2].sum + tr[p * 2 + 1].sum;
}

void build(int p, int l, int r)
{
	if(r < l) return;
	tr[p].l = l; tr[p].r = r;
	tr[p].sum = 0; tr[p].cnt = 0;
	if(l == r)
	{
		tr[p].v = nums[l];
		return;
	}
	int mid = (l + r) / 2;
	build(p * 2, l, mid);
	build(p * 2 + 1, mid + 1, r);
	pushup(p);
}

void update(int p, int x, int d)
{
	if(tr[p].l == tr[p].r)
	{
		tr[p].cnt += d;
		tr[p].sum = tr[p].cnt * tr[p].v;
		return;
	}
	int mid = (tr[p].l + tr[p].r) / 2;
	if(mid >= x) update(p * 2, x, d);
	else update(p * 2 + 1, x, d);
	pushup(p);
}

ll query(int p, int l, int r)
{
	if(r == 0) return -MaxN;
	if(tr[p].l >= l && tr[p].r <= r)
		return tr[p].sum;
	int mid = (tr[p].l + tr[p].r) / 2;
	ll res = 0;
	if(mid >= l) res += query(p * 2, l, r);
	if(mid < r) res += query(p * 2 + 1, l, r);
	return res;
}

int query_pos(int p, int l, int r)
{
	if(r == 0) return 0;
	if(tr[p].l >= l && tr[p].r <= r) return tr[p].cnt;
	int mid = (tr[p].l + tr[p].r) / 2;
	int res = 0;
	if(mid >= l) res += query_pos(p * 2, l, r);
	if(mid < r) res += query_pos(p * 2 + 1, l, r);
	return res;
}

int get(ll d)
{
	int ans, pos;
	int l = 0, r = nums.size() - 1;
	while(l <= r)
	{
		int mid = (l + r) / 2;
		if(query(1, 1, mid) + d < 0) 
		{
			ans = query_pos(1, 1, mid);
			pos = mid;
			l = mid + 1;
		}else
		{
			r = mid - 1;
		}
	}
	d += max(0ll, query(1, 1, pos));
	pos ++;
	if(pos >= nums.size()) return ans;
	l = 0, r = query_pos(1, pos, pos);
	//cout<<ans<<endl;
	int v = nums[pos];
	int temp = 0;
	//cout<<r<<" "<<v<<endl;
	while(l <= r)
	{
		int mid = (l + r) / 2;
		if(mid * v + d <= 0)
		{
			temp = mid;
			l = mid + 1;
		}else
		r = mid - 1;
	}
	//cout<<temp<<endl;
	return ans + temp;
}

signed main()
{
	nums.push_back(-INF);
	scanf("%lld%lld", &n, &q);
	for(int i = 1; i <= n; i ++ ) 
	{
		scanf("%d", &a[i]);
		//if(a[i] > 0) 
		nums.push_back(a[i]);
		if(a[i] < 0) sum += a[i];
	}
	
	for(int i = 1; i <= q; i ++ )
	{
		int x, v;
		scanf("%lld%lld", &x, &v);
		//if(v > 0) 
		nums.push_back(v);
		op[i] = {x, v};
	}
	
	sort(nums.begin(), nums.end());
	nums.erase(unique(nums.begin(), nums.end()), nums.end());
	build(1, 1, nums.size() - 1);
	
	/*if(nums.size() == 1)
	{
		for(int i = 1; i <= q; i ++ ) puts("1");
		return 0;
	}*/
	
	for(int i = 1; i <= n; i ++ )
	{
		if(a[i] > 0)
		update(1ll, find(a[i]), 1ll);
	}
	
	for(int i = 1; i <= q; i ++ )
	{
		int x = op[i].x, v = op[i].v;
		if(a[x] > 0) 
		{
			update(1ll, find(a[x]), -1ll);
		}else
		{
			sum -= a[x];
		}
		if(v > 0)
		{
			update(1ll, find(v), 1ll);
		}else
		{
			sum += v;
		}
		a[x] = v;
		int t = get(sum);
		printf("%lld\n", t + 1ll);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7972kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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:

946
65
252
410
915
592
983
487
343
899
809
432
586
587
139
464
804
84
476
699
504
149
579
352
375
856
545
166
140
657
568
509
275
710
873
430
537
879
301
1
298
970
923
510
984
642
55
879
941
344
464
788
917
994
571
610
491
442
926
101
986
840
624
613
425
345
816
423
275
221
317
113
386
116
469
260
4...

result:

ok 1000 numbers

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 8028kb

input:

1000 1000
1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...

output:

352
221
133
13
137
210
141
149
25
267
242
227
295
344
13
6
58
265
85
309
340
469
20
368
336
481
402
143
389
215
458
60
481
341
390
476
118
288
262
357
488
407
243
145
495
164
34
419
92
24
327
135
176
113
144
310
100
112
314
295
26
458
151
240
314
345
376
23
22
365
78
212
134
112
123
175
204
434
415
...

result:

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