QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#467272 | #7523. Partially Free Meal | diandian2020 | TL | 1ms | 5956kb | C++14 | 1.7kb | 2024-07-08 15:29:00 | 2024-07-08 15:29:01 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=2e5+9;
const LL INF=1e16;
int n,m,b[N];
struct node{
int a,b;
bool operator<(const node &W)const{
return b<W.b;
}
}a[N];
struct Node{
int l,r,sz; LL sum;
}tr[N*40]; int rt[N],idx;
LL res[N];
int insert(int p,int l,int r,int x){
int q=++idx; tr[q]=tr[p];
tr[q].sz++,tr[q].sum+=b[x];
// printf("I %d %d %d %d %lld\n",q,l,r,tr[q].sz,tr[q].sum);
if(l==r) return q;
int mid=l+r>>1;
if(x<=mid) tr[q].l=insert(tr[p].l,l,mid,x);
else tr[q].r=insert(tr[p].r,mid+1,r,x);
return q;
}
LL query(int u,int l,int r,int k){
// printf("Q %d %d %d %d %lld\n",u,l,r,tr[u].sz,tr[u].sum);
if(tr[u].sz<k) return INF;
if(l==r) return tr[u].sum;
int mid=l+r>>1;
if(tr[tr[u].l].sz>=k) return query(tr[u].l,l,mid,k);
else return tr[tr[u].l].sum+query(tr[u].r,mid+1,r,k-tr[tr[u].l].sz);
}
void solve(int ql,int qr,int l,int r){
if(ql>qr) return;
int mid=ql+qr>>1,x; res[mid]=INF;
for(int i=1;i<=n;i++){
// printf("%d %d %lld\n",mid,i,query(rt[i-1],1,n,mid-1));
if(query(rt[i-1],1,n,mid-1)+a[i].a+a[i].b<res[mid]) res[mid]=query(rt[i-1],1,n,mid-1)+a[i].a+a[i].b,x=i;
}
solve(ql,mid-1,l,x),solve(mid+1,qr,x,r);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d",&a[i].a,&a[i].b),b[i]=a[i].a;
sort(a+1,a+1+n);
sort(b+1,b+1+n);
m=unique(b+1,b+1+n)-b-1;
for(int i=1;i<=n;i++) rt[i]=insert(rt[i-1],1,m,lower_bound(b+1,b+1+m,a[i].a)-b);
solve(1,n,1,n);
for(int i=1;i<=n;i++) printf("%lld\n",res[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5956kb
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...