QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755824#7787. Maximum RatingweiqianpingWA 1ms5752kbC++141.8kb2024-11-16 18:07:472024-11-16 18:07:47

Judging History

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

  • [2024-11-16 18:07:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5752kb
  • [2024-11-16 18:07:47]
  • 提交

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<pair<ll,ll> > pq;
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,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],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,x});
					a[x]=v;
				}
				else
				{
					sumz-=a[x];
					sumz+=v;
					sumt-=a[x];
					sumt+=v;
					mpp[a[x]]--;
					mpp[v]++;
					pqq.push({v,x});
					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,x});
				f[x]=1;
				a[x]=v;
			}
			else//f->f
			{
				sumf-=a[x];
				sumf+=v;
			}
		}
		while(!pq.empty() && sumz-sumt>=abs(sumf))//
		{
			v=pq.top().first;
			x=pq.top().second;
			pq.pop();
			if(mp[v])
			{
				f[x]=0;
				mp[v]--;
				sumt+=v;
				t++;
				mpp[v]++;
				pqq.push({v,x});
			}
		}
		while(!pqq.empty() && sumz-sumt+pqq.top().first<=abs(sumf))
		{
			v=pqq.top().first;
			x=pqq.top().second;
			pqq.pop();
			if(mpp[v])
			{
				sumt-=v;
				t--;
				mpp[v]--;
				pq.push({v,x});
				f[x]=1;
				mp[v]++;
			}
		}
		cout<<z-t+1<<endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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
631
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000...

result:

wrong answer 3rd numbers differ - expected: '252', found: '631'