QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#755707#7787. Maximum RatingweiqianpingWA 1ms5712kbC++141.7kb2024-11-16 17:55:312024-11-16 17:55:33

Judging History

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

  • [2024-11-16 17:55:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5712kb
  • [2024-11-16 17:55:31]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const ll MAX=2e5+5;
ll n,q,a[MAX],x,v,sumf=0,sumz=0,sumt=0,t=0,f[MAX],z=0;
priority_queue<ll> pq;
priority_queue<ll,vector<ll>,greater<ll> > pqq;
map<ll,ll> mp,mpp;
int main()
{
	cin>>n>>q;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		if(a[i]>0)
		{
			sumz+=a[i];
			pq.push(a[i]);
			f[i]=1;
			mp[a[i]]++;
			z++;
		}
		else
		{
			sumf+=a[i];
		}
	}
	for(int i=1;i<=q;++i)
	{
		cin>>x>>v;
		if(a[x]>0)//z
		{
			if(v>0)//z->z
			{
				if(f[x])//zin
				{
					sumz-=a[x];
					sumz+=v;
					mp[a[x]]--;
					mp[v]++;
					pq.push(v);
					a[x]=v;
				}
				else
				{
					sumz-=a[x];
					sumz+=v;
					sumt-=a[x];
					mpp[a[x]]--;
					mpp[v]++;
					pqq.push(v);
					sumt+=v;
					a[x]=v;
				}
			}
			else//z->f
			{
				if(f[x])//zin
				{
					sumz-=a[x];
					sumf+=v;
					z--;
					mp[a[x]]--;
					a[x]=v;
					f[x]=0;
				}
				else
				{
					sumz-=a[x];
					sumf+=v;
					z--;
					sumt-=a[x];
					mpp[a[x]]--;
					t--;
					a[x]=v;
				}
			}
		}
		else//f
		{
			if(v>0)//f->z
			{
				sumf-=a[x];
				sumz+=v;
				z++;
				mp[v]++;
				pq.push(v);
				f[x]=1;
				a[x]=v;
			}
			else//f->f
			{
				sumf-=a[x];
				sumf+=v;
			}
		}
		while(!pq.empty() && sumz-sumt>=abs(sumf))//
		{
			v=pq.top();
			pq.pop();
			if(mp[v])
			{
				mp[v]--;
				sumt+=v;
				t++;
				mpp[v]++;
				pqq.push(v);
			}
		}
		while(!pqq.empty() && sumz-sumt+pqq.top()<=abs(sumf))
		{
			v=pqq.top();
			pqq.pop();
			sumt-=v;
			t--;
			mpp[v]--;
			pq.push(v);
			mp[v]++;
		}
		cout<<z-t+1<<endl;
	}
}

详细

Test #1:

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

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

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'