QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#785728#7787. Maximum RatingaYi_7WA 1ms7968kbC++171.9kb2024-11-26 18:58:152024-11-26 18:58:15

Judging History

This is the latest submission verdict.

  • [2024-11-26 18:58:15]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7968kb
  • [2024-11-26 18:58:15]
  • Submitted

answer

#include<bits/stdc++.h>

using namespace std;
int arr[2000009];
int tot=1;
int sum[29000009],cnt[2000009];
int ll[2000009],rr[2000009];
const int maxn=1000000000;

void add(int id,int l,int r,int val,int f)
{
   if(l==r)
   {
     sum[id]+=val*f;
     cnt[id]+=f;
     return ;
   }
   int mid=(l+r)>>1;
   if(val<=mid)
   {
      if(!ll[id]) ll[id]=++tot;
      add(ll[id],l,mid,val,f);
   }
   else
   {
      if(!rr[id]) rr[id]=++tot;
      add(rr[id],mid+1,r,val,f);
   }
   sum[id]=sum[ll[id]]+sum[rr[id]];
   cnt[id]=cnt[ll[id]]+cnt[rr[id]];
}


int cut;
void fnd(int id,int l,int r,int s)///遭到第一个大于的地方;
{
    if(l==r)
    {
      int jishu=sum[id]/cnt[id];
      cut+=s/jishu;
     return ;
    }
    int mid=(l+r)>>1;
    if(ll[id]&&sum[ll[id]]>s)
    {
      fnd(ll[id],l,(l+r)>>1,s);
    }
     else
     {

        cut+=cnt[ll[id]];
        s-=sum[ll[id]];
        fnd(rr[id],mid+1,r,s);
     }
}

int main()
{
   int n,q,sumf=0,zheng=0;
   scanf("%d%d",&n,&q);
   for(int i=1;i<=n;i++)
   {
      scanf("%d",&arr[i]);
      //int sumf=0;
      if(arr[i]<=0) sumf+=arr[i];
      else   zheng++;
   }
   for(int i=1;i<=q;i++)
   {
      int a,b;
      scanf("%d%d",&a,&b);
      if(arr[a]<=0)
      {
          sumf-=arr[a];
         if(b<=0)
         {
             sumf+=b;
         }
         else
         {
             zheng++;
           add(1,1,maxn,b,1);
         }
      }
      else
      {
          if(b<=0)
          {
             zheng--;
             sumf+=b;
          }
          else
          {
            add(1,1,maxn,arr[a],-1);
            add(1,1,maxn,b,-1);
          }
      }
      arr[a]=b;
      if(-sumf>=sum[1])
      {
          printf("%d\n",zheng+1);
      }
      else
      {
          cut=0;
          fnd(1,1,maxn,-sumf);
          printf("%d\n",cut);
      }
   }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7968kb

input:

3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

output:

4
3
2
2
3

result:

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