bzoj1062: [NOI2008]糖果雨

又是一道神题

题解传送门:http://blog.sina.com.cn/s/blog_86942b1401015yln.html

代码完全抄袭某神,请无视掉

const int N = 1010, M = 1000010;
struct Dat {
	int t, p;
} Dat[M];
int C1[N * 3][N << 2], C2[N * 3][N << 2];
int n, m, Len, T;

inline void Input() {
	scanf("%d%d", &T, &Len), n = Len << 1, m = n << 1;
}

inline int lowbit(int x) { return x & -x; }	
inline void Add(int C1[][N << 2], int x0, int y0, int d) {
	for(int i = x0 + 1; i < Len * 3 + 2; i += lowbit(i))
		for(int j = y0 + 1; j < (Len << 2) + 1; j += lowbit(j)) C1[i][j] += d;
}
inline void Add_a(int x, int y, int d) { Add(C1, x, x + y, d); }
inline void Add_b(int x, int y, int d) { Add(C2, x - Len, y - x + m, d); }

inline int Cal(int C1[][N << 2], int x0, int y0) {
	int Ans = 0;
	for(int i = x0 + 1; i; i -= lowbit(i))
		for(int j = y0 + 1; j; j -= lowbit(j)) Ans += C1[i][j];
	return Ans;
}
inline int Cal1(int x0, int y0, int x1, int y1) {
	return Cal(C1, x1, x1 + y1) - Cal(C1, x0 - 1, x1 + y1) - 
		Cal(C1, x1, x0 + y0 - 1) + Cal(C1, x0 - 1, x0 + y0 - 1);
}
inline int Cal2(int x0, int y0, int x1, int y1) {
	return Cal(C2, x1 - Len, y1 - x1 + m) - Cal(C2, x0 - Len - 1, y1 - x1 + m)
		- Cal(C2, x1 - Len, y0 - x0 + m - 1) + Cal(C2, x0 - Len - 1, y0 - x0 + m - 1);
}

inline void Change(int c, int d) {
	int t = Dat[c].t, p = Dat[c].p;
	Add_a(t, p, d);
	if(t <= Len) Add_a(t + n, p, d);
	Add_b(t + n, p, d);
	if(t >= Len) Add_b(t, p, d);
}
inline int Ask(int t, int L, int R) {
	int ans = Cal1(t, L, t + R, Len), d = Len == R;
	if (!R) return ans;
	return ans += Cal2(t + n - R + d, L - R + d, t + n - 1, Len + R - 1);
}
inline void Solve() {
	while(T--) {
		int K, t, c, L, R, d;
		scanf("%d%d", &K, &t), t %= n;
		if(K == 1) {
			scanf("%d%d%d%d", &c, &L, &R, &d);
			Dat[c].t = (t - d * L + n) % n, Dat[c].p = R - L, Change(c, 1);
		} else if(K == 2) scanf("%d%d", &L, &R), printf("%d\n", Ask(t, L, R));
		else scanf("%d", &c), Change(c, -1);
	}
}

int main() {
	#ifndef ONLINE_JUDGE
	SETIO("1062");
	#endif
	Input();
	Solve();
	return 0;
}

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页