#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
const int MAXN = 1e5 + 2;
const int OFF = 1 << 18;
typedef long long ll;
int n, k, tour[OFF];
vector<pair<int, int> > v[MAXN];
bool prop[MAXN];
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){
for(int i = 0; i < 2 * n; ++i) tour[i] = prop[i] = 0;
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(){
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 |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2608 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
12344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
12344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2608 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |