题目链接:https://www.luogu.org/problemnew/show/P4231
诶 我很迷啊..这跟树状数组有什么关系啊...拿二阶差分数组过了..?
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define ri register
using namespace std;
const int maxn = 11000001;
ll diff[maxn], ddiff[maxn], bit[maxn], n, m, ans, maxx = -1;
inline int read()
{
int k=0;
char c;
c=getchar();
while(!isdigit(c))c=getchar();
while(isdigit(c)){k=(k<<3)+(k<<1)+c-'0';c=getchar();}
return k;
}
int main()
{
//scanf("%lld%lld",&n,&m);
n = read(); m = read();
for(ri int i = 1; i <= m; i++)
{
ll l, r, s, e, d;
//scanf("%lld%lld%lld%lld",&l,&r,&s,&e);
l = read(); r = read(); s = read(); e = read();
d = (e-s)/(r-l);
ddiff[l] += s;
ddiff[l+1] = ddiff[l+1] + d - s;
ddiff[r+1] = ddiff[r+1] - d - e;
ddiff[r+2] += e;
}
diff[1] = ddiff[1];
for(ri int i = 2; i <= n; i++)
{
diff[i] = ddiff[i] + diff[i-1];
}
bit[1] = diff[1];
ans = bit[1];
for(ri int i = 2; i <= n; i++)
{
bit[i] = diff[i] + bit[i-1];
ans = ans^bit[i];
if(bit[i] > maxx)
maxx = bit[i];
}
printf("%lld %lld",ans,maxx);
return 0;
}