不过确实 O(nlogn) 有点悬,但是貌似有人可以过。当然也可以换 O(n) 前缀和
#include <bits/stdc++.h>
#define re register int
#define max(x, y) (x > y ? x : y)
using namespace std;
typedef long long LL;
const int N = 1e7 + 10;
int n, m;
LL a[N], c1[N], c2[N], res1, res2 = -1;
inline LL lowbit(LL x) { return x & -x; }
inline void add(LL *c, LL x, LL k)
{
while (x <= n)
{
c[x] += k;
x += lowbit(x);
}
}
inline LL query(LL *c, LL x)
{
LL res = 0;
while (x > 0)
{
res += c[x];
x -= lowbit(x);
}
return res;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
scanf("%d %d", &n, &m);
while (m --)
{
LL l, r, s, e;
scanf("%lld %lld %lld %lld", &l, &r, &s, &e);
LL delta = (e - s) / (r - l);
add(c2, l, s);
add(c2, l + 1, delta - s);
add(c2, r + 1, -(delta + e));
add(c2, r + 2, e);
}
for (re i = 1; i <= n; i ++) add(c1, i, query(c2, i));
for (re i = 1; i <= n; i ++)
{
a[i] = query(c1, i);
res1 = res1 ^ a[i];
res2 = max(res2, a[i]);
}
printf("%lld %lld\n", res1, res2);
return 0;
}