QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#795658 | #7787. Maximum Rating | youyouyou | ML | 2ms | 11840kb | C++14 | 3.5kb | 2024-11-30 22:50:36 | 2024-11-30 22:50:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
typedef struct{
i64 score,num;
}dian;
i64 ans[800005][2],lisan[400005],chaxvn[200005][2],fusum=0,chushi[200005];
bool f=false;
dian a[400005];
int lc(int p){return p<<1;}
int rc(int p){return p<<1|1;}
void push_up(int p){
ans[p][0]=(ans[lc(p)][0]+ans[rc(p)][0]); //查询方式
ans[p][1]=(ans[lc(p)][1]+ans[rc(p)][1]); //查询方式
}
void build(i64 p,i64 l,i64 r)
{
if(l==r){ans[p][0]=a[l].num*a[l].score;ans[p][1]=a[l].num; return ;} //建树,树里是什么
i64 mid=(l+r)>>1;
build(lc(p),l,mid);
build(rc(p),mid+1,r);
push_up(p);
}
void update(i64 nl,i64 nr,i64 l,i64 r,i64 p,i64 k)
{
if(nl<=l&&r<=nr) //更新值、懒标记
{
ans[p][1]+=k;
ans[p][0]+=k*a[l].score;
return ;
}
i64 mid=(l+r)>>1;
if(nl<=mid)update(nl,nr,l,mid,lc(p),k);
if(nr>mid) update(nl,nr,mid+1,r,rc(p),k);
push_up(p);
}
i64 query(i64 l,i64 r,i64 p,i64 val)
{
if(l==r){
if(ans[p][0]>val){
i64 jige=val/a[l].score;
if(jige*a[l].score<=val)jige++;
return jige;
}
return -ans[p][1];
}
i64 mid=(l+r)>>1;
i64 res=0;
if(ans[p][0]>val){
i64 zuo=query(l,mid,lc(p),val);
if(zuo<=0){
res+=(-zuo);
i64 you= query(mid+1,r,rc(p),val-ans[lc(p)][0]);
if(you<=0){
res+=(-you);
return -res;
}else{
res+=you;
return res;
}
}else{
return zuo;
}
}else{
return -ans[p][1];
}
}
void solve()
{
i64 n,m,ls=0;
cin>>n>>m;
for(i64 i=1;i<=n;i++){
cin>>chushi[i];
if(chushi[i]>0){
lisan[++ls]=chushi[i];
}
}
for(i64 i=1;i<=m;i++){
cin>>chaxvn[i][0]>>chaxvn[i][1];
if(chaxvn[i][1]>0){
lisan[++ls]=chaxvn[i][1];
}
}
sort(lisan+1,lisan+1+ls);
i64 tot=unique(lisan+1,lisan+1+ls)-lisan-1;
map<i64,i64> mp;
for(i64 i=1;i<=tot;i++){
a[i].num=0;
a[i].score=lisan[i];
mp[lisan[i]]=i;
}
for(i64 i=1;i<=n;i++){
if(chushi[i]<0)fusum+=(-chushi[i]);
else if(chushi[i]>0){
i64 weizhi=mp[chushi[i]];
a[weizhi].num++;
}
}
build(1,1,tot);
for(i64 i=1;i<=m;i++){
i64 qian=chushi[chaxvn[i][0]],hou=chaxvn[i][1];
chushi[chaxvn[i][0]]=chaxvn[i][1];
i64 wz1,wz2;
if(qian<=0&&hou<=0){
fusum+=(qian-hou);
}else if(qian<=0){
fusum-=(-qian);
wz2=mp[hou];
update(wz2,wz2,1,tot,1,1);
}else if(hou<=0){
fusum+=(-hou);
wz1=mp[qian];
update(wz1,wz1,1,tot,1,-1);
}else{
wz1=mp[qian],wz2=mp[hou];
update(wz2,wz2,1,tot,1,1);
update(wz1,wz1,1,tot,1,-1);
}
i64 jieguo=query(1,tot,1,fusum);
if(jieguo<0){
cout<<ans[1][1]+1<<'\n';
}else if(jieguo==0){
cout<<0<<'\n';
}else{
cout<<jieguo<<'\n';
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
i64 T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11824kb
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: 11840kb
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: 11828kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Memory Limit Exceeded
input:
1 1 -1000000000 1 -1000000000