80 分代码求调,玄关
查看原帖
80 分代码求调,玄关
712506
Lucky_Cloud楼主2024/3/7 20:26
#include <bits/stdc++.h>
#define N 2000010
#define M 2000000
#define ll long long
using namespace std;

inline ll read() {
	ll res = 0, f = 1; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
	while (c >= '0' && c <= '9') { res = (res << 1) + (res << 3) + (c ^ 48); c = getchar(); }
	return f == -1 ? -res : res;
}
int n, m;
ll ans[11000][5];
struct OPT {
	int op;
	int x, y;
	ll a = 0 ;
	int i, j;
	int t;
} a[N >> 2], tmp[N >> 2];

struct BIT {
	ll sum[N];
	inline void add(int x, int v) { x++; for (; x <= M; x += x & -x) sum[x] += v; }
	inline ll ask(int x) { x++; ll res = 0; for (; x; x -= x & -x) res += sum[x]; return res; }
} T;

inline void cdq(int l, int r) {
	int mid = (l + r) >> 1;
	if (l == r) return ;
	cdq(l, mid), cdq(mid + 1, r);
	int i = mid + 1, j = l, len = l - 1;
	while (i <= r && j <= mid) {
		if (a[j].x <= a[i].x) {
			tmp[++len] = a[j];
			if (!a[j].op) T.add(a[j].y, a[j].a);
			++j;
		}
		else {
			tmp[++len] = a[i];
			if (a[i].op) ans[a[i].i][a[i].j] += T.ask(a[i].y);
			++i;
		}
	}
	while (i <= r) {
		tmp[++len] = a[i];
		if (a[i].op) ans[a[i].i][a[i].j] += T.ask(a[i].y);
		++i; 
	}
	while (j <= mid) {
		if (!a[j].op) T.add(a[j].y, a[j].a);
		tmp[++len] = a[j++];
	}
	for (int i = l; i <= mid; ++i) 
		if (!a[i].op) T.add(a[i].y, -a[i].a);
	for (int i = l; i <= r; ++i) a[i] = tmp[i];
//	cout << (len == r) << '\n';
}

int main() {
	n = read(); n = read();
	int op = read(), x, y, aa, xx, yy, cnt = 0;
	while (op != 3) {
		x = read(), y = read();
		if (op == 1) {
			aa = read();
			a[++m] = { op - 1, x, y, aa, 0, 0, m };
		}
		else {
			a[++m] = { op - 1, x - 1, y - 1, 0, ++cnt, 1, m };
			xx = read(), yy = read();
			a[++m] = { op - 1, x - 1, yy, 0, cnt, 2, m };
			a[++m] = { op - 1, xx, yy, 0, cnt, 3, m };
			a[++m] = { op - 1, xx, y - 1, 0, cnt, 4, m };
		}
		op = read();
	}
	cdq(1, m);
	sort(a + 1, a + 1 + m, [&](const OPT a, const OPT b) { return a.t < b.t; });
	for (int i = 1; i <= cnt; ++i) {
		printf("%lld\n", ans[i][3] - ans[i][2] - ans[i][4] + ans[i][1]);
	}
	return 0;
}
2024/3/7 20:26
加载中...