QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#670040 | #7787. Maximum Rating | Yshanqian | RE | 1ms | 9768kb | C++20 | 1.7kb | 2024-10-23 20:19:08 | 2024-10-23 20:19:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std ;
#define endl "\n"
#define ll long long
const ll N=5e5+11;
ll n,q,tot,a[N],b[N],sum[N*8],cnt[N*8];
struct node {ll x,v;}c[N];
void update(ll p,ll l,ll r,ll pos,ll val,ll add) {
if(l==r) {
sum[p]+=val*add;
cnt[p]+=add;
return;
}
ll mid=(l+r)/2;
if(pos<=mid) update(p<<1,l,mid,pos,val,add);
else update(p<<1|1,mid+1,r,pos,val,add);
sum[p]=sum[p<<1]+sum[p<<1|1];
cnt[p]=cnt[p<<1]+cnt[p<<1|1];
}
ll ask(ll p,ll l,ll r,ll fu){
if(fu<=0) return 0;
if(l==r){
if(cnt[p]==0) return 0;
return min(cnt[p],fu/(sum[p]/cnt[p]));
}
ll mid=(l+r)/2;
if(sum[p<<1]<=fu) return cnt[p<<1]+ask(p<<1|1,mid+1,r,fu-sum[p<<1]);
else return ask(p<<1,l,mid,fu);
}
void solve() {
cin>>n>>q;
ll tot=0,fu=0;
for(ll i=1; i<=n; i++) {
cin>>a[i];
if(a[i]<=0) fu+=a[i];
else b[++tot]=a[i];
}
for(ll i=1;i<=q;i++){
cin>>c[i].x>>c[i].v;
if(c[i].v>0) b[++tot]=c[i].v;
}
sort(b+1,b+1+tot);
tot=unique(b+1,b+1+tot)-b-1;
for(ll i=1; i<=n; i++) {
if(a[i]>0) {
ll x=lower_bound(b+1,b+1+tot,a[i])-b;
update(1,1,tot,x,a[i],1);
}
}
for(ll i=1;i<=q;i++){
ll lst=a[c[i].x];
a[c[i].x]=c[i].v;
if(lst<=0) fu-=lst;
else {
ll pos=lower_bound(b+1,b+1+tot,lst)-b;
update(1,1,tot,pos,lst,-1);
}
if(a[c[i].x]<=0) fu+=a[c[i].x];
else {
ll pos=lower_bound(b+1,b+1+tot,a[c[i].x])-b;
update(1,1,tot,pos,a[c[i].x],1);
}
cout<<ask(1,1,tot,-fu)+1<<endl;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll Test=1;
//cin>>Test;
while(Test--) {
solve();;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9748kb
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: 9768kb
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: 9720kb
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