#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
const int MAXN = 1e5 + 5;
const int OFF = 1 << 18;
typedef long long ll;
int n, k, tour[OFF];
vector<pair<int, int> > v[MAXN];
bool prop[OFF];
void propagate(int x, int l, int r){
prop[x] = 0;
tour[x] = r - l + 1 - tour[x];
if(l != r){
prop[x * 2 + 1] ^= 1;
prop[x * 2 + 2] ^= 1;
}
}
void upd(int x, int l, int r, int ql, int qr){
if(prop[x]) propagate(x, l, r);
if(ql <= l && r <= qr){
prop[x] = 1;
propagate(x, l, r);
return ;
}
if(ql > r || l > qr) return ;
int mid = (l + r) >> 1;
upd(x * 2 + 1, l, mid, ql, qr);
upd(x * 2 + 2, mid + 1, r, ql, qr);
tour[x] = tour[x * 2 + 1] + tour[x * 2 + 2];
}
ll solve(int k){
ll ret = 5e9;
for(int b = 0; b < 2; ++b){
memset(tour, 0, sizeof tour);
memset(prop, 0, sizeof prop);
ll cur = 0;
for(int i = b * k; i < n; i += 2 * k){
upd(0, 0, n - 1, i, i + k - 1);
}
for(int i = 0; i < n; ++i){
for(pair<int, int> p : v[i]){
upd(0, 0, n - 1, p.X, p.Y);
}
if(i % k == 0) upd(0, 0, n - 1, 0, n - 1);
cur += tour[0];
}
ret = min(ret, cur);
}
return ret;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
for(int i = 0; i < k; ++i){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
--x1, --y1, --x2, --y2;
v[x1].push_back({y1, y2});
v[x2 + 1].push_back({y1, y2});
}
long long ans = 5e9;
for(int i = 1; i < n; ++i){
if(n % i == 0){
ans = min(ans, solve(i));
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3924 KB |
Output is correct |
2 |
Correct |
2 ms |
3924 KB |
Output is correct |
3 |
Correct |
2 ms |
3908 KB |
Output is correct |
4 |
Correct |
2 ms |
3924 KB |
Output is correct |
5 |
Correct |
2 ms |
3924 KB |
Output is correct |
6 |
Correct |
2 ms |
3924 KB |
Output is correct |
7 |
Correct |
2 ms |
3924 KB |
Output is correct |
8 |
Correct |
2 ms |
3948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
6044 KB |
Output is correct |
2 |
Correct |
27 ms |
4436 KB |
Output is correct |
3 |
Correct |
70 ms |
5588 KB |
Output is correct |
4 |
Correct |
46 ms |
5252 KB |
Output is correct |
5 |
Correct |
93 ms |
5892 KB |
Output is correct |
6 |
Correct |
56 ms |
5204 KB |
Output is correct |
7 |
Correct |
14 ms |
4304 KB |
Output is correct |
8 |
Correct |
56 ms |
5204 KB |
Output is correct |
9 |
Correct |
125 ms |
6508 KB |
Output is correct |
10 |
Correct |
73 ms |
5588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3924 KB |
Output is correct |
2 |
Correct |
2 ms |
3924 KB |
Output is correct |
3 |
Correct |
4 ms |
3924 KB |
Output is correct |
4 |
Correct |
4 ms |
3924 KB |
Output is correct |
5 |
Correct |
3 ms |
3924 KB |
Output is correct |
6 |
Correct |
3 ms |
3924 KB |
Output is correct |
7 |
Correct |
3 ms |
3924 KB |
Output is correct |
8 |
Correct |
3 ms |
3924 KB |
Output is correct |
9 |
Correct |
2 ms |
3924 KB |
Output is correct |
10 |
Correct |
2 ms |
3924 KB |
Output is correct |
11 |
Correct |
2 ms |
3864 KB |
Output is correct |
12 |
Correct |
2 ms |
3924 KB |
Output is correct |
13 |
Correct |
4 ms |
3924 KB |
Output is correct |
14 |
Correct |
4 ms |
3924 KB |
Output is correct |
15 |
Correct |
3 ms |
3924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3924 KB |
Output is correct |
2 |
Correct |
2 ms |
3924 KB |
Output is correct |
3 |
Correct |
4 ms |
3924 KB |
Output is correct |
4 |
Correct |
4 ms |
3924 KB |
Output is correct |
5 |
Correct |
3 ms |
3924 KB |
Output is correct |
6 |
Correct |
3 ms |
3924 KB |
Output is correct |
7 |
Correct |
3 ms |
3924 KB |
Output is correct |
8 |
Correct |
3 ms |
3924 KB |
Output is correct |
9 |
Correct |
2 ms |
3924 KB |
Output is correct |
10 |
Correct |
2 ms |
3924 KB |
Output is correct |
11 |
Correct |
2 ms |
3864 KB |
Output is correct |
12 |
Correct |
2 ms |
3924 KB |
Output is correct |
13 |
Correct |
4 ms |
3924 KB |
Output is correct |
14 |
Correct |
4 ms |
3924 KB |
Output is correct |
15 |
Correct |
3 ms |
3924 KB |
Output is correct |
16 |
Correct |
49 ms |
4620 KB |
Output is correct |
17 |
Correct |
65 ms |
6172 KB |
Output is correct |
18 |
Correct |
164 ms |
6248 KB |
Output is correct |
19 |
Correct |
1078 ms |
6124 KB |
Output is correct |
20 |
Correct |
1228 ms |
6100 KB |
Output is correct |
21 |
Correct |
63 ms |
6196 KB |
Output is correct |
22 |
Correct |
7 ms |
3924 KB |
Output is correct |
23 |
Correct |
157 ms |
5052 KB |
Output is correct |
24 |
Correct |
148 ms |
6100 KB |
Output is correct |
25 |
Correct |
33 ms |
4180 KB |
Output is correct |
26 |
Correct |
95 ms |
5280 KB |
Output is correct |
27 |
Correct |
177 ms |
5988 KB |
Output is correct |
28 |
Correct |
179 ms |
6108 KB |
Output is correct |
29 |
Correct |
28 ms |
4820 KB |
Output is correct |
30 |
Correct |
7 ms |
4052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
6044 KB |
Output is correct |
2 |
Correct |
27 ms |
4436 KB |
Output is correct |
3 |
Correct |
70 ms |
5588 KB |
Output is correct |
4 |
Correct |
46 ms |
5252 KB |
Output is correct |
5 |
Correct |
93 ms |
5892 KB |
Output is correct |
6 |
Correct |
56 ms |
5204 KB |
Output is correct |
7 |
Correct |
14 ms |
4304 KB |
Output is correct |
8 |
Correct |
56 ms |
5204 KB |
Output is correct |
9 |
Correct |
125 ms |
6508 KB |
Output is correct |
10 |
Correct |
73 ms |
5588 KB |
Output is correct |
11 |
Correct |
3 ms |
3924 KB |
Output is correct |
12 |
Correct |
2 ms |
3924 KB |
Output is correct |
13 |
Correct |
4 ms |
3924 KB |
Output is correct |
14 |
Correct |
4 ms |
3924 KB |
Output is correct |
15 |
Correct |
3 ms |
3924 KB |
Output is correct |
16 |
Correct |
3 ms |
3924 KB |
Output is correct |
17 |
Correct |
3 ms |
3924 KB |
Output is correct |
18 |
Correct |
3 ms |
3924 KB |
Output is correct |
19 |
Correct |
2 ms |
3924 KB |
Output is correct |
20 |
Correct |
2 ms |
3924 KB |
Output is correct |
21 |
Correct |
2 ms |
3864 KB |
Output is correct |
22 |
Correct |
2 ms |
3924 KB |
Output is correct |
23 |
Correct |
4 ms |
3924 KB |
Output is correct |
24 |
Correct |
4 ms |
3924 KB |
Output is correct |
25 |
Correct |
3 ms |
3924 KB |
Output is correct |
26 |
Correct |
49 ms |
4620 KB |
Output is correct |
27 |
Correct |
65 ms |
6172 KB |
Output is correct |
28 |
Correct |
164 ms |
6248 KB |
Output is correct |
29 |
Correct |
1078 ms |
6124 KB |
Output is correct |
30 |
Correct |
1228 ms |
6100 KB |
Output is correct |
31 |
Correct |
63 ms |
6196 KB |
Output is correct |
32 |
Correct |
7 ms |
3924 KB |
Output is correct |
33 |
Correct |
157 ms |
5052 KB |
Output is correct |
34 |
Correct |
148 ms |
6100 KB |
Output is correct |
35 |
Correct |
33 ms |
4180 KB |
Output is correct |
36 |
Correct |
95 ms |
5280 KB |
Output is correct |
37 |
Correct |
177 ms |
5988 KB |
Output is correct |
38 |
Correct |
179 ms |
6108 KB |
Output is correct |
39 |
Correct |
28 ms |
4820 KB |
Output is correct |
40 |
Correct |
7 ms |
4052 KB |
Output is correct |
41 |
Correct |
1968 ms |
6952 KB |
Output is correct |
42 |
Correct |
350 ms |
7200 KB |
Output is correct |
43 |
Correct |
1022 ms |
6952 KB |
Output is correct |
44 |
Correct |
359 ms |
7180 KB |
Output is correct |
45 |
Correct |
194 ms |
7244 KB |
Output is correct |
46 |
Execution timed out |
2072 ms |
7148 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3924 KB |
Output is correct |
2 |
Correct |
2 ms |
3924 KB |
Output is correct |
3 |
Correct |
2 ms |
3908 KB |
Output is correct |
4 |
Correct |
2 ms |
3924 KB |
Output is correct |
5 |
Correct |
2 ms |
3924 KB |
Output is correct |
6 |
Correct |
2 ms |
3924 KB |
Output is correct |
7 |
Correct |
2 ms |
3924 KB |
Output is correct |
8 |
Correct |
2 ms |
3948 KB |
Output is correct |
9 |
Correct |
98 ms |
6044 KB |
Output is correct |
10 |
Correct |
27 ms |
4436 KB |
Output is correct |
11 |
Correct |
70 ms |
5588 KB |
Output is correct |
12 |
Correct |
46 ms |
5252 KB |
Output is correct |
13 |
Correct |
93 ms |
5892 KB |
Output is correct |
14 |
Correct |
56 ms |
5204 KB |
Output is correct |
15 |
Correct |
14 ms |
4304 KB |
Output is correct |
16 |
Correct |
56 ms |
5204 KB |
Output is correct |
17 |
Correct |
125 ms |
6508 KB |
Output is correct |
18 |
Correct |
73 ms |
5588 KB |
Output is correct |
19 |
Correct |
3 ms |
3924 KB |
Output is correct |
20 |
Correct |
2 ms |
3924 KB |
Output is correct |
21 |
Correct |
4 ms |
3924 KB |
Output is correct |
22 |
Correct |
4 ms |
3924 KB |
Output is correct |
23 |
Correct |
3 ms |
3924 KB |
Output is correct |
24 |
Correct |
3 ms |
3924 KB |
Output is correct |
25 |
Correct |
3 ms |
3924 KB |
Output is correct |
26 |
Correct |
3 ms |
3924 KB |
Output is correct |
27 |
Correct |
2 ms |
3924 KB |
Output is correct |
28 |
Correct |
2 ms |
3924 KB |
Output is correct |
29 |
Correct |
2 ms |
3864 KB |
Output is correct |
30 |
Correct |
2 ms |
3924 KB |
Output is correct |
31 |
Correct |
4 ms |
3924 KB |
Output is correct |
32 |
Correct |
4 ms |
3924 KB |
Output is correct |
33 |
Correct |
3 ms |
3924 KB |
Output is correct |
34 |
Correct |
49 ms |
4620 KB |
Output is correct |
35 |
Correct |
65 ms |
6172 KB |
Output is correct |
36 |
Correct |
164 ms |
6248 KB |
Output is correct |
37 |
Correct |
1078 ms |
6124 KB |
Output is correct |
38 |
Correct |
1228 ms |
6100 KB |
Output is correct |
39 |
Correct |
63 ms |
6196 KB |
Output is correct |
40 |
Correct |
7 ms |
3924 KB |
Output is correct |
41 |
Correct |
157 ms |
5052 KB |
Output is correct |
42 |
Correct |
148 ms |
6100 KB |
Output is correct |
43 |
Correct |
33 ms |
4180 KB |
Output is correct |
44 |
Correct |
95 ms |
5280 KB |
Output is correct |
45 |
Correct |
177 ms |
5988 KB |
Output is correct |
46 |
Correct |
179 ms |
6108 KB |
Output is correct |
47 |
Correct |
28 ms |
4820 KB |
Output is correct |
48 |
Correct |
7 ms |
4052 KB |
Output is correct |
49 |
Correct |
1968 ms |
6952 KB |
Output is correct |
50 |
Correct |
350 ms |
7200 KB |
Output is correct |
51 |
Correct |
1022 ms |
6952 KB |
Output is correct |
52 |
Correct |
359 ms |
7180 KB |
Output is correct |
53 |
Correct |
194 ms |
7244 KB |
Output is correct |
54 |
Execution timed out |
2072 ms |
7148 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |