QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#674706#7787. Maximum Rating523555337WA 1ms5820kbC++142.7kb2024-10-25 17:16:482024-10-25 17:16:49

Judging History

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

  • [2024-10-25 17:16:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5820kb
  • [2024-10-25 17:16:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define ll long long
#define int long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define ret(i,a,b) for(int i = (a);i<=(b);++i)
const int N=2e5+5;
const int M=1e6+5;
const ll inf=1e18;
const ll mod=998244353;
ll ksm(ll a,ll b)
{
	ll ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
	{
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
	{
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int n,q,x,v;
int a[N],b[N];
void solve()
{
	cin>>n>>q;
	ll tot=0;
	ret(i,1,n)
	{
		cin>>a[i];
		if(a[i]<0) tot+=-a[i]; 
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	ll ans1=0;
	multiset<int,greater<int>> m1;
	multiset<int> m2;
	
	ret(i,1,n)
	{
		if(b[i]<=0) continue;
		if(ans1+b[i]<=tot)
		{
			ans1+=b[i];
			m1.insert(b[i]);
		}
		else m2.insert(b[i]);
	}
	ret(i,1,q)
	{
		cin>>x>>v;
		int u=a[x];
		if(u<=0)
		{
			tot+=u;
		}
		else
		{
			if(m1.find(u)!=m1.end())
			{
				m1.erase(m1.find(u));
				ans1-=u;
			}
			else
			{
				m2.erase(m2.find(u));
			}
			
		}
		while(1)
		{
			if(m1.empty()) break;
			if(!m2.empty())
			{
				if((*m1.begin())>(*m2.begin()))
				{
					auto dd=m1.begin();
					ans1-=(*dd);
					m1.erase(dd);
					m2.insert(*dd);
					continue;
				}
			}
			if(ans1>tot)
			{
				auto dd=m1.begin();
				ans1-=(*dd);
				m1.erase(dd);
				m2.insert(*dd);
			}
			else break;
		}
		while(1)
		{
			if(m2.empty()) break;
			auto dd=m2.begin();
			if(ans1+(*dd)<=tot)
			{
				ans1+=(*dd);
				m1.insert(*dd);
				m2.erase(dd);
			}
			else break;
		}
		a[x]=v;
		if(v<=0)
		{
			tot-=v;
		}
		else
		{
			m1.insert(v);
			ans1+=v;
		}
		while(1)
		{
			if(m1.empty()) break;
			if(!m2.empty())
			{
				if((*m1.begin())>(*m2.begin()))
				{
					auto dd=m1.begin();
					ans1-=(*dd);
					m1.erase(dd);
					m2.insert(*dd);
					continue;
				}
			}
			if(ans1>tot)
			{
				auto dd=m1.begin();
				ans1-=(*dd);
				m1.erase(dd);
				m2.insert(*dd);
			}
			else break;
		}
		while(1)
		{
			if(m2.empty()) break;
			auto dd=m2.begin();
			if(ans1+(*dd)<=tot)
			{
				ans1+=(*dd);
				m1.insert(*dd);
				m2.erase(dd);
			}
			else break;
		}
		if(m1.empty()&&m2.empty()) cout<<"0\n";
		else cout<<m1.size()+1<<endl;
	}
	return ;
}
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	int _=1;
	//cin>>_;
	while(_--) solve();
	return 0;
}




詳細信息

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

0

result:

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