QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713318#7787. Maximum RatingSoestxRE 1ms7700kbC++232.0kb2024-11-05 18:59:272024-11-05 18:59:28

Judging History

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

  • [2024-11-05 18:59:28]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7700kb
  • [2024-11-05 18:59:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int,int>
#define fi first
#define se second
#define lowbit(x) (x&(-x))
typedef long long LL;
typedef unsigned long long ull;
int n, m, k;
const int N = 1e6 + 10, M = 1e6, mod = 998244353;
int num[N], book[N];
int res, cnt;
int uni[N];

struct stu
{
	int sum,con;
}st[N<<2];

void push_up(int id)
{
	st[id].sum=st[id<<1].sum+st[id<<1|1].sum;
	st[id].con=st[id<<1].con+st[id<<1|1].con;
}

void modify(int id,int l,int r,int x,int y)
{
	if(l==r)
	{
		st[id].sum+=y*uni[x];
		st[id].con+=y;
		return;
	}
	int mid=(l+r)>>1;
	if(mid>=x) modify(id<<1,l,mid,x,y);
	else modify(id<<1|1,mid+1,r,x,y);
	push_up(id);
}

int quer(int id,int l,int r,int x)
{
	if(l==r)
	{
		int t=x/uni[l];
		return min(t,st[id].con);
	}
	int mid=(l+r)>>1;
	if(x>=st[id<<1].sum) return st[id<<1].con+quer(id<<1|1,mid+1,r,x-st[id<<1].con);
	else return quer(id<<1,l,mid,x);
}

int get(int x)
{
	return lower_bound(uni+1,uni+1+m,x)-uni;
}

void solve() {
	int con=0;
	cin>>n>>k;
	vector<pll> vt;
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(x>0) 
		{
			uni[++m]=x;
		}
		else con-=x;
		num[i]=x;
	}
	for(int i=1;i<=k;i++)
	{
		int a,b;
		cin>>a>>b;
		if(b>0) uni[++m]=b;
		vt.push_back({a,b});
	}
	sort(uni+1,uni+1+m);
	m=unique(uni+1,uni+1+m)-uni-1;
	for(int i=1;i<=n;i++)
	{
		if(num[i]<=0) continue;
		modify(1,1,m,get(num[i]),1);
	}
	for(auto it:vt)
	{
		int a=it.fi,b=it.se;
		if(num[a]>0) modify(1,1,m,get(num[a]),-1);
		if(num[a]<0) con+=num[a];
		
		num[a]=b;
		if(num[a]>0) modify(1,1,m,get(num[a]),1);
		if(num[a]<0) con-=num[a];
		
		//for(int i=1;i<=n;i++) cout<<num[i]<<" ";cout<<endl;
	//	cout<<con<<"---"<<st[1].con<<endl;;
		cout<<quer(1,1,m,con)+1<<endl;
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	//cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}
/*
100 100 10 20
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: -100
Runtime Error

input:

1 1
-1000000000
1 -1000000000

output:


result: