#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
vector<ll> divs(ll x)
{
vector<ll> ans;
for (ll y = 1; y*y <= x; ++y) {
if (x%y == 0) {
ans.push_back(y);
ans.push_back(x/y);
}
}
return ans;
}
pll get(ll l, ll r, ll len)
{
ll len2 = len*2;
ll l2 = l%len2? l-l%len2+len2: l;
ll r2 = r%len2? r-r%len2: r;
ll a0 = (r2-l2)/2;
ll a1 = (r2-l2)/2;
a0 += max(0ll, l2-l-len);
a1 += min(len, l2-l);
a0 += min(len, r-r2);
a1 += max(0ll, r-r2-len);
return {a0, a1};
}
const int N = 100'010;
ll l0[N], r0[N];
ll l1[N], r1[N];
int main()
{
cin.tie(0) -> sync_with_stdio(false);
ll n, k;
cin >> n >> k;
Loop (i,0,k) {
cin >> l0[i] >> l1[i];
cin >> r0[i] >> r1[i];
--l0[i]; --l1[i];
}
ll ans = n*n;
for (ll x : divs(n)) {
if (x == n)
continue;
ll sm0 = ((n/x) * (n/x) + 1)/2 * x * x;
ll sm1 = ((n/x) * (n/x))/2 * x * x;
Loop (i,0,k) {
auto [a0, a1] = get(l0[i], r0[i], x);
auto [b0, b1] = get(l1[i], r1[i], x);
ll bl0 = a0*b0 + a1*b1;
ll bl1 = a0*b1 + a1*b0;
sm0 -= bl0;
sm1 -= bl1;
sm0 += (r0[i] - l0[i]) * (r1[i] - l1[i]) - bl0;
sm1 += (r0[i] - l0[i]) * (r1[i] - l1[i]) - bl1;
}
ans = min(ans, sm0);
ans = min(ans, sm1);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
3672 KB |
Output is correct |
2 |
Correct |
6 ms |
1108 KB |
Output is correct |
3 |
Correct |
15 ms |
2528 KB |
Output is correct |
4 |
Correct |
15 ms |
2636 KB |
Output is correct |
5 |
Correct |
23 ms |
3276 KB |
Output is correct |
6 |
Correct |
13 ms |
2132 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
13 ms |
2120 KB |
Output is correct |
9 |
Correct |
35 ms |
5128 KB |
Output is correct |
10 |
Correct |
18 ms |
3112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
10 ms |
1620 KB |
Output is correct |
17 |
Correct |
26 ms |
4324 KB |
Output is correct |
18 |
Correct |
40 ms |
5012 KB |
Output is correct |
19 |
Correct |
77 ms |
4488 KB |
Output is correct |
20 |
Correct |
89 ms |
5008 KB |
Output is correct |
21 |
Correct |
23 ms |
4164 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
19 ms |
2388 KB |
Output is correct |
24 |
Correct |
32 ms |
4620 KB |
Output is correct |
25 |
Correct |
4 ms |
724 KB |
Output is correct |
26 |
Correct |
20 ms |
2892 KB |
Output is correct |
27 |
Correct |
25 ms |
3424 KB |
Output is correct |
28 |
Correct |
33 ms |
4852 KB |
Output is correct |
29 |
Correct |
10 ms |
1876 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
3672 KB |
Output is correct |
2 |
Correct |
6 ms |
1108 KB |
Output is correct |
3 |
Correct |
15 ms |
2528 KB |
Output is correct |
4 |
Correct |
15 ms |
2636 KB |
Output is correct |
5 |
Correct |
23 ms |
3276 KB |
Output is correct |
6 |
Correct |
13 ms |
2132 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
13 ms |
2120 KB |
Output is correct |
9 |
Correct |
35 ms |
5128 KB |
Output is correct |
10 |
Correct |
18 ms |
3112 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
10 ms |
1620 KB |
Output is correct |
27 |
Correct |
26 ms |
4324 KB |
Output is correct |
28 |
Correct |
40 ms |
5012 KB |
Output is correct |
29 |
Correct |
77 ms |
4488 KB |
Output is correct |
30 |
Correct |
89 ms |
5008 KB |
Output is correct |
31 |
Correct |
23 ms |
4164 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
19 ms |
2388 KB |
Output is correct |
34 |
Correct |
32 ms |
4620 KB |
Output is correct |
35 |
Correct |
4 ms |
724 KB |
Output is correct |
36 |
Correct |
20 ms |
2892 KB |
Output is correct |
37 |
Correct |
25 ms |
3424 KB |
Output is correct |
38 |
Correct |
33 ms |
4852 KB |
Output is correct |
39 |
Correct |
10 ms |
1876 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
73 ms |
4888 KB |
Output is correct |
42 |
Correct |
39 ms |
5540 KB |
Output is correct |
43 |
Correct |
50 ms |
4880 KB |
Output is correct |
44 |
Correct |
39 ms |
5272 KB |
Output is correct |
45 |
Correct |
36 ms |
5708 KB |
Output is correct |
46 |
Correct |
82 ms |
5324 KB |
Output is correct |
47 |
Correct |
31 ms |
5044 KB |
Output is correct |
48 |
Correct |
43 ms |
5060 KB |
Output is correct |
49 |
Correct |
34 ms |
4940 KB |
Output is correct |
50 |
Correct |
305 ms |
5332 KB |
Output is correct |
51 |
Correct |
321 ms |
5580 KB |
Output is correct |
52 |
Correct |
296 ms |
5292 KB |
Output is correct |
53 |
Correct |
322 ms |
5584 KB |
Output is correct |
54 |
Correct |
297 ms |
5140 KB |
Output is correct |
55 |
Correct |
334 ms |
5824 KB |
Output is correct |
56 |
Correct |
288 ms |
5072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
23 ms |
3672 KB |
Output is correct |
10 |
Correct |
6 ms |
1108 KB |
Output is correct |
11 |
Correct |
15 ms |
2528 KB |
Output is correct |
12 |
Correct |
15 ms |
2636 KB |
Output is correct |
13 |
Correct |
23 ms |
3276 KB |
Output is correct |
14 |
Correct |
13 ms |
2132 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
13 ms |
2120 KB |
Output is correct |
17 |
Correct |
35 ms |
5128 KB |
Output is correct |
18 |
Correct |
18 ms |
3112 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
10 ms |
1620 KB |
Output is correct |
35 |
Correct |
26 ms |
4324 KB |
Output is correct |
36 |
Correct |
40 ms |
5012 KB |
Output is correct |
37 |
Correct |
77 ms |
4488 KB |
Output is correct |
38 |
Correct |
89 ms |
5008 KB |
Output is correct |
39 |
Correct |
23 ms |
4164 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
19 ms |
2388 KB |
Output is correct |
42 |
Correct |
32 ms |
4620 KB |
Output is correct |
43 |
Correct |
4 ms |
724 KB |
Output is correct |
44 |
Correct |
20 ms |
2892 KB |
Output is correct |
45 |
Correct |
25 ms |
3424 KB |
Output is correct |
46 |
Correct |
33 ms |
4852 KB |
Output is correct |
47 |
Correct |
10 ms |
1876 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Correct |
73 ms |
4888 KB |
Output is correct |
50 |
Correct |
39 ms |
5540 KB |
Output is correct |
51 |
Correct |
50 ms |
4880 KB |
Output is correct |
52 |
Correct |
39 ms |
5272 KB |
Output is correct |
53 |
Correct |
36 ms |
5708 KB |
Output is correct |
54 |
Correct |
82 ms |
5324 KB |
Output is correct |
55 |
Correct |
31 ms |
5044 KB |
Output is correct |
56 |
Correct |
43 ms |
5060 KB |
Output is correct |
57 |
Correct |
34 ms |
4940 KB |
Output is correct |
58 |
Correct |
305 ms |
5332 KB |
Output is correct |
59 |
Correct |
321 ms |
5580 KB |
Output is correct |
60 |
Correct |
296 ms |
5292 KB |
Output is correct |
61 |
Correct |
322 ms |
5584 KB |
Output is correct |
62 |
Correct |
297 ms |
5140 KB |
Output is correct |
63 |
Correct |
334 ms |
5824 KB |
Output is correct |
64 |
Correct |
288 ms |
5072 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
1 ms |
336 KB |
Output is correct |
67 |
Correct |
315 ms |
5476 KB |
Output is correct |
68 |
Correct |
308 ms |
5452 KB |
Output is correct |
69 |
Correct |
274 ms |
4940 KB |
Output is correct |
70 |
Correct |
311 ms |
5300 KB |
Output is correct |
71 |
Correct |
298 ms |
5224 KB |
Output is correct |
72 |
Correct |
289 ms |
5136 KB |
Output is correct |
73 |
Correct |
287 ms |
5012 KB |
Output is correct |
74 |
Correct |
312 ms |
5408 KB |
Output is correct |
75 |
Correct |
299 ms |
5188 KB |
Output is correct |
76 |
Correct |
323 ms |
5524 KB |
Output is correct |
77 |
Correct |
67 ms |
5696 KB |
Output is correct |
78 |
Correct |
35 ms |
5240 KB |
Output is correct |
79 |
Correct |
50 ms |
4940 KB |
Output is correct |
80 |
Correct |
57 ms |
5324 KB |
Output is correct |
81 |
Correct |
49 ms |
4840 KB |
Output is correct |
82 |
Correct |
48 ms |
5488 KB |
Output is correct |
83 |
Correct |
37 ms |
4976 KB |
Output is correct |
84 |
Correct |
200 ms |
5648 KB |
Output is correct |
85 |
Correct |
337 ms |
5736 KB |
Output is correct |
86 |
Correct |
1 ms |
336 KB |
Output is correct |
87 |
Correct |
1 ms |
340 KB |
Output is correct |
88 |
Correct |
335 ms |
5800 KB |
Output is correct |
89 |
Correct |
66 ms |
1364 KB |
Output is correct |
90 |
Correct |
1 ms |
340 KB |
Output is correct |