#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define z return 0;
using namespace std;
const int N = 1e5 + 5;
ll inf = 1e11 + 1; //
int main(){
ios::sync_with_stdio(0), cin.tie(0);
int n, k;
cin >> n >> k;
int a[k], b[k], c[k], d[k];
for (int i = 0; i < k; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
ll ans = inf;
for (int l = 1; l < n; l++){
if (n % l) continue;
int l2 = n / l;
ll tmp = 1ll * l * l * (1ll * l2 * l2 / 2), tmp2 = tmp + 1ll * l * l * (l2 % 2);
swap(tmp, tmp2);
int d0[n + 2]{}, d1[n + 2]{}, pre[n + 1]{};
for (int i = 1; i <= n; i++){
pre[i] = pre[i - 1] + (i % (l * 2) > 0 and i % (l * 2) <= l);
}
for (int i = 0; i < k; i++){
int p = pre[c[i]] - pre[a[i] - 1], p2 = c[i] - a[i] + 1 - p;
d0[b[i]] += p;
d0[d[i] + 1] -= p;
d1[b[i]] += p2;
d1[d[i] + 1] -= p2;
}
ll pre0 = 0, pre1 = 0;
for (int i = 1; i <= n; i++){
pre0 += d0[i], pre1 += d1[i];
if (i % (l * 2) > 0 and i % (l * 2) <= l){
tmp += pre1 - pre0;
tmp2 += pre0 - pre1;
}
else{
tmp2 += pre1 - pre0;
tmp += pre0 - pre1;
}
}
ans = min({ans, tmp, tmp2});
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
2028 KB |
Output is correct |
2 |
Correct |
7 ms |
1132 KB |
Output is correct |
3 |
Correct |
18 ms |
2796 KB |
Output is correct |
4 |
Correct |
17 ms |
1900 KB |
Output is correct |
5 |
Correct |
23 ms |
3180 KB |
Output is correct |
6 |
Correct |
15 ms |
2284 KB |
Output is correct |
7 |
Correct |
4 ms |
876 KB |
Output is correct |
8 |
Correct |
15 ms |
2284 KB |
Output is correct |
9 |
Correct |
39 ms |
4224 KB |
Output is correct |
10 |
Correct |
26 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
9 ms |
876 KB |
Output is correct |
17 |
Correct |
28 ms |
1644 KB |
Output is correct |
18 |
Correct |
35 ms |
1900 KB |
Output is correct |
19 |
Correct |
46 ms |
1772 KB |
Output is correct |
20 |
Correct |
43 ms |
1900 KB |
Output is correct |
21 |
Correct |
26 ms |
1644 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
15 ms |
1004 KB |
Output is correct |
24 |
Correct |
30 ms |
1772 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
18 ms |
1260 KB |
Output is correct |
27 |
Correct |
23 ms |
1388 KB |
Output is correct |
28 |
Correct |
31 ms |
1772 KB |
Output is correct |
29 |
Correct |
11 ms |
876 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
2028 KB |
Output is correct |
2 |
Correct |
7 ms |
1132 KB |
Output is correct |
3 |
Correct |
18 ms |
2796 KB |
Output is correct |
4 |
Correct |
17 ms |
1900 KB |
Output is correct |
5 |
Correct |
23 ms |
3180 KB |
Output is correct |
6 |
Correct |
15 ms |
2284 KB |
Output is correct |
7 |
Correct |
4 ms |
876 KB |
Output is correct |
8 |
Correct |
15 ms |
2284 KB |
Output is correct |
9 |
Correct |
39 ms |
4224 KB |
Output is correct |
10 |
Correct |
26 ms |
2668 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
9 ms |
876 KB |
Output is correct |
27 |
Correct |
28 ms |
1644 KB |
Output is correct |
28 |
Correct |
35 ms |
1900 KB |
Output is correct |
29 |
Correct |
46 ms |
1772 KB |
Output is correct |
30 |
Correct |
43 ms |
1900 KB |
Output is correct |
31 |
Correct |
26 ms |
1644 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
15 ms |
1004 KB |
Output is correct |
34 |
Correct |
30 ms |
1772 KB |
Output is correct |
35 |
Correct |
3 ms |
492 KB |
Output is correct |
36 |
Correct |
18 ms |
1260 KB |
Output is correct |
37 |
Correct |
23 ms |
1388 KB |
Output is correct |
38 |
Correct |
31 ms |
1772 KB |
Output is correct |
39 |
Correct |
11 ms |
876 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
85 ms |
4844 KB |
Output is correct |
42 |
Correct |
49 ms |
5228 KB |
Output is correct |
43 |
Correct |
55 ms |
4844 KB |
Output is correct |
44 |
Correct |
42 ms |
5236 KB |
Output is correct |
45 |
Correct |
51 ms |
5356 KB |
Output is correct |
46 |
Correct |
85 ms |
5228 KB |
Output is correct |
47 |
Correct |
36 ms |
4844 KB |
Output is correct |
48 |
Correct |
48 ms |
4972 KB |
Output is correct |
49 |
Correct |
39 ms |
4844 KB |
Output is correct |
50 |
Correct |
267 ms |
4844 KB |
Output is correct |
51 |
Correct |
276 ms |
5228 KB |
Output is correct |
52 |
Correct |
268 ms |
4864 KB |
Output is correct |
53 |
Correct |
273 ms |
5100 KB |
Output is correct |
54 |
Correct |
263 ms |
4844 KB |
Output is correct |
55 |
Correct |
278 ms |
5356 KB |
Output is correct |
56 |
Correct |
263 ms |
4844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
26 ms |
2028 KB |
Output is correct |
10 |
Correct |
7 ms |
1132 KB |
Output is correct |
11 |
Correct |
18 ms |
2796 KB |
Output is correct |
12 |
Correct |
17 ms |
1900 KB |
Output is correct |
13 |
Correct |
23 ms |
3180 KB |
Output is correct |
14 |
Correct |
15 ms |
2284 KB |
Output is correct |
15 |
Correct |
4 ms |
876 KB |
Output is correct |
16 |
Correct |
15 ms |
2284 KB |
Output is correct |
17 |
Correct |
39 ms |
4224 KB |
Output is correct |
18 |
Correct |
26 ms |
2668 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
9 ms |
876 KB |
Output is correct |
35 |
Correct |
28 ms |
1644 KB |
Output is correct |
36 |
Correct |
35 ms |
1900 KB |
Output is correct |
37 |
Correct |
46 ms |
1772 KB |
Output is correct |
38 |
Correct |
43 ms |
1900 KB |
Output is correct |
39 |
Correct |
26 ms |
1644 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
15 ms |
1004 KB |
Output is correct |
42 |
Correct |
30 ms |
1772 KB |
Output is correct |
43 |
Correct |
3 ms |
492 KB |
Output is correct |
44 |
Correct |
18 ms |
1260 KB |
Output is correct |
45 |
Correct |
23 ms |
1388 KB |
Output is correct |
46 |
Correct |
31 ms |
1772 KB |
Output is correct |
47 |
Correct |
11 ms |
876 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
85 ms |
4844 KB |
Output is correct |
50 |
Correct |
49 ms |
5228 KB |
Output is correct |
51 |
Correct |
55 ms |
4844 KB |
Output is correct |
52 |
Correct |
42 ms |
5236 KB |
Output is correct |
53 |
Correct |
51 ms |
5356 KB |
Output is correct |
54 |
Correct |
85 ms |
5228 KB |
Output is correct |
55 |
Correct |
36 ms |
4844 KB |
Output is correct |
56 |
Correct |
48 ms |
4972 KB |
Output is correct |
57 |
Correct |
39 ms |
4844 KB |
Output is correct |
58 |
Correct |
267 ms |
4844 KB |
Output is correct |
59 |
Correct |
276 ms |
5228 KB |
Output is correct |
60 |
Correct |
268 ms |
4864 KB |
Output is correct |
61 |
Correct |
273 ms |
5100 KB |
Output is correct |
62 |
Correct |
263 ms |
4844 KB |
Output is correct |
63 |
Correct |
278 ms |
5356 KB |
Output is correct |
64 |
Correct |
263 ms |
4844 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
1 ms |
324 KB |
Output is correct |
67 |
Correct |
277 ms |
4972 KB |
Output is correct |
68 |
Correct |
269 ms |
4972 KB |
Output is correct |
69 |
Correct |
255 ms |
4588 KB |
Output is correct |
70 |
Correct |
259 ms |
4960 KB |
Output is correct |
71 |
Correct |
263 ms |
4972 KB |
Output is correct |
72 |
Correct |
261 ms |
4844 KB |
Output is correct |
73 |
Correct |
257 ms |
4716 KB |
Output is correct |
74 |
Correct |
272 ms |
5100 KB |
Output is correct |
75 |
Correct |
258 ms |
4856 KB |
Output is correct |
76 |
Correct |
267 ms |
4972 KB |
Output is correct |
77 |
Correct |
70 ms |
5356 KB |
Output is correct |
78 |
Correct |
43 ms |
5248 KB |
Output is correct |
79 |
Correct |
57 ms |
4972 KB |
Output is correct |
80 |
Correct |
57 ms |
4972 KB |
Output is correct |
81 |
Correct |
54 ms |
4844 KB |
Output is correct |
82 |
Correct |
52 ms |
5276 KB |
Output is correct |
83 |
Correct |
53 ms |
4972 KB |
Output is correct |
84 |
Correct |
188 ms |
5356 KB |
Output is correct |
85 |
Correct |
283 ms |
5228 KB |
Output is correct |
86 |
Correct |
157 ms |
1260 KB |
Output is correct |
87 |
Correct |
156 ms |
1260 KB |
Output is correct |
88 |
Correct |
281 ms |
5356 KB |
Output is correct |
89 |
Correct |
179 ms |
2104 KB |
Output is correct |
90 |
Correct |
158 ms |
1260 KB |
Output is correct |