P4231 三步必杀(二阶差分)

  • Post author:
  • Post category:其他


本题采用二阶差分

下面是二阶差分的推导

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e7+10;
long long c[N];

int main()
{
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 1;i <= m;i++)
	{
		int l, r, s, e;
		cin >> l >> r >> s >> e;
		int d = (e - s) / (r - l);
		c[l] += s;
		c[l + 1] += d-s;
		c[r + 1] -= e + d;
		c[r + 2] += e;
	}
	for (int i = 1;i <= n;i++)
		c[i] += c[i - 1];
	for (int i = 1;i <= n;i++)
		c[i] += c[i - 1];
	long long res = c[1];
	long long MAX = c[1];
	for (int i = 2;i <= n;i++)
	{
		res ^= c[i];
		if (MAX < c[i])
			MAX = c[i];
	}
	cout << res << ' ' << MAX;
}



版权声明:本文为qq12323qweeqwe原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。