#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 |
2640 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
2636 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
6868 KB |
Output is correct |
2 |
Correct |
19 ms |
3696 KB |
Output is correct |
3 |
Correct |
37 ms |
7108 KB |
Output is correct |
4 |
Correct |
36 ms |
4708 KB |
Output is correct |
5 |
Correct |
48 ms |
6432 KB |
Output is correct |
6 |
Correct |
49 ms |
5544 KB |
Output is correct |
7 |
Correct |
9 ms |
3660 KB |
Output is correct |
8 |
Correct |
36 ms |
5616 KB |
Output is correct |
9 |
Correct |
76 ms |
7144 KB |
Output is correct |
10 |
Correct |
41 ms |
5972 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 |
2680 KB |
Output is correct |
6 |
Correct |
2 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 |
2636 KB |
Output is correct |
10 |
Correct |
2 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 |
3 ms |
2720 KB |
Output is correct |
14 |
Correct |
3 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 |
2680 KB |
Output is correct |
6 |
Correct |
2 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 |
2636 KB |
Output is correct |
10 |
Correct |
2 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 |
3 ms |
2720 KB |
Output is correct |
14 |
Correct |
3 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 |
5948 KB |
Output is correct |
18 |
Correct |
99 ms |
6036 KB |
Output is correct |
19 |
Correct |
587 ms |
5912 KB |
Output is correct |
20 |
Correct |
692 ms |
5916 KB |
Output is correct |
21 |
Correct |
45 ms |
5964 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
81 ms |
4340 KB |
Output is correct |
24 |
Correct |
90 ms |
5972 KB |
Output is correct |
25 |
Correct |
19 ms |
3020 KB |
Output is correct |
26 |
Correct |
59 ms |
4692 KB |
Output is correct |
27 |
Correct |
101 ms |
5744 KB |
Output is correct |
28 |
Correct |
99 ms |
6008 KB |
Output is correct |
29 |
Correct |
20 ms |
4044 KB |
Output is correct |
30 |
Correct |
5 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
6868 KB |
Output is correct |
2 |
Correct |
19 ms |
3696 KB |
Output is correct |
3 |
Correct |
37 ms |
7108 KB |
Output is correct |
4 |
Correct |
36 ms |
4708 KB |
Output is correct |
5 |
Correct |
48 ms |
6432 KB |
Output is correct |
6 |
Correct |
49 ms |
5544 KB |
Output is correct |
7 |
Correct |
9 ms |
3660 KB |
Output is correct |
8 |
Correct |
36 ms |
5616 KB |
Output is correct |
9 |
Correct |
76 ms |
7144 KB |
Output is correct |
10 |
Correct |
41 ms |
5972 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 |
2680 KB |
Output is correct |
16 |
Correct |
2 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 |
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 |
3 ms |
2720 KB |
Output is correct |
24 |
Correct |
3 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 |
5948 KB |
Output is correct |
28 |
Correct |
99 ms |
6036 KB |
Output is correct |
29 |
Correct |
587 ms |
5912 KB |
Output is correct |
30 |
Correct |
692 ms |
5916 KB |
Output is correct |
31 |
Correct |
45 ms |
5964 KB |
Output is correct |
32 |
Correct |
3 ms |
2636 KB |
Output is correct |
33 |
Correct |
81 ms |
4340 KB |
Output is correct |
34 |
Correct |
90 ms |
5972 KB |
Output is correct |
35 |
Correct |
19 ms |
3020 KB |
Output is correct |
36 |
Correct |
59 ms |
4692 KB |
Output is correct |
37 |
Correct |
101 ms |
5744 KB |
Output is correct |
38 |
Correct |
99 ms |
6008 KB |
Output is correct |
39 |
Correct |
20 ms |
4044 KB |
Output is correct |
40 |
Correct |
5 ms |
2764 KB |
Output is correct |
41 |
Correct |
976 ms |
9044 KB |
Output is correct |
42 |
Correct |
178 ms |
9412 KB |
Output is correct |
43 |
Correct |
474 ms |
9068 KB |
Output is correct |
44 |
Correct |
182 ms |
9360 KB |
Output is correct |
45 |
Correct |
97 ms |
9624 KB |
Output is correct |
46 |
Correct |
1134 ms |
9428 KB |
Output is correct |
47 |
Correct |
80 ms |
9156 KB |
Output is correct |
48 |
Correct |
354 ms |
9108 KB |
Output is correct |
49 |
Correct |
184 ms |
9056 KB |
Output is correct |
50 |
Execution timed out |
2075 ms |
9032 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
2636 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2636 KB |
Output is correct |
9 |
Correct |
54 ms |
6868 KB |
Output is correct |
10 |
Correct |
19 ms |
3696 KB |
Output is correct |
11 |
Correct |
37 ms |
7108 KB |
Output is correct |
12 |
Correct |
36 ms |
4708 KB |
Output is correct |
13 |
Correct |
48 ms |
6432 KB |
Output is correct |
14 |
Correct |
49 ms |
5544 KB |
Output is correct |
15 |
Correct |
9 ms |
3660 KB |
Output is correct |
16 |
Correct |
36 ms |
5616 KB |
Output is correct |
17 |
Correct |
76 ms |
7144 KB |
Output is correct |
18 |
Correct |
41 ms |
5972 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 |
2680 KB |
Output is correct |
24 |
Correct |
2 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 |
2636 KB |
Output is correct |
28 |
Correct |
2 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 |
3 ms |
2720 KB |
Output is correct |
32 |
Correct |
3 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 |
5948 KB |
Output is correct |
36 |
Correct |
99 ms |
6036 KB |
Output is correct |
37 |
Correct |
587 ms |
5912 KB |
Output is correct |
38 |
Correct |
692 ms |
5916 KB |
Output is correct |
39 |
Correct |
45 ms |
5964 KB |
Output is correct |
40 |
Correct |
3 ms |
2636 KB |
Output is correct |
41 |
Correct |
81 ms |
4340 KB |
Output is correct |
42 |
Correct |
90 ms |
5972 KB |
Output is correct |
43 |
Correct |
19 ms |
3020 KB |
Output is correct |
44 |
Correct |
59 ms |
4692 KB |
Output is correct |
45 |
Correct |
101 ms |
5744 KB |
Output is correct |
46 |
Correct |
99 ms |
6008 KB |
Output is correct |
47 |
Correct |
20 ms |
4044 KB |
Output is correct |
48 |
Correct |
5 ms |
2764 KB |
Output is correct |
49 |
Correct |
976 ms |
9044 KB |
Output is correct |
50 |
Correct |
178 ms |
9412 KB |
Output is correct |
51 |
Correct |
474 ms |
9068 KB |
Output is correct |
52 |
Correct |
182 ms |
9360 KB |
Output is correct |
53 |
Correct |
97 ms |
9624 KB |
Output is correct |
54 |
Correct |
1134 ms |
9428 KB |
Output is correct |
55 |
Correct |
80 ms |
9156 KB |
Output is correct |
56 |
Correct |
354 ms |
9108 KB |
Output is correct |
57 |
Correct |
184 ms |
9056 KB |
Output is correct |
58 |
Execution timed out |
2075 ms |
9032 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |