QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#363498#7523. Partially Free MealDelay_for_five_minutes#WA 295ms64704kbC++201.5kb2024-03-23 23:28:042024-03-23 23:28:04

Judging History

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

  • [2024-03-23 23:28:04]
  • 评测
  • 测评结果:WA
  • 用时:295ms
  • 内存:64704kb
  • [2024-03-23 23:28:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N=2e5+3,M=1e9;
int n;
pii a[N];

int rt=0,tot=0,lc[N*40],rc[N*40],s[N*40];
ll sum[N*40];
void upd(int& x,int l,int r,int p,int v){
    if(!x)x=++tot;
    s[x]+=v,sum[x]+=p*v;
    if(l==r)return;
    int mid=(l+r)>>1;
    if(p<=mid)upd(lc[x],l,mid,p,v);
    else upd(rc[x],mid+1,r,p,v);
}
ll qry(int x,int l,int r,int p){
    if(l==r)return s[x];
    int mid=(l+r)>>1;
    if(p<=mid)return qry(lc[x],l,mid,p);
    return sum[lc[x]]+qry(rc[x],mid+1,r,p);
}
int kth(int x,int l,int r,int k){
    if(l==r)return l;
    int mid=(l+r)>>1;
    if(k<=s[lc[x]])return kth(lc[x],l,mid,k);
    return kth(rc[x],mid+1,r,k-s[lc[x]]);
}

ll c[N],ans[N];
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i].second>>a[i].first;
    sort(a+1,a+n+1);
    for(int i=2;i<=n;++i)c[i]=a[i].second-a[i].first+a[i-1].first;
    for(int i=1;i<=n;++i)upd(rt,1,M,a[i].second,1);
    int j=1;
    for(int i=n;i>=2;--i){
        while(j<=n-1){
            int pos=kth(rt,1,M,j+1);
            if(pos<=c[i])ans[j]=qry(rt,1,M,pos)+a[i].first,++j;
            else break;
        }
        upd(rt,1,M,a[i].second,-1);
    }
    ll ss=0;
    for(int i=1;i<=j-1;++i)ss+=a[i].second;
    for(int i=j;i<=n;++i){
        ss+=a[i].second;
        ans[i]=ss+a[i].first;
    }
    for(int i=1;i<=n;++i)cout<<ans[i]<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9832kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 295ms
memory: 64704kb

input:

200000
466436993 804989151
660995237 756645598
432103296 703610564
6889895 53276988
873617076 822481192
532911431 126844295
623111499 456772252
937464699 762157133
708503076 786039753
78556972 5436013
582960979 398984169
786333369 325119902
930705057 615928139
924915828 506145001
164984329 208212435...

output:

1000002368
1000006588
1000015275
1000025351
1000037370
1000049896
1000066241
1000083467
1000103048
1000126448
1000153303
1000180557
1000212355
1000244637
1000285636
1000329000
1000372599
1000419682
1000468520
1000519407
1000572800
1000627809
1000689337
1000751933
1000820307
1000890067
1000960649
100...

result:

wrong answer 1st lines differ - expected: '1318594', found: '1000002368'