分块求助
  • 板块学术版
  • 楼主cmll02
  • 当前回复4
  • 已保存回复4
  • 发布时间2020/6/13 11:46
  • 上次更新2023/11/7 00:45:42
查看原帖
分块求助
171487
cmll02楼主2020/6/13 11:46

题面: 点我

代码:

#include <string.h>
#include <stdio.h>
typedef long long LL;
inline long long read()
{
	long long num = 0; int f = 1; char c = getchar();
	while (c < 48 || c>57){ if (c == '-')f = -1; c = getchar(); }
	while (c >= 48 && c <= 57)num = (num << 3) + (num << 1) + (c ^ 48), c = getchar();
	return num*f;
}
LL a[50005], BLOCK[230], brl[50005], sum[230];
const int BLOCKSIZE = 224;
//224 one block
#include <algorithm>
inline LL min(LL a, LL b)
{
	return a < b ? a : b;
}
signed main()
{
	LL n = read();
	for (LL i = 1; i <= n; i++)a[i] = read(), brl[i] = (i - 1) / BLOCKSIZE + 1, sum[brl[i]] += a[i];
	for (LL ii = 0; ii < n; ii++)
	{
		LL opt = read(), l = read(), r = read(), c = read();
		if (opt==2)
		{
			LL LB = brl[l], RB = brl[r];
			LL ans = 0;
			for (LL i = l; i <= min(BLOCKSIZE*LB, r); i++)ans = (ans + a[i] + BLOCK[LB]) % (c + 1);
			if (LB != RB)
			{
				for (LL i = LB + 1; i < RB; i++)ans = (ans + BLOCK[i] + sum[i]) % (c + 1);
				for (LL i = (RB - 1)*BLOCKSIZE + 1; i <= r; i++)ans += a[i]+BLOCK[RB], ans %= (c + 1);
			}
			printf("%lld\n", ans % (c+1));
		}
		else
		{
			LL LB = brl[l], RB = brl[r];
			for (LL i = l; i <= min(BLOCKSIZE*LB, r); i++)a[i] += c, sum[brl[i]] += c;
			if (LB != RB)
			{
				for (LL i = LB + 1; i < RB; i++)BLOCK[i] += c;
				for (LL i = (RB - 1)*BLOCKSIZE + 1; i <= r; i++)a[i] += c, sum[brl[i]] += c;
			}
		}
	}///w///hile (1);
	getchar();
	return 0;
}

听取WA声一片

2020/6/13 11:46
加载中...