QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#584499 | #7523. Partially Free Meal | xlwang | TL | 1ms | 5964kb | C++14 | 2.5kb | 2024-09-23 14:52:57 | 2024-09-23 14:52:58 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
// int t=read();
// while(t--) work();
//}
const int Maxn=2e5+10,Maxm=Maxn*30,V=1e9;
int ls[Maxm],rs[Maxm],num[Maxm];
ll s[Maxm];
int nod;
inline int newnode(int x){++nod;ls[nod]=ls[x];rs[nod]=rs[x];num[nod]=num[x];s[nod]=s[x];return nod;}
inline void update(int ql,int l,int r,int &x,int y){
x=newnode(y);++num[x];s[x]+=ql;
if(l==r) return;
int mid;mid=(l+r)>>1;
if(ql<=mid) update(ql,l,mid,ls[x],ls[y]);
else update(ql,mid+1,r,rs[x],rs[y]);
}
inline ll query(int l,int r,int x,int k){
if(l==r) return 1ll*l*k;
int mid;mid=(l+r)>>1;
if(num[ls[x]]<k) return query(mid+1,r,rs[x],k-num[ls[x]])+s[ls[x]];
return query(l,mid,ls[x],k);
}
struct node{int a,b;}e[Maxn];
inline bool cmp(node a,node b){return a.b<b.b;}
int n;
ll f[Maxn];
int rt[Maxn];
inline void init(){
n=read();
fr(i,1,n) e[i].a=read(),e[i].b=read();
sort(e+1,e+n+1,cmp);
fr(i,1,n) update(e[i].a,1,V,rt[i],rt[i-1]);
}
inline void solve(int l,int r,int ql,int qr){
if(l>r || ql>qr) return;
int mid;mid=(l+r)>>1;
ll minn=1e17;
int id=-1;
fr(i,max(ql,mid),qr){
ll now=query(1,V,rt[i],mid)+e[i].b;
// cout<<mid<<' '<<i<<' '<<now<<endl;
if(now<minn) minn=now,id=i;
}
f[mid]=minn;
solve(l,mid-1,ql,id);solve(mid+1,r,id,qr);
}
inline void work(){
solve(1,n,1,n);
fr(i,1,n) printf("%lld\n",f[i]);
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();work();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5964kb
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...