//Dost SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define vi vector<int>
#define all(xx) xx.begin(),xx.end()
#define ps(xxx) cout << (xxx) << endl;
const int N = 5e2+1,inf = 1e16,MOD = 1e9+7;
int t1[400001],lazy1[400001],t2[400001],lazy2[400001];
struct ST {
int* t;
int* lazy;
ST(int* p1,int* p2) {
t = p1,lazy = p2;
}
inline void push(const int& node,const int& l,const int& r) {
if (!lazy[node]) return;
t[node] = (r-l+1)-t[node];
if (l != r) {
lazy[2*node]^=1;
lazy[2*node+1]^=1;
}
lazy[node] = 0;
}
void update(int node,int l,int r,int L,int R) {
push(node,l,r);
if (l > R || r < L) return;
if (l >= L && r <= R) {
lazy[node]^=1;
push(node,l,r);
return;
}
int m = (l+r) >> 1;
update(2*node,l,m,L,R),update(2*node+1,m+1,r,L,R);
t[node] = t[2*node]+t[2*node+1];
}
int query(int node,int l,int r,int L,int R) {
push(node,l,r);
if (l > R || r < L) return 0;
if (l >= L && r <= R) return t[node];
int m = (l+r) >> 1;
return query(2*node,l,m,L,R)+query(2*node+1,m+1,r,L,R);
}
void clear() {
fill(lazy,lazy+400001,0);
fill(t,t+400001,0);
}
};
void solve() {
int n,k;
cin >> n >> k;
vector<pii> upds[n+1];
for (int i=1;i<=k;i++) {
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
upds[x1].push_back({y1,y2});
if (x2 < n) upds[x2+1].push_back({y1,y2});
}
vi divs;
for (int i=1;i<n;i++) if (n%i == 0) divs.push_back(i);
int ans = inf;
ST st1(t1,lazy1),st2(t2,lazy2);
for (int d : divs) {
st1.clear();
st2.clear();
int cur = 1;
while (cur <= n) {
if ((cur/d)%2) st2.update(1,1,n,cur,cur+d-1);
else st1.update(1,1,n,cur,cur+d-1);
cur+=d;
}
int need = 0;
for (int j = 1;j<=n;j++) {
for (auto it : upds[j]) {
st1.update(1,1,n,it.ff,it.ss);
st2.update(1,1,n,it.ff,it.ss);
}
if (((j-1)/d)%2 == 0) need+=st1.query(1,1,n,1,n);
else need+=st2.query(1,1,n,1,n);
}
ans = min(ans,need);
ans = min(ans,n*n-need);
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12880 KB |
Output is correct |
2 |
Correct |
6 ms |
12880 KB |
Output is correct |
3 |
Correct |
5 ms |
12880 KB |
Output is correct |
4 |
Correct |
5 ms |
12984 KB |
Output is correct |
5 |
Correct |
3 ms |
12880 KB |
Output is correct |
6 |
Correct |
7 ms |
12988 KB |
Output is correct |
7 |
Correct |
3 ms |
12880 KB |
Output is correct |
8 |
Correct |
4 ms |
12980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
17484 KB |
Output is correct |
2 |
Correct |
18 ms |
14176 KB |
Output is correct |
3 |
Correct |
53 ms |
17044 KB |
Output is correct |
4 |
Correct |
32 ms |
15440 KB |
Output is correct |
5 |
Correct |
91 ms |
17056 KB |
Output is correct |
6 |
Correct |
41 ms |
15696 KB |
Output is correct |
7 |
Correct |
14 ms |
13904 KB |
Output is correct |
8 |
Correct |
56 ms |
15952 KB |
Output is correct |
9 |
Correct |
87 ms |
18256 KB |
Output is correct |
10 |
Correct |
52 ms |
16376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12880 KB |
Output is correct |
2 |
Correct |
16 ms |
12916 KB |
Output is correct |
3 |
Correct |
19 ms |
12880 KB |
Output is correct |
4 |
Correct |
19 ms |
12884 KB |
Output is correct |
5 |
Correct |
11 ms |
12880 KB |
Output is correct |
6 |
Correct |
11 ms |
12880 KB |
Output is correct |
7 |
Correct |
14 ms |
12880 KB |
Output is correct |
8 |
Correct |
6 ms |
12880 KB |
Output is correct |
9 |
Correct |
4 ms |
12880 KB |
Output is correct |
10 |
Correct |
4 ms |
12880 KB |
Output is correct |
11 |
Correct |
4 ms |
12880 KB |
Output is correct |
12 |
Correct |
3 ms |
12880 KB |
Output is correct |
13 |
Correct |
5 ms |
12880 KB |
Output is correct |
14 |
Correct |
6 ms |
12880 KB |
Output is correct |
15 |
Correct |
5 ms |
12880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12880 KB |
Output is correct |
2 |
Correct |
16 ms |
12916 KB |
Output is correct |
3 |
Correct |
19 ms |
12880 KB |
Output is correct |
4 |
Correct |
19 ms |
12884 KB |
Output is correct |
5 |
Correct |
11 ms |
12880 KB |
Output is correct |
6 |
Correct |
11 ms |
12880 KB |
Output is correct |
7 |
Correct |
14 ms |
12880 KB |
Output is correct |
8 |
Correct |
6 ms |
12880 KB |
Output is correct |
9 |
Correct |
4 ms |
12880 KB |
Output is correct |
10 |
Correct |
4 ms |
12880 KB |
Output is correct |
11 |
Correct |
4 ms |
12880 KB |
Output is correct |
12 |
Correct |
3 ms |
12880 KB |
Output is correct |
13 |
Correct |
5 ms |
12880 KB |
Output is correct |
14 |
Correct |
6 ms |
12880 KB |
Output is correct |
15 |
Correct |
5 ms |
12880 KB |
Output is correct |
16 |
Correct |
38 ms |
14160 KB |
Output is correct |
17 |
Correct |
63 ms |
17220 KB |
Output is correct |
18 |
Correct |
147 ms |
17232 KB |
Output is correct |
19 |
Correct |
736 ms |
17280 KB |
Output is correct |
20 |
Correct |
785 ms |
17028 KB |
Output is correct |
21 |
Correct |
46 ms |
17232 KB |
Output is correct |
22 |
Correct |
8 ms |
12880 KB |
Output is correct |
23 |
Correct |
92 ms |
15184 KB |
Output is correct |
24 |
Correct |
98 ms |
17232 KB |
Output is correct |
25 |
Correct |
21 ms |
13392 KB |
Output is correct |
26 |
Correct |
63 ms |
15628 KB |
Output is correct |
27 |
Correct |
114 ms |
16976 KB |
Output is correct |
28 |
Correct |
100 ms |
17224 KB |
Output is correct |
29 |
Correct |
20 ms |
14672 KB |
Output is correct |
30 |
Correct |
6 ms |
13136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
17484 KB |
Output is correct |
2 |
Correct |
18 ms |
14176 KB |
Output is correct |
3 |
Correct |
53 ms |
17044 KB |
Output is correct |
4 |
Correct |
32 ms |
15440 KB |
Output is correct |
5 |
Correct |
91 ms |
17056 KB |
Output is correct |
6 |
Correct |
41 ms |
15696 KB |
Output is correct |
7 |
Correct |
14 ms |
13904 KB |
Output is correct |
8 |
Correct |
56 ms |
15952 KB |
Output is correct |
9 |
Correct |
87 ms |
18256 KB |
Output is correct |
10 |
Correct |
52 ms |
16376 KB |
Output is correct |
11 |
Correct |
13 ms |
12880 KB |
Output is correct |
12 |
Correct |
16 ms |
12916 KB |
Output is correct |
13 |
Correct |
19 ms |
12880 KB |
Output is correct |
14 |
Correct |
19 ms |
12884 KB |
Output is correct |
15 |
Correct |
11 ms |
12880 KB |
Output is correct |
16 |
Correct |
11 ms |
12880 KB |
Output is correct |
17 |
Correct |
14 ms |
12880 KB |
Output is correct |
18 |
Correct |
6 ms |
12880 KB |
Output is correct |
19 |
Correct |
4 ms |
12880 KB |
Output is correct |
20 |
Correct |
4 ms |
12880 KB |
Output is correct |
21 |
Correct |
4 ms |
12880 KB |
Output is correct |
22 |
Correct |
3 ms |
12880 KB |
Output is correct |
23 |
Correct |
5 ms |
12880 KB |
Output is correct |
24 |
Correct |
6 ms |
12880 KB |
Output is correct |
25 |
Correct |
5 ms |
12880 KB |
Output is correct |
26 |
Correct |
38 ms |
14160 KB |
Output is correct |
27 |
Correct |
63 ms |
17220 KB |
Output is correct |
28 |
Correct |
147 ms |
17232 KB |
Output is correct |
29 |
Correct |
736 ms |
17280 KB |
Output is correct |
30 |
Correct |
785 ms |
17028 KB |
Output is correct |
31 |
Correct |
46 ms |
17232 KB |
Output is correct |
32 |
Correct |
8 ms |
12880 KB |
Output is correct |
33 |
Correct |
92 ms |
15184 KB |
Output is correct |
34 |
Correct |
98 ms |
17232 KB |
Output is correct |
35 |
Correct |
21 ms |
13392 KB |
Output is correct |
36 |
Correct |
63 ms |
15628 KB |
Output is correct |
37 |
Correct |
114 ms |
16976 KB |
Output is correct |
38 |
Correct |
100 ms |
17224 KB |
Output is correct |
39 |
Correct |
20 ms |
14672 KB |
Output is correct |
40 |
Correct |
6 ms |
13136 KB |
Output is correct |
41 |
Correct |
1220 ms |
19644 KB |
Output is correct |
42 |
Correct |
222 ms |
20048 KB |
Output is correct |
43 |
Correct |
525 ms |
19528 KB |
Output is correct |
44 |
Correct |
193 ms |
20040 KB |
Output is correct |
45 |
Correct |
100 ms |
20296 KB |
Output is correct |
46 |
Correct |
1223 ms |
20040 KB |
Output is correct |
47 |
Correct |
95 ms |
19784 KB |
Output is correct |
48 |
Correct |
404 ms |
19868 KB |
Output is correct |
49 |
Correct |
202 ms |
19536 KB |
Output is correct |
50 |
Execution timed out |
2066 ms |
19532 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12880 KB |
Output is correct |
2 |
Correct |
6 ms |
12880 KB |
Output is correct |
3 |
Correct |
5 ms |
12880 KB |
Output is correct |
4 |
Correct |
5 ms |
12984 KB |
Output is correct |
5 |
Correct |
3 ms |
12880 KB |
Output is correct |
6 |
Correct |
7 ms |
12988 KB |
Output is correct |
7 |
Correct |
3 ms |
12880 KB |
Output is correct |
8 |
Correct |
4 ms |
12980 KB |
Output is correct |
9 |
Correct |
73 ms |
17484 KB |
Output is correct |
10 |
Correct |
18 ms |
14176 KB |
Output is correct |
11 |
Correct |
53 ms |
17044 KB |
Output is correct |
12 |
Correct |
32 ms |
15440 KB |
Output is correct |
13 |
Correct |
91 ms |
17056 KB |
Output is correct |
14 |
Correct |
41 ms |
15696 KB |
Output is correct |
15 |
Correct |
14 ms |
13904 KB |
Output is correct |
16 |
Correct |
56 ms |
15952 KB |
Output is correct |
17 |
Correct |
87 ms |
18256 KB |
Output is correct |
18 |
Correct |
52 ms |
16376 KB |
Output is correct |
19 |
Correct |
13 ms |
12880 KB |
Output is correct |
20 |
Correct |
16 ms |
12916 KB |
Output is correct |
21 |
Correct |
19 ms |
12880 KB |
Output is correct |
22 |
Correct |
19 ms |
12884 KB |
Output is correct |
23 |
Correct |
11 ms |
12880 KB |
Output is correct |
24 |
Correct |
11 ms |
12880 KB |
Output is correct |
25 |
Correct |
14 ms |
12880 KB |
Output is correct |
26 |
Correct |
6 ms |
12880 KB |
Output is correct |
27 |
Correct |
4 ms |
12880 KB |
Output is correct |
28 |
Correct |
4 ms |
12880 KB |
Output is correct |
29 |
Correct |
4 ms |
12880 KB |
Output is correct |
30 |
Correct |
3 ms |
12880 KB |
Output is correct |
31 |
Correct |
5 ms |
12880 KB |
Output is correct |
32 |
Correct |
6 ms |
12880 KB |
Output is correct |
33 |
Correct |
5 ms |
12880 KB |
Output is correct |
34 |
Correct |
38 ms |
14160 KB |
Output is correct |
35 |
Correct |
63 ms |
17220 KB |
Output is correct |
36 |
Correct |
147 ms |
17232 KB |
Output is correct |
37 |
Correct |
736 ms |
17280 KB |
Output is correct |
38 |
Correct |
785 ms |
17028 KB |
Output is correct |
39 |
Correct |
46 ms |
17232 KB |
Output is correct |
40 |
Correct |
8 ms |
12880 KB |
Output is correct |
41 |
Correct |
92 ms |
15184 KB |
Output is correct |
42 |
Correct |
98 ms |
17232 KB |
Output is correct |
43 |
Correct |
21 ms |
13392 KB |
Output is correct |
44 |
Correct |
63 ms |
15628 KB |
Output is correct |
45 |
Correct |
114 ms |
16976 KB |
Output is correct |
46 |
Correct |
100 ms |
17224 KB |
Output is correct |
47 |
Correct |
20 ms |
14672 KB |
Output is correct |
48 |
Correct |
6 ms |
13136 KB |
Output is correct |
49 |
Correct |
1220 ms |
19644 KB |
Output is correct |
50 |
Correct |
222 ms |
20048 KB |
Output is correct |
51 |
Correct |
525 ms |
19528 KB |
Output is correct |
52 |
Correct |
193 ms |
20040 KB |
Output is correct |
53 |
Correct |
100 ms |
20296 KB |
Output is correct |
54 |
Correct |
1223 ms |
20040 KB |
Output is correct |
55 |
Correct |
95 ms |
19784 KB |
Output is correct |
56 |
Correct |
404 ms |
19868 KB |
Output is correct |
57 |
Correct |
202 ms |
19536 KB |
Output is correct |
58 |
Execution timed out |
2066 ms |
19532 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |