QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697764#7787. Maximum RatingblhxzjrWA 1ms5664kbC++231.5kb2024-11-01 15:39:352024-11-01 15:39:35

Judging History

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

  • [2024-11-01 15:39:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5664kb
  • [2024-11-01 15:39:35]
  • 提交

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){
		return gs(id);
	}
	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(query(root,1,mx,abs(sum))==-1){
			ans=zs+1;
		}
		else ans=query(root,1,mx,abs(sum));
		// cout<<zs<<' '<<query(root,1,mx,abs(sum))<<' ';
		// cout<<sum(root)<<' ';
		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: 5664kb

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: -100
Wrong Answer
time: 1ms
memory: 5660kb

input:

3 5
1 2 3
3 4
2 -2
1 3
3 1
2 1

output:

1
2
1
2
2

result:

wrong answer 5th numbers differ - expected: '1', found: '2'