#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(){
cin >> n >> k;
for (int i = 0; i < k; i++)
{
int x1, y1, x2, y2; cin >> 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();
}
# |
결과 |
실행 시간 |
메모리 |
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 |
4900 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 |
1 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
6936 KB |
Output is correct |
2 |
Correct |
22 ms |
5464 KB |
Output is correct |
3 |
Correct |
58 ms |
7764 KB |
Output is correct |
4 |
Correct |
58 ms |
6996 KB |
Output is correct |
5 |
Correct |
77 ms |
8056 KB |
Output is correct |
6 |
Correct |
50 ms |
6972 KB |
Output is correct |
7 |
Correct |
11 ms |
5212 KB |
Output is correct |
8 |
Correct |
50 ms |
6988 KB |
Output is correct |
9 |
Correct |
121 ms |
9372 KB |
Output is correct |
10 |
Correct |
70 ms |
7668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
2 ms |
4696 KB |
Output is correct |
4 |
Correct |
3 ms |
4696 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 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 |
2 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4748 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 |
4696 KB |
Output is correct |
3 |
Correct |
2 ms |
4696 KB |
Output is correct |
4 |
Correct |
3 ms |
4696 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 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 |
2 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4748 KB |
Output is correct |
14 |
Correct |
2 ms |
4700 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
44 ms |
5212 KB |
Output is correct |
17 |
Correct |
81 ms |
6944 KB |
Output is correct |
18 |
Correct |
142 ms |
6880 KB |
Output is correct |
19 |
Correct |
671 ms |
6868 KB |
Output is correct |
20 |
Correct |
750 ms |
6860 KB |
Output is correct |
21 |
Correct |
79 ms |
6812 KB |
Output is correct |
22 |
Correct |
3 ms |
4696 KB |
Output is correct |
23 |
Correct |
111 ms |
5828 KB |
Output is correct |
24 |
Correct |
126 ms |
6736 KB |
Output is correct |
25 |
Correct |
23 ms |
4952 KB |
Output is correct |
26 |
Correct |
81 ms |
6040 KB |
Output is correct |
27 |
Correct |
132 ms |
6744 KB |
Output is correct |
28 |
Correct |
134 ms |
6828 KB |
Output is correct |
29 |
Correct |
31 ms |
5604 KB |
Output is correct |
30 |
Correct |
5 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
6936 KB |
Output is correct |
2 |
Correct |
22 ms |
5464 KB |
Output is correct |
3 |
Correct |
58 ms |
7764 KB |
Output is correct |
4 |
Correct |
58 ms |
6996 KB |
Output is correct |
5 |
Correct |
77 ms |
8056 KB |
Output is correct |
6 |
Correct |
50 ms |
6972 KB |
Output is correct |
7 |
Correct |
11 ms |
5212 KB |
Output is correct |
8 |
Correct |
50 ms |
6988 KB |
Output is correct |
9 |
Correct |
121 ms |
9372 KB |
Output is correct |
10 |
Correct |
70 ms |
7668 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
14 |
Correct |
3 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
2 ms |
4700 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 |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4748 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 KB |
Output is correct |
26 |
Correct |
44 ms |
5212 KB |
Output is correct |
27 |
Correct |
81 ms |
6944 KB |
Output is correct |
28 |
Correct |
142 ms |
6880 KB |
Output is correct |
29 |
Correct |
671 ms |
6868 KB |
Output is correct |
30 |
Correct |
750 ms |
6860 KB |
Output is correct |
31 |
Correct |
79 ms |
6812 KB |
Output is correct |
32 |
Correct |
3 ms |
4696 KB |
Output is correct |
33 |
Correct |
111 ms |
5828 KB |
Output is correct |
34 |
Correct |
126 ms |
6736 KB |
Output is correct |
35 |
Correct |
23 ms |
4952 KB |
Output is correct |
36 |
Correct |
81 ms |
6040 KB |
Output is correct |
37 |
Correct |
132 ms |
6744 KB |
Output is correct |
38 |
Correct |
134 ms |
6828 KB |
Output is correct |
39 |
Correct |
31 ms |
5604 KB |
Output is correct |
40 |
Correct |
5 ms |
4700 KB |
Output is correct |
41 |
Correct |
1086 ms |
10476 KB |
Output is correct |
42 |
Correct |
232 ms |
10812 KB |
Output is correct |
43 |
Correct |
537 ms |
10368 KB |
Output is correct |
44 |
Correct |
254 ms |
10780 KB |
Output is correct |
45 |
Correct |
185 ms |
10892 KB |
Output is correct |
46 |
Correct |
1195 ms |
10868 KB |
Output is correct |
47 |
Correct |
123 ms |
10320 KB |
Output is correct |
48 |
Correct |
388 ms |
10436 KB |
Output is correct |
49 |
Correct |
211 ms |
10324 KB |
Output is correct |
50 |
Execution timed out |
2031 ms |
10576 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
4900 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 |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
90 ms |
6936 KB |
Output is correct |
10 |
Correct |
22 ms |
5464 KB |
Output is correct |
11 |
Correct |
58 ms |
7764 KB |
Output is correct |
12 |
Correct |
58 ms |
6996 KB |
Output is correct |
13 |
Correct |
77 ms |
8056 KB |
Output is correct |
14 |
Correct |
50 ms |
6972 KB |
Output is correct |
15 |
Correct |
11 ms |
5212 KB |
Output is correct |
16 |
Correct |
50 ms |
6988 KB |
Output is correct |
17 |
Correct |
121 ms |
9372 KB |
Output is correct |
18 |
Correct |
70 ms |
7668 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4696 KB |
Output is correct |
21 |
Correct |
2 ms |
4696 KB |
Output is correct |
22 |
Correct |
3 ms |
4696 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4700 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 |
2 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4748 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
2 ms |
4700 KB |
Output is correct |
34 |
Correct |
44 ms |
5212 KB |
Output is correct |
35 |
Correct |
81 ms |
6944 KB |
Output is correct |
36 |
Correct |
142 ms |
6880 KB |
Output is correct |
37 |
Correct |
671 ms |
6868 KB |
Output is correct |
38 |
Correct |
750 ms |
6860 KB |
Output is correct |
39 |
Correct |
79 ms |
6812 KB |
Output is correct |
40 |
Correct |
3 ms |
4696 KB |
Output is correct |
41 |
Correct |
111 ms |
5828 KB |
Output is correct |
42 |
Correct |
126 ms |
6736 KB |
Output is correct |
43 |
Correct |
23 ms |
4952 KB |
Output is correct |
44 |
Correct |
81 ms |
6040 KB |
Output is correct |
45 |
Correct |
132 ms |
6744 KB |
Output is correct |
46 |
Correct |
134 ms |
6828 KB |
Output is correct |
47 |
Correct |
31 ms |
5604 KB |
Output is correct |
48 |
Correct |
5 ms |
4700 KB |
Output is correct |
49 |
Correct |
1086 ms |
10476 KB |
Output is correct |
50 |
Correct |
232 ms |
10812 KB |
Output is correct |
51 |
Correct |
537 ms |
10368 KB |
Output is correct |
52 |
Correct |
254 ms |
10780 KB |
Output is correct |
53 |
Correct |
185 ms |
10892 KB |
Output is correct |
54 |
Correct |
1195 ms |
10868 KB |
Output is correct |
55 |
Correct |
123 ms |
10320 KB |
Output is correct |
56 |
Correct |
388 ms |
10436 KB |
Output is correct |
57 |
Correct |
211 ms |
10324 KB |
Output is correct |
58 |
Execution timed out |
2031 ms |
10576 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |