QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748913#7787. Maximum RatingyldWA 1ms3820kbC++202.4kb2024-11-14 21:56:372024-11-14 21:56:39

Judging History

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

  • [2024-11-14 21:56:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3820kb
  • [2024-11-14 21:56:37]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
const int MAXN=1e6+5;
struct SegmentTree{
    int l,r,sum,num;
}tr[MAXN];
void update(int rt)
{
    tr[rt].sum=tr[ls].sum+tr[rs].sum;
    tr[rt].num=tr[ls].num+tr[rs].num;
}
void build(int l,int r,int rt)
{
    tr[rt].l=l,tr[rt].r=r;
    if(l==r) return;
    int mid=l+r>>1;
    build(l,mid,ls);
    build(mid+1,r,rs);
    update(rt);
}
void modify(int pos,int rt,int c)
{
    if(tr[rt].l==tr[rt].r)
    {
        tr[rt].sum+=c;
        if(c>0) tr[rt].num++;
        else tr[rt].num--;
        return;
    }
    int mid=tr[rt].l+tr[rt].r>>1;
    if(pos<=mid) modify(pos,ls,c);
    else modify(pos,rs,c);
    update(rt);
}
int query(int l,int r,int rt,int num)
{
    // cout<<l<<' '<<r<<' '<<tr[rt].sum<<' '<<tr[rt].num<<' '<<num<<endl;
    if(l==r)
    {
        if(tr[rt].sum<=num) return tr[rt].num;
        else return 0;
    }
    int mid=l+r>>1;
    if(tr[ls].sum>=num) return query(l,mid,ls,num);
    else return tr[ls].num+query(mid+1,r,rs,num-tr[ls].sum);
}
void solve()
{
    int n,q;
    cin>>n>>q;
    vector<int> a(n+1),X;
    vector<pair<int,int>> ask(q+1);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]>0)X.push_back(a[i]);
    }
    for(int i=1;i<=q;i++)
    {
        cin>>ask[i].first>>ask[i].second;
        if(ask[i].second>0) X.push_back(ask[i].second);
    }
    sort(X.begin(),X.end());
    X.erase(unique(X.begin(),X.end()),X.end());
    int len=X.size();
    if(len==0){cout<<1<<endl;return;}
    build(1,len,1);
    int fu=0;   
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=0) fu-=a[i];
        else modify(lower_bound(X.begin(),X.end(),a[i])-X.begin()+1,1,a[i]);
    }
    for(int i=1;i<=q;i++)
    {
        int pos=ask[i].first;
        if(a[pos]<=0) fu+=a[pos];
        else modify(lower_bound(X.begin(),X.end(),a[pos])-X.begin()+1,1,-a[pos]);
        a[pos]=ask[i].second;
        if(a[pos]<=0) fu-=a[pos];
        else modify(lower_bound(X.begin(),X.end(),a[pos])-X.begin()+1,1,a[pos]);
        // cout<<fu<<endl;
        cout<<query(1,len,1,fu)+1<<endl;
        // cout<<tr[1].sum<<' '<<tr[1].num<<endl;
        // cout<<"============\n";
    }
}
signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t=1;
    while(t--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3592kb

input:

1000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 1st numbers differ - expected: '946', found: '1'