QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#363508 | #7523. Partially Free Meal | Delay_for_five_minutes# | WA | 305ms | 64368kb | C++20 | 1.5kb | 2024-03-23 23:34:13 | 2024-03-23 23:34:14 |
Judging History
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);
if(pos<=c[i])ans[j]=qry(rt,1,M,pos)-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: 0ms
memory: 11940kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 305ms
memory: 64368kb
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:
999995620 999998148 999997901 1000005199 1000013332 1000024844 1000033551 1000049015 1000063886 1000079648 1000099593 1000126049 1000148759 1000180073 1000203638 1000242272 1000285401 1000325516 1000370844 1000417633 1000466014 1000517791 1000566281 1000626741 1000683559 1000750547 1000819485 100088...
result:
wrong answer 1st lines differ - expected: '1318594', found: '999995620'