QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796284#7787. Maximum RatingUESTC_DebugSimulator#WA 2ms6144kbC++171.4kb2024-12-01 16:06:352024-12-01 16:06:36

Judging History

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

  • [2024-12-01 16:06:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6144kb
  • [2024-12-01 16:06:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200005,INF=1e9;
int n,q,a[N],cnt;
struct node{
	int ls,rs,num;
	ll sum;
}tr[N*50];
void upd(int i,int l,int r,int x,int w){
	if(l==r){
		tr[i].num+=w;
		tr[i].sum+=1ll*w*x;
		return;
	}
	int mid=l+r>>1;
	if(x<=mid){
		if(!tr[i].ls)tr[i].ls=++cnt;
		upd(tr[i].ls,l,mid,x,w);
	}
	else{
		if(!tr[i].rs)tr[i].rs=++cnt;
		upd(tr[i].rs,mid+1,r,x,w);
	}
	tr[i].sum=tr[tr[i].ls].sum+tr[tr[i].rs].sum;
	tr[i].num=tr[tr[i].ls].num+tr[tr[i].rs].num;
}
int qry(int i,int l,int r,ll sum){
	if(l==r){
		if(tr[i].sum<=sum)return tr[i].num;
		return sum/l;
	}
	int mid=l+r>>1;
	if(!tr[i].ls)return qry(tr[i].rs,mid+1,r,sum);
	if(!tr[i].rs)return qry(tr[i].ls,l,mid,sum);
	if(tr[tr[i].ls].sum<=sum)return tr[tr[i].ls].num+qry(tr[i].rs,mid+1,r,sum-tr[tr[i].ls].sum);
	return qry(tr[i].ls,l,mid,sum);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>q;
	ll neg=0;
	int sn=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]<=0){
			sn++;
			neg-=a[i];
		}
		else upd(0,1,INF,a[i],1);
	}
	while(q--){
		int x,v;
		cin>>x>>v;
		if(a[x]>0)upd(0,1,INF,a[x],-1);
		else{
			sn--;
			neg+=a[x];
		}
		a[x]=v;
		if(a[x]>0)upd(0,1,INF,a[x],1);
		else{
			sn++;
			neg-=a[x];
		}
		int mx=n-sn;
		int mn=max(0,mx-qry(0,1,INF,neg));
		cout<<mx-mn+1<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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: 0
Accepted
time: 1ms
memory: 5648kb

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:

500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
...

result:

ok 1000 numbers

Test #7:

score: -100
Wrong Answer
time: 2ms
memory: 6144kb

input:

1000 1000
-485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...

output:

2
3
4
5
3
3
3
3
10
11
-1472219056
12
-787611187
-2098058958
-352524554
16
17
18
-218118975
20
21
22
-1172471080
24
25
26
26
27
28
29
30
-536475303
-536475304
-1442696481
34
35
-727701901
-1769013879
-1769013879
-1769013879
-1769013879
-1769013879
-1769013879
43
-1378117262
-1910963699
46
47
-9181625...

result:

wrong answer 5th numbers differ - expected: '6', found: '3'