QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#622537#7787. Maximum RatinglolteWA 0ms40556kbC++141.8kb2024-10-08 22:25:092024-10-08 22:25:10

Judging History

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

  • [2024-10-08 22:25:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:40556kb
  • [2024-10-08 22:25:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5+10;
int n,m,a[maxn],b[maxn*2],tot,cnt[maxn*20],sum=0,siz=0,tr[maxn*20];
struct question{
	int x,v;
}q[maxn];
#define lson l,mid,t<<1
#define rson mid+1,r,t<<1|1
void push_up(int t) {
	cnt[t]=cnt[t<<1]+cnt[t<<1|1];	
	tr[t]=tr[t<<1]+tr[t<<1|1];	
} 
void change(int l,int r,int t,int val,int opt) {
	if (l==r) {
		cnt[t]+=opt;
		tr[t]+=b[val]*opt;
		return;
	}
	int mid=(l+r)>>1;
	if (val<=mid) {
		change(lson,val,opt);
	}
	else {
		change(rson,val,opt);
	}
	push_up(t);
}
int query(int l,int r,int t,int k) {
	if (tr[t]<=k) {
		return cnt[t];
	}
	if (l==r) {
		return sum<=0 ? 0 : (sum+b[l]-1)/b[l];
	}
	int mid=(l+r)>>1;
	int ans=0;
	if (tr[t<<1|1]>=k) {
		ans=query(rson,k);
	}
	else {
		ans=cnt[t<<1|1];
		ans+=query(lson,k-tr[t<<1|1]);
	}
	return ans;
}
int	f(int x) {
	return lower_bound(b+1,b+tot+1,x)-b;
}
signed main(){
    ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);std::cout.tie(nullptr);
    memset(cnt,0,sizeof(cnt));
    cin>>n>>m;
    int qwq=0;
    for (int i=1;i<=n;++i) {
    	cin>>a[i];
    	if (a[i]>0) {
    		b[++qwq]=a[i];
		}
	}
	
	for (int i=1;i<=m;++i) {
		cin>>q[i].x>>q[i].v;
		if (q[i].v>0) {
    		b[++qwq]=q[i].v;
		}
	}
	sort(b+1,b+qwq+1);
	tot=unique(b+1,b+qwq+1)-b-1;
	for (int i=1;i<=n;++i) {
		if (a[i]>0) {
			++siz;
			change(1,tot,1,f(a[i]),1);
		}
		sum+=a[i];
	}
	for (int i=1;i<=m;++i) {
		if (a[q[i].x]>0) {
			change(1,tot,1,f(a[q[i].x]),-1);
			--siz;
		}
		if (q[i].v>0) {
			change(1,tot,1,f(q[i].v),1);
			++siz;
		}
		sum+=q[i].v-a[q[i].x];
		a[q[i].x]=q[i].v;
		if (sum<=0) {
			cout<<siz+1<<"\n";
		}
		else {
			cout<<siz-query(1,tot,1,sum)+1<<"\n";
		}
	}
	return 0; 
}


详细

Test #1:

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

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: 0ms
memory: 36468kb

input:

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

output:

1
2
0
2
1

result:

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