BZOJ3179 [Coci2012]RASPORED

树状数组

题目传送门
学考爆炸飞天
%%%ZZP
YY一下就会发现最大肯定是按T从小到大做。因为每单位时间每个订单减少的贡献相同。
修改就是把T的位置改变一下,我们用两个树状数组来实现。

具体见代码:

#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200005
#define F inline
using namespace std;
typedef long long LL;
int n,m,L[N],T[N];
LL ans,s,t1[N],t2[N];
//t1维护T[i]所花费的时间,t2维护权值T[i]的个数
F char readc(){
    static char buf[100000],*l=buf,*r=buf;
    if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
    return l==r?EOF:*l++;
}
F int _read(){
    int x=0; char ch=readc();
    while (!isdigit(ch)) ch=readc();
    while (isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=readc();
    return x;
}
F void writec(LL x){
    if (x<0) putchar('-'),x=-x;
    if (x>9) writec(x/10); putchar(x%10+48);
}
F void _write(LL x){ writec(x),puts(""); }
#define lbt(x) ((x)&-(x))
F void mdfy(LL *t,int x,int y){ for (;x<=(N>>1);x+=lbt(x)) t[x]+=y; }
F LL srch(LL *t,int x){ for (s=0;x;x-=lbt(x)) s+=t[x]; return s; }
F void nsrt(int x){
    ans-=srch(t1,(N>>1)-x)*x,ans-=srch(t2,x)+x;
    mdfy(t1,(N>>1)-x,1),mdfy(t2,x+1,x);
}
F void dlt(int x){
    mdfy(t1,(N>>1)-x,-1),mdfy(t2,x+1,-x);
    ans+=srch(t1,(N>>1)-x)*x,ans+=srch(t2,x)+x;
}
int main(){
    n=_read(),m=_read();
    for (int i=1;i<=n;i++) ans+=(L[i]=_read()),nsrt(T[i]=_read());
    while (m--){
        _write(ans); int x=_read(),l=_read(),t=_read();
        ans-=L[x],ans+=(L[x]=l),dlt(T[x]),nsrt(T[x]=t);
    }
    return _write(ans),0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值