CF1053C
n个物品,每个物品有两个值w,v。
一个物品i到位置t的代价是w[i]*|v[i]-v[t]|
要求支持更改一个数的w。
求出把一个区间的物品全部移到一起的最小代价。
我们做这题首先要想到货仓选址这个题
选的是中位数 不过这题要维护带权中位数
带权中位数就是要维护 一个 pos 使得左边pos相加大于右边pos
你可以假设pos 是最优答案 如果pos向右移动一个单位 对于答案的讨论来确定
因为移动后相对位置不变 所以相当于把每个数选一个数向他逼近
那么就是找到这个带权中位数 然后统计
a[pos] - a[i] - (pos-i) 这是左边的
(a[i]-a[pos] - (i-pos)) 这是右边的
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)
#define MOD 1000000007
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){
int ans=1;while(b){
if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;