QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#679163 | #7787. Maximum Rating | heyuhao | WA | 1ms | 7828kb | C++20 | 3.6kb | 2024-10-26 17:02:02 | 2024-10-26 17:02:03 |
Judging History
answer
#pragma GCC optimize(3)
#include<cstring>
#include<bits/stdc++.h>
#pragma GCC optimize(3)
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
const int N=2e5+10;
int n,q,nn;
long long fsum=0;
int a[N],b[5*N],cnt=0;
pair<int,int> c[N];
vector<int> all;
int find(int x)
{
return lower_bound(all.begin(),all.end(),x)-all.begin()+1;
}
struct node{
int l,r;
int date;
long long sum;
}tri[4*N];
void build(int u,int l,int r)
{
if(l==r)
{
tri[u].l=l;
tri[u].r=r;
tri[u].date=0;
tri[u].sum=0;
}
else
{
tri[u].l=l;
tri[u].r=r;
int m=l+r>>1;
build(u<<1,l,m);
build(u<<1|1,m+1,r);
tri[u].date=0;
tri[u].sum=0;
}
}
void modify(int u,int d,int v)
{
int l=tri[u].l,r=tri[u].r;
if(l==r)
{
tri[u].date+=v;
tri[u].sum+=all[d-1]*v;
}
else
{
int m=l+r>>1;
if(d<=m)
{
modify(u<<1,d,v);
tri[u].sum=tri[u<<1].sum+tri[u<<1|1].sum;
tri[u].date+=v;
}
else
{
modify(u<<1|1,d,v);
tri[u].sum=tri[u<<1].sum+tri[u<<1|1].sum;
tri[u].date+=v;
}
}
}
long long query(int u,int l,int r)
{
if(tri[u].l>=l&&tri[u].r<=r)
return tri[u].sum;
int m=tri[u].l+tri[u].r>>1;
if(r<=m)
return query(u<<1,l,r);
else if(l>m)
return query(u<<1|1,l,r);
else
return query(u<<1,l,r)+query(u<<1|1,l,r);
}
long long dquery(int u,int l,int r)
{
if(tri[u].l>=l&&tri[u].r<=r)
return tri[u].date;
int m=tri[u].l+tri[u].r>>1;
if(r<=m)
return query(u<<1,l,r);
else if(l>m)
return query(u<<1|1,l,r);
else
return query(u<<1,l,r)+query(u<<1|1,l,r);
}
int chose(long long sum)
{
int l=1,r=nn;
while(l<r)
{
int mid=l+r+1>>1;
if(query(1,1,mid)<=sum)
l=mid;
else
r=mid-1;
}
if(r==1&& query(1,1,1)>sum)
return 0;
return dquery(1,1,r);
}
void solve()
{
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=q;i++)
cin>>c[i].first>>c[i].second;
for(int i=1;i<=n;i++)
{
if(a[i]>0)
all.push_back(a[i]),cnt++;
else
fsum-=a[i];
}
for(int i=1;i<=1;i++)
{
if(c[i].second>0)
all.push_back(c[i].second);
}
sort(all.begin(),all.end());
all.erase(unique(all.begin(),all.end()),all.end());
// cout<<find(1);
nn=all.size();
if(nn==0)
{
cout<<"0\n";
return;
}
build(1,1,nn);
for(int i=1;i<=n;i++)
{
if(a[i]>0)
{
int x=find(a[i]);
modify(1,x,1);
}
}
// cout<<tri[1].sum;
// cout<<query(1,1,nn);
//cout<<chose(6);
//for(int i=0;i<=6;i++)
//{
// cout<<i<<" "<<chose(i)<<"\n";
//}
for(int i=1;i<=q;i++)
{
int x=c[i].first,v=c[i].second;
if(a[x]>0)
{
cnt--;
modify(1,find(a[x]),-1);
}
else
fsum+=a[x];
if(v>0)
{
cnt++;
modify(1,find(v),1);
}
else
fsum-=v;
a[x]=v;
int tt=chose(fsum);
cout<<tt+1<<"\n";
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
// cin>>t;
while(t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7668kb
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: 7800kb
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: 7828kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5632kb
input:
1 1 -1000000000 1 -1000000000
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'