QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#546296#7523. Partially Free MealLiangsheng298TL 0ms11876kbC++142.5kb2024-09-03 22:28:352024-09-03 22:28:36

Judging History

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

  • [2024-09-03 22:28:36]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:11876kb
  • [2024-09-03 22:28:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(){
    T x=0;char ch=getchar();bool fl=false;
    while(!isdigit(ch)){if(ch=='-')fl=true;ch=getchar();}
    while(isdigit(ch)){
        x=(x<<3)+(x<<1)+(ch^48);ch=getchar();
    }
    return fl?-x:x;
}
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define LL long long
#define read() read<int>()
const int maxn = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
int cnt;
struct tree{
    int ls,rs,sz;
    LL val;
}t[maxn<<5];
#define mid ((l+r)>>1)
void build(int &p,int l,int r){
    p=++cnt;
    if(l==r)return ;
    build(t[p].ls,l,mid);
    build(t[p].rs,mid+1,r);
}
void update(int &p,int pre,int l,int r,int pos,LL val){
    p=++cnt;
    cerr<<p<<" "<<pre<<endl;
    t[p].sz=t[pre].sz+1;
    t[p].ls=t[pre].ls;t[p].rs=t[pre].rs;
    t[p].val=t[pre].val+val;
    if(l==r)return ;
    if(pos<=mid)update(t[p].ls,t[pre].ls,l,mid,pos,val);
    else update(t[p].rs,t[pre].rs,mid+1,r,pos,val);
}
LL query(int p,int l,int r,int k){
    if(!k)return 0;
    if(l==r){
        return t[p].val/t[p].sz*k;
    }
    if(t[t[p].ls].sz>=k)return query(t[p].ls,l,mid,k);
    LL res=t[t[p].ls].val;
    res+=query(t[p].rs,mid+1,r,k-t[t[p].ls].sz);
    return res;
}
int rt[maxn],n;
LL f[maxn],b[maxn],tot,mp[maxn];
pair<LL,LL> a[maxn];
inline LL w(int k,int x){
    return a[x].first+mp[a[x].second]+query(rt[x-1],1,tot,k-1);
}
void DP(int l,int r,int k_l,int k_r){
    assert(k_l<=k_r);
    int k=max(k_l,mid);
    for(int i=max(k_l,mid);i<=k_r;i++)if(w(mid,i)<w(mid,k))k=i;
    f[mid]=w(mid,k);
    if(l<mid)DP(l,mid-1,k_l,k);
    if(r>mid)DP(mid+1,r,k,k_r);                                                                                                                                                                                                                                                                                                                                    
}
int main(){
    FASTIO;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].second>>a[i].first;
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)b[i]=a[i].second;
    sort(b+1,b+1+n);
    tot=unique(b+1,b+1+n)-(b+1);
    build(rt[0],1,tot);
    for(int i=1;i<=n;i++){
        int pos=lower_bound(b+1,b+1+tot,a[i].second)-b;
        mp[pos]=a[i].second;
        a[i].second=pos;
        update(rt[i],rt[i-1],1,tot,a[i].second,mp[a[i].second]);
    }
    DP(1,n,1,n);
    for(int i=1;i<=n;i++)cout<<f[i]<<'\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

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:


result: