#include <vector>
#include <iostream>
#include <climits>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MN 107171
using ll = long long;
using namespace std;
int n, k;
namespace AINT {
int V[4 * MN];
bool LZ[4 * MN];
void clear(int u = 1, int s = 1, int d = n) {
V[u] = LZ[u] = 0;
if(s != d)
clear(u * 2, s, (s + d) /2), clear(u * 2 + 1, (s + d) / 2 + 1, d);
}
void prp(int u, int s, int d) {
if(!LZ[u]) return;
V[u] = d - s + 1 - V[u];
LZ[u] = 0;
if(s != d)
LZ[u * 2] ^= 1, LZ[u * 2 + 1] ^= 1;
}
void update(int l, int r, int u = 1, int s = 1, int d = n) {
prp(u, s, d);
if(r < s || d < l) return;
if(l <= s && d <= r) {
LZ[u] ^= 1;
prp(u, s, d);
return;
}
update(l, r, u * 2, s, (s + d) / 2);
update(l, r, u * 2 + 1, (s + d) / 2 + 1, d);
V[u] = V[u * 2] + V[u * 2 + 1];
}
}
vector<pair<int, int>> OP[MN];
ll acopera(int l, int c0) {
if(l == n) return LLONG_MAX;
///c0 = 1 daca coloram primul patrat
AINT::clear();
for(int i = 1 + (1 - c0) * l; i <= n; i += 2 * l)
AINT::update(i, i + l - 1);
ll re = 0;
for(int i = 1; i <= n; ++i) {
for(auto [l, r] : OP[i])
AINT::update(l, r);
re += AINT::V[1];
if(i % l == 0)
AINT::update(1, n);
}
return re;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> k;
ll re = LLONG_MAX;
for (int i = 1, a, b, c, d; i <= k; ++i) {
cin >> a >> b >> c >> d;
OP[a].emplace_back(b, d);
OP[c + 1].emplace_back(b, d);
}
vector<int> D{1};
for (int i = 2; i * i <= n; ++i)
if (i * i == n) D.push_back(i);
else if (n % i == 0)
D.push_back(i), D.push_back(n / i);
for (auto it: D) {
ll v = acopera(it, 0);
re = min(re, min(v, 1ll * n * n - v));
}
cout << re << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2764 KB |
Output is correct |
2 |
Correct |
2 ms |
2764 KB |
Output is correct |
3 |
Correct |
2 ms |
2764 KB |
Output is correct |
4 |
Correct |
1 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2764 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
1 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
5572 KB |
Output is correct |
2 |
Correct |
17 ms |
3532 KB |
Output is correct |
3 |
Correct |
53 ms |
5800 KB |
Output is correct |
4 |
Correct |
37 ms |
4180 KB |
Output is correct |
5 |
Correct |
57 ms |
5332 KB |
Output is correct |
6 |
Correct |
37 ms |
4816 KB |
Output is correct |
7 |
Correct |
15 ms |
3400 KB |
Output is correct |
8 |
Correct |
44 ms |
4716 KB |
Output is correct |
9 |
Correct |
101 ms |
5860 KB |
Output is correct |
10 |
Correct |
50 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2764 KB |
Output is correct |
2 |
Correct |
1 ms |
2764 KB |
Output is correct |
3 |
Correct |
2 ms |
2764 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2844 KB |
Output is correct |
8 |
Correct |
2 ms |
2764 KB |
Output is correct |
9 |
Correct |
2 ms |
2764 KB |
Output is correct |
10 |
Correct |
2 ms |
2780 KB |
Output is correct |
11 |
Correct |
2 ms |
2764 KB |
Output is correct |
12 |
Correct |
2 ms |
2764 KB |
Output is correct |
13 |
Correct |
3 ms |
2764 KB |
Output is correct |
14 |
Correct |
3 ms |
2764 KB |
Output is correct |
15 |
Correct |
2 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2764 KB |
Output is correct |
2 |
Correct |
1 ms |
2764 KB |
Output is correct |
3 |
Correct |
2 ms |
2764 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2844 KB |
Output is correct |
8 |
Correct |
2 ms |
2764 KB |
Output is correct |
9 |
Correct |
2 ms |
2764 KB |
Output is correct |
10 |
Correct |
2 ms |
2780 KB |
Output is correct |
11 |
Correct |
2 ms |
2764 KB |
Output is correct |
12 |
Correct |
2 ms |
2764 KB |
Output is correct |
13 |
Correct |
3 ms |
2764 KB |
Output is correct |
14 |
Correct |
3 ms |
2764 KB |
Output is correct |
15 |
Correct |
2 ms |
2764 KB |
Output is correct |
16 |
Correct |
31 ms |
3580 KB |
Output is correct |
17 |
Correct |
46 ms |
5132 KB |
Output is correct |
18 |
Correct |
98 ms |
5068 KB |
Output is correct |
19 |
Correct |
601 ms |
4932 KB |
Output is correct |
20 |
Correct |
668 ms |
5004 KB |
Output is correct |
21 |
Correct |
43 ms |
5060 KB |
Output is correct |
22 |
Correct |
4 ms |
2764 KB |
Output is correct |
23 |
Correct |
86 ms |
4040 KB |
Output is correct |
24 |
Correct |
97 ms |
5096 KB |
Output is correct |
25 |
Correct |
22 ms |
3092 KB |
Output is correct |
26 |
Correct |
64 ms |
4172 KB |
Output is correct |
27 |
Correct |
125 ms |
4884 KB |
Output is correct |
28 |
Correct |
101 ms |
5020 KB |
Output is correct |
29 |
Correct |
20 ms |
3784 KB |
Output is correct |
30 |
Correct |
5 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
5572 KB |
Output is correct |
2 |
Correct |
17 ms |
3532 KB |
Output is correct |
3 |
Correct |
53 ms |
5800 KB |
Output is correct |
4 |
Correct |
37 ms |
4180 KB |
Output is correct |
5 |
Correct |
57 ms |
5332 KB |
Output is correct |
6 |
Correct |
37 ms |
4816 KB |
Output is correct |
7 |
Correct |
15 ms |
3400 KB |
Output is correct |
8 |
Correct |
44 ms |
4716 KB |
Output is correct |
9 |
Correct |
101 ms |
5860 KB |
Output is correct |
10 |
Correct |
50 ms |
5068 KB |
Output is correct |
11 |
Correct |
2 ms |
2764 KB |
Output is correct |
12 |
Correct |
1 ms |
2764 KB |
Output is correct |
13 |
Correct |
2 ms |
2764 KB |
Output is correct |
14 |
Correct |
3 ms |
2764 KB |
Output is correct |
15 |
Correct |
2 ms |
2764 KB |
Output is correct |
16 |
Correct |
2 ms |
2764 KB |
Output is correct |
17 |
Correct |
3 ms |
2844 KB |
Output is correct |
18 |
Correct |
2 ms |
2764 KB |
Output is correct |
19 |
Correct |
2 ms |
2764 KB |
Output is correct |
20 |
Correct |
2 ms |
2780 KB |
Output is correct |
21 |
Correct |
2 ms |
2764 KB |
Output is correct |
22 |
Correct |
2 ms |
2764 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
24 |
Correct |
3 ms |
2764 KB |
Output is correct |
25 |
Correct |
2 ms |
2764 KB |
Output is correct |
26 |
Correct |
31 ms |
3580 KB |
Output is correct |
27 |
Correct |
46 ms |
5132 KB |
Output is correct |
28 |
Correct |
98 ms |
5068 KB |
Output is correct |
29 |
Correct |
601 ms |
4932 KB |
Output is correct |
30 |
Correct |
668 ms |
5004 KB |
Output is correct |
31 |
Correct |
43 ms |
5060 KB |
Output is correct |
32 |
Correct |
4 ms |
2764 KB |
Output is correct |
33 |
Correct |
86 ms |
4040 KB |
Output is correct |
34 |
Correct |
97 ms |
5096 KB |
Output is correct |
35 |
Correct |
22 ms |
3092 KB |
Output is correct |
36 |
Correct |
64 ms |
4172 KB |
Output is correct |
37 |
Correct |
125 ms |
4884 KB |
Output is correct |
38 |
Correct |
101 ms |
5020 KB |
Output is correct |
39 |
Correct |
20 ms |
3784 KB |
Output is correct |
40 |
Correct |
5 ms |
2892 KB |
Output is correct |
41 |
Correct |
1054 ms |
7120 KB |
Output is correct |
42 |
Correct |
201 ms |
9668 KB |
Output is correct |
43 |
Correct |
505 ms |
9172 KB |
Output is correct |
44 |
Correct |
222 ms |
9472 KB |
Output is correct |
45 |
Correct |
113 ms |
9764 KB |
Output is correct |
46 |
Correct |
1211 ms |
9620 KB |
Output is correct |
47 |
Correct |
132 ms |
9140 KB |
Output is correct |
48 |
Correct |
354 ms |
9412 KB |
Output is correct |
49 |
Correct |
196 ms |
9128 KB |
Output is correct |
50 |
Execution timed out |
2059 ms |
9364 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2764 KB |
Output is correct |
2 |
Correct |
2 ms |
2764 KB |
Output is correct |
3 |
Correct |
2 ms |
2764 KB |
Output is correct |
4 |
Correct |
1 ms |
2764 KB |
Output is correct |
5 |
Correct |
2 ms |
2764 KB |
Output is correct |
6 |
Correct |
2 ms |
2764 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
1 ms |
2764 KB |
Output is correct |
9 |
Correct |
95 ms |
5572 KB |
Output is correct |
10 |
Correct |
17 ms |
3532 KB |
Output is correct |
11 |
Correct |
53 ms |
5800 KB |
Output is correct |
12 |
Correct |
37 ms |
4180 KB |
Output is correct |
13 |
Correct |
57 ms |
5332 KB |
Output is correct |
14 |
Correct |
37 ms |
4816 KB |
Output is correct |
15 |
Correct |
15 ms |
3400 KB |
Output is correct |
16 |
Correct |
44 ms |
4716 KB |
Output is correct |
17 |
Correct |
101 ms |
5860 KB |
Output is correct |
18 |
Correct |
50 ms |
5068 KB |
Output is correct |
19 |
Correct |
2 ms |
2764 KB |
Output is correct |
20 |
Correct |
1 ms |
2764 KB |
Output is correct |
21 |
Correct |
2 ms |
2764 KB |
Output is correct |
22 |
Correct |
3 ms |
2764 KB |
Output is correct |
23 |
Correct |
2 ms |
2764 KB |
Output is correct |
24 |
Correct |
2 ms |
2764 KB |
Output is correct |
25 |
Correct |
3 ms |
2844 KB |
Output is correct |
26 |
Correct |
2 ms |
2764 KB |
Output is correct |
27 |
Correct |
2 ms |
2764 KB |
Output is correct |
28 |
Correct |
2 ms |
2780 KB |
Output is correct |
29 |
Correct |
2 ms |
2764 KB |
Output is correct |
30 |
Correct |
2 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
2764 KB |
Output is correct |
32 |
Correct |
3 ms |
2764 KB |
Output is correct |
33 |
Correct |
2 ms |
2764 KB |
Output is correct |
34 |
Correct |
31 ms |
3580 KB |
Output is correct |
35 |
Correct |
46 ms |
5132 KB |
Output is correct |
36 |
Correct |
98 ms |
5068 KB |
Output is correct |
37 |
Correct |
601 ms |
4932 KB |
Output is correct |
38 |
Correct |
668 ms |
5004 KB |
Output is correct |
39 |
Correct |
43 ms |
5060 KB |
Output is correct |
40 |
Correct |
4 ms |
2764 KB |
Output is correct |
41 |
Correct |
86 ms |
4040 KB |
Output is correct |
42 |
Correct |
97 ms |
5096 KB |
Output is correct |
43 |
Correct |
22 ms |
3092 KB |
Output is correct |
44 |
Correct |
64 ms |
4172 KB |
Output is correct |
45 |
Correct |
125 ms |
4884 KB |
Output is correct |
46 |
Correct |
101 ms |
5020 KB |
Output is correct |
47 |
Correct |
20 ms |
3784 KB |
Output is correct |
48 |
Correct |
5 ms |
2892 KB |
Output is correct |
49 |
Correct |
1054 ms |
7120 KB |
Output is correct |
50 |
Correct |
201 ms |
9668 KB |
Output is correct |
51 |
Correct |
505 ms |
9172 KB |
Output is correct |
52 |
Correct |
222 ms |
9472 KB |
Output is correct |
53 |
Correct |
113 ms |
9764 KB |
Output is correct |
54 |
Correct |
1211 ms |
9620 KB |
Output is correct |
55 |
Correct |
132 ms |
9140 KB |
Output is correct |
56 |
Correct |
354 ms |
9412 KB |
Output is correct |
57 |
Correct |
196 ms |
9128 KB |
Output is correct |
58 |
Execution timed out |
2059 ms |
9364 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |