#include <bits/stdc++.h>
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define ld long double
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const int N = 1e5 + 2;
int n, sum[100002], k, lazy[400002], aint[400002], l[400002], r[400002];
struct query {
int type, l, r;
bool operator < (const query &other) {
return type < other.type;
}
};
vector<query>q[100002];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> k;
while (k--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--; y1--; x2--; y2--;
q[x1].push_back({1, y1, y2});
q[x2 + 1].push_back({0, y1, y2});
}
for (int i = 0; i < n; i++)
sort(q[i].begin(), q[i].end());
ll sol = 1ll * n * n, div = 0;;
for (int lat = 1; lat < n; lat++) {
if (n % lat == 0) {
div++;
for (int i = 0; i < n; i++) {
sum[i] = ((i / lat) & 1) + (i > 0 ? sum[i - 1] : 0);
}
ll lin = sum[n - 1], nr = 0;
for (int i = 0; i < n; i++) {
for (auto it : q[i]) {
if (it.type == 0) {
lin = lin - (it.r - it.l + 1) + 2 * (sum[it.r] - (it.l > 0 ? sum[it.l - 1] : 0));
}
else {
lin = lin + (it.r - it.l + 1) - 2 * (sum[it.r] - (it.l > 0 ? sum[it.l - 1] : 0));
}
}
if ((i / lat) & 1)
nr += n - lin;
else
nr += lin;
}
sol = min(sol, min(nr, 1l * n * n - nr));
}
}
cout << sol;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2672 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
1 ms |
2636 KB |
Output is correct |
4 |
Correct |
1 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
1 ms |
2636 KB |
Output is correct |
7 |
Correct |
1 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
5744 KB |
Output is correct |
2 |
Correct |
9 ms |
3700 KB |
Output is correct |
3 |
Correct |
24 ms |
5636 KB |
Output is correct |
4 |
Correct |
18 ms |
4800 KB |
Output is correct |
5 |
Correct |
29 ms |
5736 KB |
Output is correct |
6 |
Correct |
18 ms |
4596 KB |
Output is correct |
7 |
Correct |
5 ms |
3268 KB |
Output is correct |
8 |
Correct |
20 ms |
5036 KB |
Output is correct |
9 |
Correct |
47 ms |
7980 KB |
Output is correct |
10 |
Correct |
26 ms |
5932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2672 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
1 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2672 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
1 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
13 ms |
4124 KB |
Output is correct |
17 |
Correct |
27 ms |
6132 KB |
Output is correct |
18 |
Correct |
32 ms |
6160 KB |
Output is correct |
19 |
Correct |
44 ms |
6000 KB |
Output is correct |
20 |
Correct |
46 ms |
6488 KB |
Output is correct |
21 |
Correct |
27 ms |
7304 KB |
Output is correct |
22 |
Correct |
2 ms |
2676 KB |
Output is correct |
23 |
Correct |
16 ms |
4980 KB |
Output is correct |
24 |
Correct |
31 ms |
7364 KB |
Output is correct |
25 |
Correct |
6 ms |
3060 KB |
Output is correct |
26 |
Correct |
19 ms |
5444 KB |
Output is correct |
27 |
Correct |
24 ms |
6212 KB |
Output is correct |
28 |
Correct |
31 ms |
7224 KB |
Output is correct |
29 |
Correct |
12 ms |
4556 KB |
Output is correct |
30 |
Correct |
3 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
5744 KB |
Output is correct |
2 |
Correct |
9 ms |
3700 KB |
Output is correct |
3 |
Correct |
24 ms |
5636 KB |
Output is correct |
4 |
Correct |
18 ms |
4800 KB |
Output is correct |
5 |
Correct |
29 ms |
5736 KB |
Output is correct |
6 |
Correct |
18 ms |
4596 KB |
Output is correct |
7 |
Correct |
5 ms |
3268 KB |
Output is correct |
8 |
Correct |
20 ms |
5036 KB |
Output is correct |
9 |
Correct |
47 ms |
7980 KB |
Output is correct |
10 |
Correct |
26 ms |
5932 KB |
Output is correct |
11 |
Correct |
1 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2672 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
1 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
2 ms |
2636 KB |
Output is correct |
26 |
Correct |
13 ms |
4124 KB |
Output is correct |
27 |
Correct |
27 ms |
6132 KB |
Output is correct |
28 |
Correct |
32 ms |
6160 KB |
Output is correct |
29 |
Correct |
44 ms |
6000 KB |
Output is correct |
30 |
Correct |
46 ms |
6488 KB |
Output is correct |
31 |
Correct |
27 ms |
7304 KB |
Output is correct |
32 |
Correct |
2 ms |
2676 KB |
Output is correct |
33 |
Correct |
16 ms |
4980 KB |
Output is correct |
34 |
Correct |
31 ms |
7364 KB |
Output is correct |
35 |
Correct |
6 ms |
3060 KB |
Output is correct |
36 |
Correct |
19 ms |
5444 KB |
Output is correct |
37 |
Correct |
24 ms |
6212 KB |
Output is correct |
38 |
Correct |
31 ms |
7224 KB |
Output is correct |
39 |
Correct |
12 ms |
4556 KB |
Output is correct |
40 |
Correct |
3 ms |
2808 KB |
Output is correct |
41 |
Correct |
85 ms |
7904 KB |
Output is correct |
42 |
Correct |
53 ms |
8260 KB |
Output is correct |
43 |
Correct |
67 ms |
7836 KB |
Output is correct |
44 |
Correct |
58 ms |
8184 KB |
Output is correct |
45 |
Correct |
52 ms |
8464 KB |
Output is correct |
46 |
Correct |
91 ms |
8196 KB |
Output is correct |
47 |
Correct |
43 ms |
8004 KB |
Output is correct |
48 |
Correct |
63 ms |
8112 KB |
Output is correct |
49 |
Correct |
53 ms |
7932 KB |
Output is correct |
50 |
Correct |
340 ms |
8056 KB |
Output is correct |
51 |
Correct |
309 ms |
9344 KB |
Output is correct |
52 |
Correct |
267 ms |
8812 KB |
Output is correct |
53 |
Correct |
296 ms |
9312 KB |
Output is correct |
54 |
Correct |
282 ms |
8660 KB |
Output is correct |
55 |
Correct |
322 ms |
9548 KB |
Output is correct |
56 |
Correct |
271 ms |
8568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2672 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
1 ms |
2636 KB |
Output is correct |
4 |
Correct |
1 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
1 ms |
2636 KB |
Output is correct |
7 |
Correct |
1 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
32 ms |
5744 KB |
Output is correct |
10 |
Correct |
9 ms |
3700 KB |
Output is correct |
11 |
Correct |
24 ms |
5636 KB |
Output is correct |
12 |
Correct |
18 ms |
4800 KB |
Output is correct |
13 |
Correct |
29 ms |
5736 KB |
Output is correct |
14 |
Correct |
18 ms |
4596 KB |
Output is correct |
15 |
Correct |
5 ms |
3268 KB |
Output is correct |
16 |
Correct |
20 ms |
5036 KB |
Output is correct |
17 |
Correct |
47 ms |
7980 KB |
Output is correct |
18 |
Correct |
26 ms |
5932 KB |
Output is correct |
19 |
Correct |
1 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2672 KB |
Output is correct |
25 |
Correct |
2 ms |
2636 KB |
Output is correct |
26 |
Correct |
2 ms |
2636 KB |
Output is correct |
27 |
Correct |
2 ms |
2636 KB |
Output is correct |
28 |
Correct |
1 ms |
2636 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
31 |
Correct |
2 ms |
2636 KB |
Output is correct |
32 |
Correct |
2 ms |
2636 KB |
Output is correct |
33 |
Correct |
2 ms |
2636 KB |
Output is correct |
34 |
Correct |
13 ms |
4124 KB |
Output is correct |
35 |
Correct |
27 ms |
6132 KB |
Output is correct |
36 |
Correct |
32 ms |
6160 KB |
Output is correct |
37 |
Correct |
44 ms |
6000 KB |
Output is correct |
38 |
Correct |
46 ms |
6488 KB |
Output is correct |
39 |
Correct |
27 ms |
7304 KB |
Output is correct |
40 |
Correct |
2 ms |
2676 KB |
Output is correct |
41 |
Correct |
16 ms |
4980 KB |
Output is correct |
42 |
Correct |
31 ms |
7364 KB |
Output is correct |
43 |
Correct |
6 ms |
3060 KB |
Output is correct |
44 |
Correct |
19 ms |
5444 KB |
Output is correct |
45 |
Correct |
24 ms |
6212 KB |
Output is correct |
46 |
Correct |
31 ms |
7224 KB |
Output is correct |
47 |
Correct |
12 ms |
4556 KB |
Output is correct |
48 |
Correct |
3 ms |
2808 KB |
Output is correct |
49 |
Correct |
85 ms |
7904 KB |
Output is correct |
50 |
Correct |
53 ms |
8260 KB |
Output is correct |
51 |
Correct |
67 ms |
7836 KB |
Output is correct |
52 |
Correct |
58 ms |
8184 KB |
Output is correct |
53 |
Correct |
52 ms |
8464 KB |
Output is correct |
54 |
Correct |
91 ms |
8196 KB |
Output is correct |
55 |
Correct |
43 ms |
8004 KB |
Output is correct |
56 |
Correct |
63 ms |
8112 KB |
Output is correct |
57 |
Correct |
53 ms |
7932 KB |
Output is correct |
58 |
Correct |
340 ms |
8056 KB |
Output is correct |
59 |
Correct |
309 ms |
9344 KB |
Output is correct |
60 |
Correct |
267 ms |
8812 KB |
Output is correct |
61 |
Correct |
296 ms |
9312 KB |
Output is correct |
62 |
Correct |
282 ms |
8660 KB |
Output is correct |
63 |
Correct |
322 ms |
9548 KB |
Output is correct |
64 |
Correct |
271 ms |
8568 KB |
Output is correct |
65 |
Correct |
1 ms |
2636 KB |
Output is correct |
66 |
Correct |
1 ms |
2636 KB |
Output is correct |
67 |
Correct |
336 ms |
8688 KB |
Output is correct |
68 |
Correct |
304 ms |
8684 KB |
Output is correct |
69 |
Correct |
272 ms |
8064 KB |
Output is correct |
70 |
Correct |
257 ms |
8392 KB |
Output is correct |
71 |
Correct |
265 ms |
8516 KB |
Output is correct |
72 |
Correct |
271 ms |
8300 KB |
Output is correct |
73 |
Correct |
295 ms |
8160 KB |
Output is correct |
74 |
Correct |
267 ms |
8548 KB |
Output is correct |
75 |
Correct |
256 ms |
8308 KB |
Output is correct |
76 |
Correct |
298 ms |
8772 KB |
Output is correct |
77 |
Correct |
95 ms |
9284 KB |
Output is correct |
78 |
Correct |
51 ms |
8604 KB |
Output is correct |
79 |
Correct |
65 ms |
8344 KB |
Output is correct |
80 |
Correct |
66 ms |
8492 KB |
Output is correct |
81 |
Correct |
66 ms |
8108 KB |
Output is correct |
82 |
Correct |
61 ms |
8816 KB |
Output is correct |
83 |
Correct |
53 ms |
8388 KB |
Output is correct |
84 |
Correct |
208 ms |
9028 KB |
Output is correct |
85 |
Correct |
275 ms |
8904 KB |
Output is correct |
86 |
Correct |
121 ms |
2892 KB |
Output is correct |
87 |
Correct |
123 ms |
2980 KB |
Output is correct |
88 |
Correct |
287 ms |
8984 KB |
Output is correct |
89 |
Correct |
153 ms |
4084 KB |
Output is correct |
90 |
Correct |
123 ms |
2892 KB |
Output is correct |