P4231

題目:
https://www.luogu.com.cn/problem/P4231

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define MAXN 10000005

ll arr[MAXN];
ll l, r, s, e, d;
int n, m; // n columns, m attacks

void build(){
arr[l] += s;
arr[l+1] += d-s;
arr[r+1] -= d+e;
arr[r+2] += e;
}

void calculate(){
for(int i=1; i<=n; ++i){
arr[i] += arr[i-1];
}
for(int i=1; i<=n; ++i){
arr[i] += arr[i-1];
}
}

int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
while(cin >> n >> m){
for(int i=1; i<=m; ++i){
cin >> l >> r >> s >> e;
d = (e-s) / (r-l);
build();
}
calculate();
ll maxi = 0, Xor = 0;
for(int i=1; i<=n; ++i){
maxi = max(arr[i], maxi);
Xor ^= arr[i];
}
cout << Xor << ' ' << maxi << '\n';
}
return 0;
}