using namespace std;
int prices[100000];
int n;
int bit[100000 + 1];
vectorroad[1001];
//分解
void add(int idx, int delta)
{
for (; idx < n; idx += idx & -idx) {
bit[idx] += delta;
}
}
//合并
int sum(int idx)
{
register int ret = 0;
for (; idx != 0; idx -= idx & -idx) {
ret += bit[idx];
}
return ret;
}
void init(int N, int M, int mType[], int mTime[])
{
for (int i = 0; i < M; i++)
road[i].clear();
n = N;
for (register int i = 1; i < N; i++)
bit[i] = 0;
for (register int i = 0; i < N - 1; i++) {
prices[i] = mTime[i];
add(i + 1, mTime[i]);
road[mType[i]].push_back(i);
}
}
void destroy()
{
}
void update(int mID, int mNewTime)
{
add(mID + 1, mNewTime - prices[mID]);
prices[mID] = mNewTime;
}
int updateByType(int mTypeID, int mRatio256)
{
register int ret = 0, newTime;
for (auto i = road[mTypeID].begin(); i != road[mTypeID].end(); i++)
{
newTime = (prices[i] mRatio256) >> 8;
update(*i, newTime);
ret += newTime;
}
return ret;
}
int calculate(int mA, int mB)
{
return mA > mB ? sum(mA) - sum(mB) : sum(mB) - sum(mA);
}
include
using namespace std; int prices[100000]; int n; int bit[100000 + 1]; vectorroad[1001];
//分解
void add(int idx, int delta)
{
for (; idx < n; idx += idx & -idx) {
bit[idx] += delta;
}
}
//合并
int sum(int idx)
{
register int ret = 0;
for (; idx != 0; idx -= idx & -idx) {
ret += bit[idx];
}
return ret;
}
void init(int N, int M, int mType[], int mTime[]) { for (int i = 0; i < M; i++) road[i].clear(); n = N; for (register int i = 1; i < N; i++) bit[i] = 0; for (register int i = 0; i < N - 1; i++) { prices[i] = mTime[i]; add(i + 1, mTime[i]); road[mType[i]].push_back(i); } } void destroy() { } void update(int mID, int mNewTime) { add(mID + 1, mNewTime - prices[mID]); prices[mID] = mNewTime; }
int updateByType(int mTypeID, int mRatio256) { register int ret = 0, newTime; for (auto i = road[mTypeID].begin(); i != road[mTypeID].end(); i++) { newTime = (prices[i] mRatio256) >> 8; update(*i, newTime); ret += newTime; } return ret; }
int calculate(int mA, int mB) { return mA > mB ? sum(mA) - sum(mB) : sum(mB) - sum(mA); }