QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#266563#7619. Make SYSU Great Again Iucup-team073#RE 0ms0kbC++202.4kb2023-11-26 15:26:152023-11-26 15:26:16

Judging History

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

  • [2023-11-26 15:26:16]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-26 15:26:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long

int rest[500010],d[500010],a[500010];
int tree[2000010],lazy[2000010];
void build(int p,int l,int r){
  lazy[p]=0;
  if(l==r){
    tree[p]=d[l];
    return;
  }
  int mid=l+r>>1;
  build(p<<1,l,mid);
  build(p<<1|1,mid+1,r);
  tree[p]=tree[p<<1]+tree[p<<1|1];
}
void pushdown(int p,int l,int r){
  if(lazy[p]){
    int mid=l+r>>1;
    tree[p<<1]+=lazy[p]*(mid-l+1);
    tree[p<<1|1]+=lazy[p]*(r-mid);
    lazy[p<<1]+=lazy[p];
    lazy[p<<1|1]+=lazy[p];
    lazy[p]=0;
  }
}
void modify(int p,int l,int r,int x,int y,int k){
  if(l>=x&&r<=y){
    tree[p]+=k*(r-l+1);
    lazy[p]+=k;
    return;
  }
  pushdown(p,l,r);
  int mid=l+r>>1;
  if(mid>=x)modify(p<<1,l,mid,x,y,k);
  if(mid<y)modify(p<<1|1,mid+1,r,x,y,k);
  tree[p]=tree[p<<1]+tree[p<<1|1];
}
int query(int p,int l,int r,int x){
  if(l==x&&r==x)return tree[p];
  pushdown(p,l,r);
  int mid=l+r>>1;
  if(mid>=x)return query(p<<1,l,mid,x);
  else return query(p<<1|1,mid+1,r,x);
}
signed main(){
  int n,k,q;cin>>n>>k>>q;
  for(int i=1;i<=n;++i)cin>>a[i];
  sort(a+1,a+n+1,greater<int>());
  for(int i=1;i<=n;++i)rest[i]=a[i]%k,d[i]=a[i]/k;
  //for(int i=1;i<=n;++i)cout<<d[i]<<' ';cout<<endl;
  build(1,1,n);
  int cur=1,gap=0;
  while(q--){
    char c;int x;cin>>c>>x;
    if(c=='C'){
      if(gap){
        if(x<cur-gap)modify(1,1,n,gap+1,gap+x,-1),gap+=x,x=0;
        else modify(1,1,n,gap+1,cur,-1),x-=(cur-gap),gap=0;
      }
      while(x){
        if(cur==n)break;
        int sum=(query(1,1,n,cur)-query(1,1,n,cur+1))*cur;
        //cout<<"sum="<<sum<<" cur="<<cur<<endl;
        if(sum<=x){
          x-=sum;
          modify(1,1,n,1,cur,query(1,1,n,cur+1)-query(1,1,n,cur));
          ++cur;
        }
        else{
          int t=x/cur;
          modify(1,1,n,1,cur,-t);
          t=x%cur;
          modify(1,1,n,1,t,-1);
          gap=t;
          x=0;
        }
      }
      if(cur==n&&x){
        int t=x/cur;modify(1,1,n,1,cur,-t);
        t=x%cur;modify(1,1,n,1,t,-1);
        gap=t,x=0;
      }
    }
    else{
      int sum1=cur-gap,sum2=cur;
      if(x<=sum1)cout<<query(1,1,n,gap+x)*k+rest[gap+x]<<endl;
      else if(x<=sum2)cout<<query(1,1,n,x-sum1)*k+rest[x-sum1]<<endl;
      else cout<<query(1,1,n,x)*k+rest[x]<<endl;
    }
    for(int i=1;i<=n;++i)cout<<query(1,1,n,i)<<' ';cout<<endl;
  }
  return 0;
}

/*
3 5 5
7 3 9
C 3
A 1
C 2
A 2
C 3
  
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3 6

output:


result: