#include <iostream>
#include <climits>
#include <tuple>
#include <vector>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MN 107171
using namespace std;
using ll = long long;
ll n, k;
tuple<int, int, int, int> R[MN];
ll P[MN], D[MN];
ll P2[MN], D2[MN];
static inline ll calc(ll a, ll b, ll l) {
if(P[a] == 0 && P[b] == 0)
return ((D[a] * D[b] + 1) >> 1) * l * l;
if(P[a]) {
ll nrseg;
if((D[a] & 1) == 0) {
if(P2[b] <= l) nrseg = D2[b] * l + P2[b];
else nrseg = (D2[b] + 1) * l;
} else {
if(P2[b] <= l) nrseg = D2[b] * l;
else nrseg = (D2[b] - 1) * l + P2[b];
}
return calc(a - P[a], b, l) + P[a] * nrseg;
}
return calc(b, a, l);
}
ll sol(ll l) {
for(int i = 1; i <= n; ++i) {
D[i] = D[i-1];
P[i] = P[i-1] + 1;
if(P[i] == l) ++D[i], P[i] = 0;
D2[i] = D2[i-1];
P2[i] = P2[i-1] + 1;
if(P2[i] == (l << 1)) ++D2[i], P2[i] = 0;
}
ll arie = ((n / l) * (n / l) + 1) / 2 * l * l, selec;
for(int i = 1; i <= k; ++i) {
auto &[a, b, c, d] = R[i];
selec = calc(c, d, l) + calc(a-1, b-1, l) - calc(c, b-1, l) - calc(a-1, d, l);
arie += (c - a + 1) * (d - b + 1) - 2 * selec;
}
return min(arie, 1ll * n * n - arie);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> k;
for(int i = 1, a, b, c, d; i <= k; ++i)
cin >> a >> b >> c >> d, R[i] = make_tuple(a, b, c, d);
ll re = LLONG_MAX;
for(int i = 1; i < n; ++i)
if(n % i == 0) re = min(re, sol(i));
cout << re << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3148 KB |
Output is correct |
2 |
Correct |
5 ms |
972 KB |
Output is correct |
3 |
Correct |
13 ms |
3532 KB |
Output is correct |
4 |
Correct |
13 ms |
1036 KB |
Output is correct |
5 |
Correct |
20 ms |
2900 KB |
Output is correct |
6 |
Correct |
11 ms |
2380 KB |
Output is correct |
7 |
Correct |
3 ms |
1100 KB |
Output is correct |
8 |
Correct |
11 ms |
2380 KB |
Output is correct |
9 |
Correct |
39 ms |
2628 KB |
Output is correct |
10 |
Correct |
25 ms |
2288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
13 ms |
696 KB |
Output is correct |
17 |
Correct |
20 ms |
1612 KB |
Output is correct |
18 |
Correct |
34 ms |
1808 KB |
Output is correct |
19 |
Correct |
135 ms |
1740 KB |
Output is correct |
20 |
Correct |
187 ms |
1884 KB |
Output is correct |
21 |
Correct |
19 ms |
1504 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
24 ms |
952 KB |
Output is correct |
24 |
Correct |
30 ms |
1740 KB |
Output is correct |
25 |
Correct |
6 ms |
460 KB |
Output is correct |
26 |
Correct |
20 ms |
1196 KB |
Output is correct |
27 |
Correct |
29 ms |
1356 KB |
Output is correct |
28 |
Correct |
32 ms |
1740 KB |
Output is correct |
29 |
Correct |
9 ms |
836 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3148 KB |
Output is correct |
2 |
Correct |
5 ms |
972 KB |
Output is correct |
3 |
Correct |
13 ms |
3532 KB |
Output is correct |
4 |
Correct |
13 ms |
1036 KB |
Output is correct |
5 |
Correct |
20 ms |
2900 KB |
Output is correct |
6 |
Correct |
11 ms |
2380 KB |
Output is correct |
7 |
Correct |
3 ms |
1100 KB |
Output is correct |
8 |
Correct |
11 ms |
2380 KB |
Output is correct |
9 |
Correct |
39 ms |
2628 KB |
Output is correct |
10 |
Correct |
25 ms |
2288 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
13 ms |
696 KB |
Output is correct |
27 |
Correct |
20 ms |
1612 KB |
Output is correct |
28 |
Correct |
34 ms |
1808 KB |
Output is correct |
29 |
Correct |
135 ms |
1740 KB |
Output is correct |
30 |
Correct |
187 ms |
1884 KB |
Output is correct |
31 |
Correct |
19 ms |
1504 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
24 ms |
952 KB |
Output is correct |
34 |
Correct |
30 ms |
1740 KB |
Output is correct |
35 |
Correct |
6 ms |
460 KB |
Output is correct |
36 |
Correct |
20 ms |
1196 KB |
Output is correct |
37 |
Correct |
29 ms |
1356 KB |
Output is correct |
38 |
Correct |
32 ms |
1740 KB |
Output is correct |
39 |
Correct |
9 ms |
836 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
146 ms |
4728 KB |
Output is correct |
42 |
Correct |
42 ms |
4804 KB |
Output is correct |
43 |
Correct |
88 ms |
4748 KB |
Output is correct |
44 |
Correct |
43 ms |
4824 KB |
Output is correct |
45 |
Correct |
34 ms |
4892 KB |
Output is correct |
46 |
Correct |
191 ms |
4800 KB |
Output is correct |
47 |
Correct |
27 ms |
4684 KB |
Output is correct |
48 |
Correct |
61 ms |
4812 KB |
Output is correct |
49 |
Correct |
37 ms |
4684 KB |
Output is correct |
50 |
Correct |
807 ms |
4336 KB |
Output is correct |
51 |
Correct |
837 ms |
6744 KB |
Output is correct |
52 |
Correct |
781 ms |
6476 KB |
Output is correct |
53 |
Correct |
851 ms |
6716 KB |
Output is correct |
54 |
Correct |
777 ms |
6436 KB |
Output is correct |
55 |
Correct |
875 ms |
6864 KB |
Output is correct |
56 |
Correct |
748 ms |
6320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
20 ms |
3148 KB |
Output is correct |
10 |
Correct |
5 ms |
972 KB |
Output is correct |
11 |
Correct |
13 ms |
3532 KB |
Output is correct |
12 |
Correct |
13 ms |
1036 KB |
Output is correct |
13 |
Correct |
20 ms |
2900 KB |
Output is correct |
14 |
Correct |
11 ms |
2380 KB |
Output is correct |
15 |
Correct |
3 ms |
1100 KB |
Output is correct |
16 |
Correct |
11 ms |
2380 KB |
Output is correct |
17 |
Correct |
39 ms |
2628 KB |
Output is correct |
18 |
Correct |
25 ms |
2288 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
13 ms |
696 KB |
Output is correct |
35 |
Correct |
20 ms |
1612 KB |
Output is correct |
36 |
Correct |
34 ms |
1808 KB |
Output is correct |
37 |
Correct |
135 ms |
1740 KB |
Output is correct |
38 |
Correct |
187 ms |
1884 KB |
Output is correct |
39 |
Correct |
19 ms |
1504 KB |
Output is correct |
40 |
Correct |
2 ms |
332 KB |
Output is correct |
41 |
Correct |
24 ms |
952 KB |
Output is correct |
42 |
Correct |
30 ms |
1740 KB |
Output is correct |
43 |
Correct |
6 ms |
460 KB |
Output is correct |
44 |
Correct |
20 ms |
1196 KB |
Output is correct |
45 |
Correct |
29 ms |
1356 KB |
Output is correct |
46 |
Correct |
32 ms |
1740 KB |
Output is correct |
47 |
Correct |
9 ms |
836 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
146 ms |
4728 KB |
Output is correct |
50 |
Correct |
42 ms |
4804 KB |
Output is correct |
51 |
Correct |
88 ms |
4748 KB |
Output is correct |
52 |
Correct |
43 ms |
4824 KB |
Output is correct |
53 |
Correct |
34 ms |
4892 KB |
Output is correct |
54 |
Correct |
191 ms |
4800 KB |
Output is correct |
55 |
Correct |
27 ms |
4684 KB |
Output is correct |
56 |
Correct |
61 ms |
4812 KB |
Output is correct |
57 |
Correct |
37 ms |
4684 KB |
Output is correct |
58 |
Correct |
807 ms |
4336 KB |
Output is correct |
59 |
Correct |
837 ms |
6744 KB |
Output is correct |
60 |
Correct |
781 ms |
6476 KB |
Output is correct |
61 |
Correct |
851 ms |
6716 KB |
Output is correct |
62 |
Correct |
777 ms |
6436 KB |
Output is correct |
63 |
Correct |
875 ms |
6864 KB |
Output is correct |
64 |
Correct |
748 ms |
6320 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
1 ms |
332 KB |
Output is correct |
67 |
Correct |
839 ms |
6616 KB |
Output is correct |
68 |
Correct |
813 ms |
6596 KB |
Output is correct |
69 |
Correct |
708 ms |
6144 KB |
Output is correct |
70 |
Correct |
711 ms |
6488 KB |
Output is correct |
71 |
Correct |
781 ms |
6468 KB |
Output is correct |
72 |
Correct |
706 ms |
6376 KB |
Output is correct |
73 |
Correct |
791 ms |
6284 KB |
Output is correct |
74 |
Correct |
828 ms |
6548 KB |
Output is correct |
75 |
Correct |
781 ms |
6412 KB |
Output is correct |
76 |
Correct |
810 ms |
6692 KB |
Output is correct |
77 |
Correct |
122 ms |
7352 KB |
Output is correct |
78 |
Correct |
44 ms |
6852 KB |
Output is correct |
79 |
Correct |
86 ms |
6736 KB |
Output is correct |
80 |
Correct |
87 ms |
6852 KB |
Output is correct |
81 |
Correct |
82 ms |
6724 KB |
Output is correct |
82 |
Correct |
68 ms |
7124 KB |
Output is correct |
83 |
Correct |
54 ms |
6804 KB |
Output is correct |
84 |
Correct |
527 ms |
7260 KB |
Output is correct |
85 |
Correct |
847 ms |
6780 KB |
Output is correct |
86 |
Correct |
31 ms |
2916 KB |
Output is correct |
87 |
Incorrect |
32 ms |
2920 KB |
Output isn't correct |
88 |
Halted |
0 ms |
0 KB |
- |