#include <bits/stdc++.h>
#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];
struct query {
int type, l, r;
bool operator < (const query &other) {
return type < other.type;
}
};
vector<query>q[100002];
void build (int nod, int st, int dr) {
aint[nod] = sum[dr] - (st > 0 ? sum[st - 1] : 0);
if (st == dr)
return;
int mij = (st + dr) / 2;
build(2 * nod, st, mij);
build(2 * nod + 1, mij + 1, dr);
}
void push (int nod, int st, int dr) {
if (lazy[nod] != -1) {
if (st != dr) {
lazy[2 * nod] = lazy[nod];
lazy[2 * nod + 1] = lazy[nod];
}
if (lazy[nod] == 0)
aint[nod] = sum[dr] - (st > 0 ? sum[st - 1] : 0);
else
aint[nod] = (dr - st + 1) - (sum[dr] - (st > 0 ? sum[st - 1] : 0));
}
lazy[nod] = -1;
}
void update (int nod, int st, int dr, int a, int b, int val) {
push(nod, st, dr);
if (a <= st && dr <= b) {
if (val == 0)
aint[nod] = sum[dr] - (st > 0 ? sum[st - 1] : 0);
else
aint[nod] = (dr - st + 1) - (sum[dr] - (st > 0 ? sum[st - 1] : 0));
if (st != dr) {
lazy[2 * nod] = val;
lazy[2 * nod + 1] = val;
}
return;
}
int mij = (st + dr) / 2;
if (a <= mij)
update(2 * nod, st, mij, a, b, val);
else
update(2 * nod + 1, mij + 1, dr, a, b, val);
aint[nod] = aint[2 * nod] + aint[2 * nod + 1];
}
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;
for (int l = 1; l < n; l++) {
if (n % l == 0) {
for (int i = 0; i < n; i++) {
sum[i] = (i / l) % 2 + (i > 0 ? sum[i - 1] : 0);
}
ll nr = 0;
for (int i = 1; i <= 4 * n; i++) {
lazy[i] = -1;
}
build(1, 0, n - 1);
for (int i = 0; i < n; i++) {
for (auto it : q[i]) {
if (it.type == 0)
update(1, 0, n - 1, it.l, it.r, 0);
else
update(1, 0, n - 1, it.l, it.r, 1);
}
if ((i / l) % 2)
nr += n - aint[1];
else
nr += aint[1];
}
sol = min(sol, min(nr, 1l * n * n - nr));
}
}
cout << sol;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 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 |
1 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 |
1 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
6968 KB |
Output is correct |
2 |
Correct |
15 ms |
4084 KB |
Output is correct |
3 |
Correct |
40 ms |
7976 KB |
Output is correct |
4 |
Correct |
29 ms |
5456 KB |
Output is correct |
5 |
Correct |
49 ms |
7748 KB |
Output is correct |
6 |
Correct |
32 ms |
6372 KB |
Output is correct |
7 |
Correct |
8 ms |
3836 KB |
Output is correct |
8 |
Correct |
37 ms |
6368 KB |
Output is correct |
9 |
Correct |
74 ms |
9244 KB |
Output is correct |
10 |
Correct |
42 ms |
7144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 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 |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2628 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
1 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 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 |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2628 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 |
27 ms |
3660 KB |
Output is correct |
17 |
Correct |
44 ms |
6032 KB |
Output is correct |
18 |
Correct |
96 ms |
6020 KB |
Output is correct |
19 |
Correct |
557 ms |
5908 KB |
Output is correct |
20 |
Correct |
617 ms |
5904 KB |
Output is correct |
21 |
Correct |
43 ms |
5964 KB |
Output is correct |
22 |
Correct |
4 ms |
2636 KB |
Output is correct |
23 |
Correct |
80 ms |
4304 KB |
Output is correct |
24 |
Correct |
90 ms |
6016 KB |
Output is correct |
25 |
Correct |
17 ms |
3020 KB |
Output is correct |
26 |
Correct |
55 ms |
4688 KB |
Output is correct |
27 |
Correct |
106 ms |
5748 KB |
Output is correct |
28 |
Correct |
91 ms |
5844 KB |
Output is correct |
29 |
Correct |
19 ms |
4096 KB |
Output is correct |
30 |
Correct |
6 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
6968 KB |
Output is correct |
2 |
Correct |
15 ms |
4084 KB |
Output is correct |
3 |
Correct |
40 ms |
7976 KB |
Output is correct |
4 |
Correct |
29 ms |
5456 KB |
Output is correct |
5 |
Correct |
49 ms |
7748 KB |
Output is correct |
6 |
Correct |
32 ms |
6372 KB |
Output is correct |
7 |
Correct |
8 ms |
3836 KB |
Output is correct |
8 |
Correct |
37 ms |
6368 KB |
Output is correct |
9 |
Correct |
74 ms |
9244 KB |
Output is correct |
10 |
Correct |
42 ms |
7144 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
1 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2636 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 |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2628 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 |
27 ms |
3660 KB |
Output is correct |
27 |
Correct |
44 ms |
6032 KB |
Output is correct |
28 |
Correct |
96 ms |
6020 KB |
Output is correct |
29 |
Correct |
557 ms |
5908 KB |
Output is correct |
30 |
Correct |
617 ms |
5904 KB |
Output is correct |
31 |
Correct |
43 ms |
5964 KB |
Output is correct |
32 |
Correct |
4 ms |
2636 KB |
Output is correct |
33 |
Correct |
80 ms |
4304 KB |
Output is correct |
34 |
Correct |
90 ms |
6016 KB |
Output is correct |
35 |
Correct |
17 ms |
3020 KB |
Output is correct |
36 |
Correct |
55 ms |
4688 KB |
Output is correct |
37 |
Correct |
106 ms |
5748 KB |
Output is correct |
38 |
Correct |
91 ms |
5844 KB |
Output is correct |
39 |
Correct |
19 ms |
4096 KB |
Output is correct |
40 |
Correct |
6 ms |
2764 KB |
Output is correct |
41 |
Correct |
869 ms |
11028 KB |
Output is correct |
42 |
Correct |
177 ms |
11716 KB |
Output is correct |
43 |
Correct |
437 ms |
11028 KB |
Output is correct |
44 |
Correct |
181 ms |
11552 KB |
Output is correct |
45 |
Correct |
93 ms |
11904 KB |
Output is correct |
46 |
Correct |
968 ms |
11664 KB |
Output is correct |
47 |
Correct |
80 ms |
11204 KB |
Output is correct |
48 |
Correct |
308 ms |
11292 KB |
Output is correct |
49 |
Correct |
159 ms |
11092 KB |
Output is correct |
50 |
Execution timed out |
2064 ms |
11124 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 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 |
1 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 |
1 ms |
2636 KB |
Output is correct |
9 |
Correct |
57 ms |
6968 KB |
Output is correct |
10 |
Correct |
15 ms |
4084 KB |
Output is correct |
11 |
Correct |
40 ms |
7976 KB |
Output is correct |
12 |
Correct |
29 ms |
5456 KB |
Output is correct |
13 |
Correct |
49 ms |
7748 KB |
Output is correct |
14 |
Correct |
32 ms |
6372 KB |
Output is correct |
15 |
Correct |
8 ms |
3836 KB |
Output is correct |
16 |
Correct |
37 ms |
6368 KB |
Output is correct |
17 |
Correct |
74 ms |
9244 KB |
Output is correct |
18 |
Correct |
42 ms |
7144 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 |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
3 ms |
2636 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 |
2644 KB |
Output is correct |
28 |
Correct |
1 ms |
2628 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 |
27 ms |
3660 KB |
Output is correct |
35 |
Correct |
44 ms |
6032 KB |
Output is correct |
36 |
Correct |
96 ms |
6020 KB |
Output is correct |
37 |
Correct |
557 ms |
5908 KB |
Output is correct |
38 |
Correct |
617 ms |
5904 KB |
Output is correct |
39 |
Correct |
43 ms |
5964 KB |
Output is correct |
40 |
Correct |
4 ms |
2636 KB |
Output is correct |
41 |
Correct |
80 ms |
4304 KB |
Output is correct |
42 |
Correct |
90 ms |
6016 KB |
Output is correct |
43 |
Correct |
17 ms |
3020 KB |
Output is correct |
44 |
Correct |
55 ms |
4688 KB |
Output is correct |
45 |
Correct |
106 ms |
5748 KB |
Output is correct |
46 |
Correct |
91 ms |
5844 KB |
Output is correct |
47 |
Correct |
19 ms |
4096 KB |
Output is correct |
48 |
Correct |
6 ms |
2764 KB |
Output is correct |
49 |
Correct |
869 ms |
11028 KB |
Output is correct |
50 |
Correct |
177 ms |
11716 KB |
Output is correct |
51 |
Correct |
437 ms |
11028 KB |
Output is correct |
52 |
Correct |
181 ms |
11552 KB |
Output is correct |
53 |
Correct |
93 ms |
11904 KB |
Output is correct |
54 |
Correct |
968 ms |
11664 KB |
Output is correct |
55 |
Correct |
80 ms |
11204 KB |
Output is correct |
56 |
Correct |
308 ms |
11292 KB |
Output is correct |
57 |
Correct |
159 ms |
11092 KB |
Output is correct |
58 |
Execution timed out |
2064 ms |
11124 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |