QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697789#7787. Maximum RatingblhxzjrWA 1ms5720kbC++231.6kb2024-11-01 15:46:592024-11-01 15:47:00

Judging History

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

  • [2024-11-01 15:47:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5720kb
  • [2024-11-01 15:46:59]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
using PII = pair<int,int>;
int n,m,k,_;
const int N=2e5+10;
const int M=N*20;
const int mx=1e9+10;
int a[N];
struct seg{
	int ls,rs,sum,gs;
	#define ls(id) t[id].ls
	#define rs(id) t[id].rs
	#define sum(id) t[id].sum
	#define gs(id) t[id].gs
}t[M];
int tot,root;
void up(int id) {
	gs(id)=gs(ls(id))+gs(rs(id));
	sum(id)=sum(ls(id))+sum(rs(id));
}
void modify(int &id,int l,int r,int x,int v){
	if(!id) id=++tot;
	if(l==r) {sum(id)+=v*x; gs(id)+=v; return;}
	int mid=l+r>>1;
	if(x<=mid) modify(ls(id),l,mid,x,v);
	else modify(rs(id),mid+1,r,x,v);
	up(id);
}
int query(int id,int l,int r,int s){
	if(l==r){
		if(s>0)
		return (s+l-1)/l;
		else 
		return 1;
	}
	int mid=l+r>>1;
	if(sum(ls(id))>=s) return query(ls(id),l,mid,s);
	else if(sum(id)<s) return -1;
	else return query(rs(id),mid+1,r,s-sum(ls(id)))+gs(ls(id));
}
void solve() {
	int q;
	cin>>n>>q;
	int sum=0;
	int zs=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]>0) modify(root,1,mx,a[i],1),zs++;
		else sum+=a[i];
	}
	while(q--){
		int p,v;
		cin>>p>>v;
		if(a[p]>0) modify(root,1,mx,a[p],-1),zs--;
		else sum-=a[p];
		if(v>0) modify(root,1,mx,v,1),zs++;
		else sum+=v;
		a[p]=v;
		int ans;
		if(sum(root)<=abs(sum)){
			ans=zs+1;
		}
		else ans=query(root,1,mx,abs(sum));
		// cout<<zs<<' '<<query(root,1,mx,abs(sum))<<' ';
		// cout<<sum(root)<<' '<<sum<<' ';
		cout<<ans<<endl;
	}
}
signed main(){
	ios::sync_with_stdio(false),cin.tie(0);
	int T = 1;
	//cin >> T;
	while (T--)
		solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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'