玄关求掉
  • 板块P4879 ycz的妹子
  • 楼主FChang
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/12/20 15:36
  • 上次更新2024/12/20 20:04:03
查看原帖
玄关求掉
744853
FChang楼主2024/12/20 15:36

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 5;
int n, m;
struct BIT {
#define lowbit(x) (x & -x)
	int d[N];
	inline void update (int x, int y) {
		for (int i = x; i <= 5e5; i += lowbit (i)) d[i] += y;
		return ;
	}
	inline int ask (int x) {
		int ans = 0;
		for (int i = x; i; i-= lowbit (i)) ans += d[i];
		return ans;
	}
	inline int query (int x, int y) {
		return ask (y) - ask (x - 1);
	} 
} T1, T2;
signed main () {
	ios::sync_with_stdio (false);
	cin.tie (nullptr), cout.tie (nullptr);
	cin >> n >> m;
	for (int i = 1, x; i <= n; ++ i) {
		cin >> x;
		T1.update (i, 1);
		T2.update (i, x);
	}
	char opt;
	int x, y;
	while (m --) {
		cin >> opt;
		if (opt == 'C') {
			cin >> x >> y;
			T2.update (x, -y);
		} else if (opt == 'I') {
			cin >> x >> y;
			int d = T2.query (x, x);
			T2.update (x, -d);
			T2.update (x, y);
			if (T1.query (x, x) == 0) T1.update (x, 1);
		} else if (opt == 'D') {
			cin >> x;
			int l = 1, r = 5e5, mid, p;
			while (l <= r) {
				mid = (l + r) >> 1;
				if (T1.query (1, mid) <= x) p = mid, l = mid + 1;
				else r = mid - 1;
			}
			T1.update (p, -1);
			int d = T2.query (p, p);
			T2.update (p, -d);
		} else {
			cout << T2.query (1, 5e5) << "\n";
		}
	}
	return 0;
}

20pts

2024/12/20 15:36
加载中...