QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#679149#7787. Maximum RatingheyuhaoRE 1ms7752kbC++203.5kb2024-10-26 16:59:362024-10-26 16:59:37

Judging History

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

  • [2024-10-26 16:59:37]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7752kb
  • [2024-10-26 16:59:36]
  • 提交

answer

#pragma GCC optimize(3)
#include<cstring>
#include<bits/stdc++.h>
#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();
    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: 7728kb

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: 7752kb

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: 7724kb

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

output:


result: