QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#546059#7523. Partially Free MealLiangsheng298WA 589ms109216kbC++142.1kb2024-09-03 19:21:582024-09-03 19:21:58

Judging History

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

  • [2024-09-03 19:21:58]
  • 评测
  • 测评结果:WA
  • 用时:589ms
  • 内存:109216kb
  • [2024-09-03 19:21:58]
  • 提交

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;
    t[p].ls=t[pre].ls;t[p].rs=t[pre].rs;
    t[p].sz=t[pre].sz+1;
    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(t[p].sz<k)return INF;
    if(!k)return 0;
    if(l==r)return t[p].val;
    if(t[t[p].ls].sz>=k)return query(t[p].ls,l,r,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){
    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;
}

詳細信息

Test #1:

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

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 589ms
memory: 109216kb

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:

1318594
4557430888800148993
4557430888802038417
4557430888804400925
4557430888806171244
4557430888808053746
4557430888809980264
4557430888811162609
4557430888812307222
4557430888813618679
4557430888815003294
4557430888816599026
4557430888818167032
4557430888819524178
4557430888820835635
455743088882...

result:

wrong answer 2nd lines differ - expected: '3208018', found: '4557430888800148993'