ABC348G Max(Sum-Max)
将
考虑
现在考虑所有的
发现
发现
点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<unordered_map>
#include<vector>
#include<queue>
#include<bitset>
#include<set>
#include<ctime>
#include<random>
#define x1 xx1
#define y1 yy1
#define IOS ios::sync_with_stdio(false)
#define ITIE cin.tie(0);
#define OTIE cout.tie(0);
#define PY puts("Yes")
#define PN puts("No")
#define PW puts("-1")
#define P__ puts("")
#define PU puts("--------------------")
#define popc __builtin_popcount
#define mp make_pair
#define fi first
#define se second
#define gc getchar
#define pc putchar
#define pb emplace_back
#define rep(a,b,c) for(int a=(b);a<=(c);++a)
#define per(a,b,c) for(int a=(b);a>=(c);--a)
#define reprange(a,b,c,d) for(int a=(b);a<=(c);a+=(d))
#define perrange(a,b,c,d) for(int a=(b);a>=(c);a-=(d))
#define graph(i,j,k,l) for(int i=k[j];i;i=l[i].nxt)
#define lowbit(x) (x&-x)
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define mem(x,y) memset(x,y,sizeof x)
//#define double long double
#define int long long
//#define int __int128
using namespace std;
typedef long long i64;
using pii=pair<int,int>;
bool greating(int x,int y){return x>y;}
bool greatingll(long long x,long long y){return x>y;}
inline int rd(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}return x*f;
}
inline void write(int x,char ch='\0'){
if(x<0){x=-x;putchar('-');}
int y=0;char z[40];
while(x||!y){z[y++]=x%10+48;x/=10;}
while(y--)putchar(z[y]);if(ch!='\0')putchar(ch);
}
bool Mbg;
const int maxn=2e5+5,maxm=4e5+5,inf=0x3f3f3f3f;
const long long llinf=0x3f3f3f3f3f3f3f3f;
int n,m;
int a[maxn],b[maxn],c[maxn];
struct ___{int x,y;bool operator<(const ___ &p)const{return y<p.y;}}_[maxn];
namespace segtree{
struct node{
int ls,rs,val,sum;
}d[maxn<<6];
int rt[maxn],cnt;
#define mid ((l+r)>>1)
void bd(int l,int r,int &p){
p=++cnt;if(l==r)return;
bd(l,mid,d[p].ls),bd(mid+1,r,d[p].rs);
}
void ins(int x,int v,int l,int r,int &p,int tp){
p=++cnt,d[p]=d[tp],d[p].val++,d[p].sum+=v;
if(l==r)return;
if(x<=mid)ins(x,v,l,mid,d[p].ls,d[tp].ls);
else ins(x,v,mid+1,r,d[p].rs,d[tp].rs);
}
int qry(int k,int l,int r,int p){
if(l==r)return k*c[l];
if(k<=d[d[p].rs].val)return qry(k,mid+1,r,d[p].rs);
return qry(k-d[d[p].rs].val,l,mid,d[p].ls)+d[d[p].rs].sum;
}
#undef mid
}using namespace segtree;
int ans[maxn];
void solve(int l,int r,int L,int R){
if(l>r)return;
int mid=l+r>>1,p=0;
rep(i,max(L,mid),R){
int res=qry(mid,1,m,rt[i])-b[i];
if(res>ans[mid])ans[mid]=res,p=i;
}
solve(l,mid-1,L,p),solve(mid+1,r,p,R);
}
void solve_the_problem(){
n=rd();rep(i,1,n)_[i].x=rd(),_[i].y=rd();
sort(_+1,_+n+1);rep(i,1,n)a[i]=c[i]=_[i].x,b[i]=_[i].y;
sort(c+1,c+n+1);m=unique(c+1,c+n+1)-(c+1);
bd(1,m,rt[0]);
rep(i,1,n)ins(lower_bound(c+1,c+m+1,a[i])-c,a[i],1,m,rt[i],rt[i-1]);
mem(ans,0xc0);
solve(1,n,1,n);
rep(i,1,n)write(ans[i],10);
}
bool Med;
signed main(){
// freopen(".in","r",stdin);freopen(".out","w",stdout);
// fprintf(stderr,"%.3lfMB\n",(&Mbg-&Med)/1048576.0);
int _=1;while(_--)solve_the_problem();
}
/*
*/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现