梦熊 跳蚤市场

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10;
int n,m;
LL v[N],l[N],r[N];
struct BIT{
    LL sum[N];
    void add(int x,LL y){
        for( ;x<N;x+= x&-x){
        	sum[x]+=y;
        }
    }
    LL qur(int x){
        LL res=0;
        for( ;x;x-=x&-x){
			res+=sum[x];
		}
        return res;
    }
    LL qursuf(int x){
		return qur(N-1)-qur(x-1);
	}
}ds1,ds2;
bool check(int mid) {
    LL p = ds2.qursuf(mid + 1), q = ds1.qursuf(mid + 1) + r[0];
    return mid * q < p;
}
LL gcd(LL x, LL y) {
    if(y==0){
    	return x;
	}
    return gcd(y, x % y);
}
void calc(){
    int lt=0,rt=N-1,pos=0;
    for(;lt<=rt; ){
        int mid=(lt+rt)/2;
        if(check(mid)){
            pos=mid;
			lt=mid+1;
        }
        else{
            rt=mid-1;
        }
    }
    LL p=ds2.qursuf(pos + 1);
	LL q=ds1.qursuf(pos+1)+r[0];
    if(q==0){
        q=1;
    }
    LL d=gcd(p,q);
    printf("%lld/%lld\n",p/d,q/d);
}
int main() {
    freopen("market.in", "r", stdin);
    freopen("market.out", "w", stdout);
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++){
    	scanf("%lld",&v[i]);
    }
    for(int i=0;i<=n;i++){
    	scanf("%lld",&l[i]);
    }
    for(int i=0;i<=n;i++){
    	scanf("%lld",&r[i]);
    }
    for(int i=1;i<=n;i++){
        ds1.add(v[i],l[i]);
        ds2.add(v[i],v[i]*l[i]);
    }
    calc();
    for(int i=1;i<=m;i++){
        int op,x,y,z;
        scanf("%d%d%d", &op, &x, &y);
        if (op == 1) {
            scanf("%d", &z);
            if (x == 0) {
                l[x] = y, r[x] = z;
            } else {
                ds1.add(v[x], -l[x]);
                ds2.add(v[x], -v[x] * l[x]);
                l[x]=y;
				r[x]=z;
                ds1.add(v[x],l[x]);
                ds2.add(v[x],v[x]*l[x]);
            }
        }
		else{
            ds1.add(v[x],-l[x]);
            ds2.add(v[x],-v[x]*l[x]);
            v[x]=y;
            ds1.add(v[x],l[x]);
            ds2.add(v[x],v[x]*l[x]);
        }
        calc();
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值