#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 = 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2664 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2664 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Correct |
2 ms |
2664 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
8452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2660 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
4 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2676 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2668 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2676 KB |
Output is correct |
12 |
Correct |
3 ms |
2676 KB |
Output is correct |
13 |
Correct |
4 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2660 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
4 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2676 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2668 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2676 KB |
Output is correct |
12 |
Correct |
3 ms |
2676 KB |
Output is correct |
13 |
Correct |
4 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2676 KB |
Output is correct |
16 |
Correct |
31 ms |
4068 KB |
Output is correct |
17 |
Correct |
46 ms |
7320 KB |
Output is correct |
18 |
Correct |
100 ms |
7644 KB |
Output is correct |
19 |
Correct |
587 ms |
7348 KB |
Output is correct |
20 |
Correct |
657 ms |
7504 KB |
Output is correct |
21 |
Correct |
44 ms |
7288 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
83 ms |
5028 KB |
Output is correct |
24 |
Correct |
107 ms |
7444 KB |
Output is correct |
25 |
Correct |
20 ms |
3188 KB |
Output is correct |
26 |
Correct |
55 ms |
5596 KB |
Output is correct |
27 |
Correct |
96 ms |
6728 KB |
Output is correct |
28 |
Correct |
92 ms |
7364 KB |
Output is correct |
29 |
Correct |
19 ms |
4672 KB |
Output is correct |
30 |
Correct |
5 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
8452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2664 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2664 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Correct |
2 ms |
2664 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Incorrect |
65 ms |
8452 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |