#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int MAX = 1e5 + 5;
const ll oo = 1e15;
int tree[MAX * 4], lazy[MAX * 4];
void build(int node, int l, int r, int k){
lazy[node] = 0;
if(l == r){
tree[node] = ((l - 1) / k) & 1;
return;
}
int mid = (l + r) / 2;
build(node * 2, l, mid, k);
build(node * 2 + 1, mid + 1, r, k);
tree[node] = tree[node * 2] + tree[node * 2 + 1];
}
void relax(int node, int l, int r){
if(!lazy[node]) return;
tree[node] = (r - l + 1) - tree[node];
if(l != r){
lazy[node * 2] ^= 1;
lazy[node * 2 + 1] ^= 1;
}
lazy[node] = 0;
return;
}
void update(int node, int l, int r, int ql, int qr){
relax(node, l, r);
if(ql > r || qr < l) return;
if(ql <= l && r <= qr){
lazy[node] ^= 1;
relax(node, l, r);
return;
}
int mid = (l + r) / 2;
update(node * 2, l, mid, ql, qr);
update(node * 2 + 1, mid + 1, r, ql, qr);
tree[node] = tree[node * 2] + tree[node * 2 + 1];
}
vector<array<int, 2>> events[MAX];
int n, k;
ll check(int d){
build(1, 1, n, d);
ll a = 0, b = 0;
for (int i = 1; i <= n; i++)
{
if((i - 1) % d == 0) lazy[1] ^= 1;
for(auto& e:events[i]){
update(1, 1, n, e[0], e[1]);
}
relax(1, 1, n);
a += tree[1];
b += n - tree[1];
}
return min(a, b);
}
void solve(){
scanf("%d%d", &n, &k);
for (int i = 0; i < k; i++)
{
int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
events[x1].push_back({y1, y2});
events[x2 + 1].push_back({y1, y2});
}
ll ans = oo;
for (int i = 1; i * i <= n; i++)
{
if(n % i == 0){
ans = min(ans, check(i));
if(i != 1){
ans = min(ans, check(n / i));
}
}
}
cout << ans << '\n';
}
int main()
{
solve();
}
Compilation message
chessboard.cpp: In function 'void solve()':
chessboard.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:73:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4712 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
7000 KB |
Output is correct |
2 |
Correct |
14 ms |
5212 KB |
Output is correct |
3 |
Correct |
37 ms |
6924 KB |
Output is correct |
4 |
Correct |
30 ms |
5976 KB |
Output is correct |
5 |
Correct |
48 ms |
6760 KB |
Output is correct |
6 |
Correct |
32 ms |
5980 KB |
Output is correct |
7 |
Correct |
7 ms |
4956 KB |
Output is correct |
8 |
Correct |
32 ms |
6188 KB |
Output is correct |
9 |
Correct |
75 ms |
7252 KB |
Output is correct |
10 |
Correct |
52 ms |
6540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4700 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4700 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
30 ms |
5208 KB |
Output is correct |
17 |
Correct |
46 ms |
6748 KB |
Output is correct |
18 |
Correct |
107 ms |
6916 KB |
Output is correct |
19 |
Correct |
640 ms |
6876 KB |
Output is correct |
20 |
Correct |
711 ms |
6748 KB |
Output is correct |
21 |
Correct |
44 ms |
6744 KB |
Output is correct |
22 |
Correct |
3 ms |
4700 KB |
Output is correct |
23 |
Correct |
90 ms |
5816 KB |
Output is correct |
24 |
Correct |
95 ms |
6952 KB |
Output is correct |
25 |
Correct |
20 ms |
4952 KB |
Output is correct |
26 |
Correct |
61 ms |
5980 KB |
Output is correct |
27 |
Correct |
108 ms |
6748 KB |
Output is correct |
28 |
Correct |
112 ms |
6868 KB |
Output is correct |
29 |
Correct |
19 ms |
5464 KB |
Output is correct |
30 |
Correct |
4 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
7000 KB |
Output is correct |
2 |
Correct |
14 ms |
5212 KB |
Output is correct |
3 |
Correct |
37 ms |
6924 KB |
Output is correct |
4 |
Correct |
30 ms |
5976 KB |
Output is correct |
5 |
Correct |
48 ms |
6760 KB |
Output is correct |
6 |
Correct |
32 ms |
5980 KB |
Output is correct |
7 |
Correct |
7 ms |
4956 KB |
Output is correct |
8 |
Correct |
32 ms |
6188 KB |
Output is correct |
9 |
Correct |
75 ms |
7252 KB |
Output is correct |
10 |
Correct |
52 ms |
6540 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4696 KB |
Output is correct |
18 |
Correct |
2 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
1 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 KB |
Output is correct |
26 |
Correct |
30 ms |
5208 KB |
Output is correct |
27 |
Correct |
46 ms |
6748 KB |
Output is correct |
28 |
Correct |
107 ms |
6916 KB |
Output is correct |
29 |
Correct |
640 ms |
6876 KB |
Output is correct |
30 |
Correct |
711 ms |
6748 KB |
Output is correct |
31 |
Correct |
44 ms |
6744 KB |
Output is correct |
32 |
Correct |
3 ms |
4700 KB |
Output is correct |
33 |
Correct |
90 ms |
5816 KB |
Output is correct |
34 |
Correct |
95 ms |
6952 KB |
Output is correct |
35 |
Correct |
20 ms |
4952 KB |
Output is correct |
36 |
Correct |
61 ms |
5980 KB |
Output is correct |
37 |
Correct |
108 ms |
6748 KB |
Output is correct |
38 |
Correct |
112 ms |
6868 KB |
Output is correct |
39 |
Correct |
19 ms |
5464 KB |
Output is correct |
40 |
Correct |
4 ms |
4700 KB |
Output is correct |
41 |
Correct |
1101 ms |
8368 KB |
Output is correct |
42 |
Correct |
191 ms |
8692 KB |
Output is correct |
43 |
Correct |
498 ms |
8276 KB |
Output is correct |
44 |
Correct |
186 ms |
8788 KB |
Output is correct |
45 |
Correct |
94 ms |
8784 KB |
Output is correct |
46 |
Correct |
1114 ms |
8788 KB |
Output is correct |
47 |
Correct |
79 ms |
8276 KB |
Output is correct |
48 |
Correct |
404 ms |
8484 KB |
Output is correct |
49 |
Correct |
161 ms |
8384 KB |
Output is correct |
50 |
Execution timed out |
2078 ms |
8284 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4712 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
56 ms |
7000 KB |
Output is correct |
10 |
Correct |
14 ms |
5212 KB |
Output is correct |
11 |
Correct |
37 ms |
6924 KB |
Output is correct |
12 |
Correct |
30 ms |
5976 KB |
Output is correct |
13 |
Correct |
48 ms |
6760 KB |
Output is correct |
14 |
Correct |
32 ms |
5980 KB |
Output is correct |
15 |
Correct |
7 ms |
4956 KB |
Output is correct |
16 |
Correct |
32 ms |
6188 KB |
Output is correct |
17 |
Correct |
75 ms |
7252 KB |
Output is correct |
18 |
Correct |
52 ms |
6540 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4696 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4696 KB |
Output is correct |
26 |
Correct |
2 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4700 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
2 ms |
4700 KB |
Output is correct |
34 |
Correct |
30 ms |
5208 KB |
Output is correct |
35 |
Correct |
46 ms |
6748 KB |
Output is correct |
36 |
Correct |
107 ms |
6916 KB |
Output is correct |
37 |
Correct |
640 ms |
6876 KB |
Output is correct |
38 |
Correct |
711 ms |
6748 KB |
Output is correct |
39 |
Correct |
44 ms |
6744 KB |
Output is correct |
40 |
Correct |
3 ms |
4700 KB |
Output is correct |
41 |
Correct |
90 ms |
5816 KB |
Output is correct |
42 |
Correct |
95 ms |
6952 KB |
Output is correct |
43 |
Correct |
20 ms |
4952 KB |
Output is correct |
44 |
Correct |
61 ms |
5980 KB |
Output is correct |
45 |
Correct |
108 ms |
6748 KB |
Output is correct |
46 |
Correct |
112 ms |
6868 KB |
Output is correct |
47 |
Correct |
19 ms |
5464 KB |
Output is correct |
48 |
Correct |
4 ms |
4700 KB |
Output is correct |
49 |
Correct |
1101 ms |
8368 KB |
Output is correct |
50 |
Correct |
191 ms |
8692 KB |
Output is correct |
51 |
Correct |
498 ms |
8276 KB |
Output is correct |
52 |
Correct |
186 ms |
8788 KB |
Output is correct |
53 |
Correct |
94 ms |
8784 KB |
Output is correct |
54 |
Correct |
1114 ms |
8788 KB |
Output is correct |
55 |
Correct |
79 ms |
8276 KB |
Output is correct |
56 |
Correct |
404 ms |
8484 KB |
Output is correct |
57 |
Correct |
161 ms |
8384 KB |
Output is correct |
58 |
Execution timed out |
2078 ms |
8284 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |