QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269533 | #7523. Partially Free Meal | yspm | WA | 426ms | 135284kb | C++14 | 2.1kb | 2023-11-29 18:39:30 | 2023-11-29 18:39:31 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
template<typename T>inline void ckmax(T &x,T y){x=x<y?y:x;}
template<typename T>inline void ckmin(T &x,T y){x=x>y?y:x;}
template<typename T=int>inline T read(){
T res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
template<typename T>inline void print(T x,bool fl=1){
if(x<0) putchar('-'),x=-x;
if(x>=10) print(x/10,0);
putchar(x%10+'0');
if(fl) putchar('\n');
}
const int N=200010,M=N*30;
int tot,f[N],ls[M],rs[M],siz[M],sum[M],rt[N],b[N],bcnt,n;
pair<int,int> v[N];
inline void insert(int &p,int pre,int l,int r,int pos){
p=++tot; ls[p]=ls[pre],rs[p]=rs[pre];
sum[p]=b[pos]+sum[pre],siz[p]=1+siz[pre];
if(l==r){
siz[p]++; sum[p]+=b[pos];
return ;
}
int mid=(l+r)>>1;
if(pos<=mid) insert(ls[p],ls[pre],l,mid,pos);
else insert(rs[p],rs[pre],mid+1,r,pos);
return ;
}
inline int query(int p,int l,int r,int K){
if(siz[p]<K) return 3e18;
if(siz[p]==K) return sum[p];
if(l==r) return b[l]*K;
int mid=(l+r)>>1;
if(siz[ls[p]]>=K) return query(ls[p],l,mid,K);
return query(rs[p],mid+1,r,K-siz[ls[p]])+sum[ls[p]];
}
inline int calc(int x,int pos){
return v[pos].second+b[v[pos].first]+query(rt[pos-1],1,bcnt,x-1);
}
inline void solve(int pl,int pr,int l,int r){
ckmax(pl,l);
assert(pr>=l);
if(r<l) return ;
if(pl==pr){
for(int i=l;i<=r;++i) f[i]=pl;
return ;
}
int mid=(l+r)>>1,tar=pl,vv=calc(mid,pl);
for(int i=max(pl+1,mid);i<=pr;++i) if(calc(mid,tar)>calc(mid,i)) tar=i;
f[mid]=tar;
solve(pl,tar,l,mid-1);
solve(tar,pr,mid+1,r);
return ;
}
signed main(){
n=read();
for(int i=1;i<=n;++i){
v[i].first=read(),v[i].second=read();
b[++bcnt]=v[i].first;
}
sort(b+1,b+bcnt+1);
bcnt=unique(b+1,b+bcnt+1)-b-1;
for(int i=1;i<=n;++i) v[i].first=lower_bound(b+1,b+bcnt+1,v[i].first)-b;
sort(v+1,v+n+1,[&](pair<int,int> x,pair<int,int>y){return x.second<y.second;});
for(int i=1;i<=n;++i) insert(rt[i],rt[i-1],1,bcnt,v[i].first);
solve(1,n,1,n);
for(int i=1;i<=n;++i) print(calc(i,f[i]));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7548kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 426ms
memory: 135284kb
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 3208018 5570526 7340845 9223347 11149865 12332210 13476823 14788280 16172895 17768627 19336633 20693779 22005236 23389851 25073157 26760338 28509336 30294967 32093959 33976461 35893858 37754030 39588384 41470886 43388283 45309771 47309654 48837539 50417767 52079411 53762717 55190044 56577630...
result:
wrong answer 25827th lines differ - expected: '894878200462', found: '894878197034'