QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#626962 | #7787. Maximum Rating | Stelor | WA | 1ms | 7640kb | C++20 | 2.0kb | 2024-10-10 14:13:40 | 2024-10-10 14:13:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5e5+100;
int n,a[N],b[N];
struct Node
{
int sum;
int cnt;
} tree[N<<2];
void push_up(int u)
{
tree[u].cnt=tree[u<<1].cnt+tree[u<<1|1].cnt;
tree[u].sum=tree[u<<1].sum+tree[u<<1|1].sum;
}
void change(int u,int l,int r,int x,int rea)
{
if(l==r)
{
tree[u].sum+=rea;
if(rea>0)
tree[u].cnt++;
else tree[u].cnt--;
return;
}
int mid=l+r>>1;
if(x<=mid) change(u<<1,l,mid,x,rea);
else change(u<<1|1,mid+1,r,x,rea);
push_up(u);
}
int query(int u,int l,int r,int fu)
{
if(l==r)
{
return min(tree[u].cnt,fu/b[l]);
}
int mid=l+r>>1;
if(tree[u<<1].sum<=fu)
{
return tree[u<<1].cnt+query(u<<1|1,mid+1,r,fu-tree[u<<1].sum);
}
else
{
return query(u<<1,l,mid,fu);
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> n >> q;
int fu=0;
int m=0;
for(int i=1;i<=n;++i)
{
cin >> a[i];
fu+=min(0ll,a[i]);
if(a[i]>0)
{
b[++m]=a[i];
}
}
vector<array<int,2>> op(q);
for(int i=0;i<q;++i) {
cin >> op[i][0] >> op[i][1];
b[++m]=op[i][1];
}
sort(b+1,b+1+m);
m=unique(b+1,b+1+m)-b-1;
int cnt=0;
for(int i=1;i<=n;++i)
{
if(a[i]<=0) continue;
cnt++;
int id=lower_bound(b+1,b+1+m,a[i])-b;
change(1,1,m,id,a[i]);
}
for(auto [idx,p]:op)
{
if(a[idx]<=0)
{
if(p<=0)
{
fu=fu-a[idx]+p;
}
else
{
cnt++;
fu-=a[idx];
int id=lower_bound(b+1,b+1+m,p)-b;
change(1,1,m,id,p);
}
}
else
{
if(p<=0)
{
cnt--;
fu=fu+p;
int id=lower_bound(b+1,b+1+m,a[idx])-b;
change(1,1,m,id,-a[idx]);
}
else
{
int id=lower_bound(b+1,b+1+m,a[idx])-b;
change(1,1,m,id,-a[idx]);
id=lower_bound(b+1,b+1+m,p)-b;
change(1,1,m,id,p);
}
}
cout<<query(1,1,m,-fu)+1<<endl;
a[idx]=p;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7600kb
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: 7640kb
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: 7632kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 7632kb
input:
1 1 -1000000000 1 -1000000000
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'