QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671874#7787. Maximum RatingKOH-#WA 1ms5652kbC++142.0kb2024-10-24 14:48:572024-10-24 14:48:57

Judging History

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

  • [2024-10-24 14:48:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5652kb
  • [2024-10-24 14:48:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x){
	x=0;char ch=getchar();bool f=false;
	while(!isdigit(ch))	f|=ch=='-',ch=getchar();
	while(isdigit(ch))	x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	x=f?-x:x;return;
} 
template <typename T>
inline void print(T x){
	if(x<0)	putchar('-'),x=-x;
	if(x>9)	print(x/10);
	putchar(x%10^48);return; 
}
#define int long long
#define ll long long 
const int N=2e5+3,M=1e9;
int a[N],n,q;
int ls[N*20],rs[N*20],cnt[N*20],rt,tot;
ll sum[N*20];
void Modify(int &x,int l,int r,int d,ll s,int g){
	if(!x) x=++tot;
	cnt[x]+=d,sum[x]+=s;
	if(l==r)	return;
	int mid=(l+r)>>1;
	if(mid>=g)	Modify(ls[x],l,mid,d,s,g);
	else Modify(rs[x],mid+1,r,d,s,g);
	return;
}
int Query(int x,int l,int r,ll s){
	if(l==r) return min(1ll*cnt[x],s/l);
	if(sum[x]<=s)	return cnt[x];
	if(!x)	return 0;
	int res=0,mid=(l+r)>>1;
	if(sum[ls[x]]<=s){
		res+=cnt[ls[x]]; 
		res+=Query(rs[x],mid+1,r,s-sum[ls[x]]);
	}
	else res=Query(ls[x],l,mid,s);
	
	return res; 
}
signed main(){
	read(n);read(q);ll ns=0;
	for(int i=1;i<=n;++i){
		read(a[i]);
		if(a[i]<=0)	ns+=a[i];
		else Modify(rt,1,M,1,a[i],a[i]);
	}
	while(q--){
		int x,v;read(x),read(v);
		if(a[x]>0&&v<=0){
			Modify(rt,1,M,-1,-a[x],a[x]);
			ns+=v;
			a[x]=v;
			int ans=0;
			if(cnt[1]) ans=1;
//			cout<<Query(1,1,M,-ns)x	x<<"????\n";
			print(ans+Query(1,1,M,-ns)),putchar('\n');
		}
		else if(a[x]>0&&v>0){
			Modify(rt,1,M,-1,-a[x],a[x]);
			a[x]=v;
			Modify(rt,1,M,1,a[x],a[x]);
			int ans=0;
			if(cnt[1]) ans=1;
			print(ans+Query(1,1,M,-ns)),putchar('\n');
		}
		else if(a[x]<=0&&v>0){
			ns-=a[x];
			a[x]=v;
			Modify(rt,1,M,1,a[x],a[x]);
		int ans=0;
			if(cnt[1]) ans=1;
			print(ans+Query(1,1,M,-ns)),putchar('\n');
		}
		else{
			ns-=a[x];a[x]=v;
			ns+=a[x];
			int ans=0;
			if(cnt[1]) ans=1;
			print(ans+Query(1,1,M,-ns)),putchar('\n');
		}
	}
	return 0;
}
/*
3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1
*/
	

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

0

result:

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