// -- //
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pll pair<ll, ll>
#define ppll pair<pll, pll>
#define x first
#define y second
using namespace std;
typedef long long rll;
typedef int ll;
const ll N = 1e5+228;
ppll a[N];
vector<pll> add[N], del[N];
ll n, k;
rll res;
inline void ch(ll m, ll bln) __attribute__((always_inline));
inline void ch(ll m, ll bln){
rll bob=0, bow=0;
rll no[2]={0};
for(ll i = 1;i<=n;i++){
for(auto &j : add[i]){
ll s = j.x, e = j.y;
--s, e--;
ll bs = s/m, be = e/m;
rll bse = ((rll)bs+1)*m-1;
if(bs==be) no[bs&1] += e-s+1;
else if(bs+1==be){
no[bs&1] += bse-s+1;
no[be&1] += e-bse;
}else{
no[bs&1] += bse-s+1;
no[be&1] += e-bse;
bs++, be--;
ll kb = (be-bs+1)/2;
no[bs&1] += ((rll)(be-bs+1-kb))*m;
no[be&1] += ((rll)kb)*m;
}
}
if(((i-1)/m)&1){
bow+=no[0], bob+=no[1];
}else{
bob+=no[0], bow+=no[1];
}
for(auto &j : del[i]){
ll s = j.x, e = j.y;
--s, e--;
ll bs = s/m, be = e/m;
rll bse = ((rll)bs+1)*m-1;
if(bs==be) no[bs&1] -= e-s+1;
else if(bs+1==be){
no[bs&1] -= bse-s+1;
no[be&1] -= e-bse;
}else{
no[bs&1] -= bse-s+1;
no[be&1] -= e-bse;
bs++, be--;
ll kb = (be-bs+1)/2;
no[bs&1] -= ((rll)(be-bs+1-kb))*m;
no[be&1] -= ((rll)kb)*m;
}
}
}
rll mbb = 1LL*((rll)(bln>>1))*((rll)m)*((rll)n)+1LL*((rll)((bln&1) ? (bln+1)>>1 : 0))*((rll)m)*((rll)m);
rll v1 = (mbb-bob)+bow;
rll v2 = bob+(((rll)n*n)-mbb-bow);
if(v1<res) res=v1;
if(v2<res) res=v2;
}
signed main(){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
cin >> n >> k;
for(ll i =0 ;i<k;i++){
cin >> a[i].x.x >> a[i].x.y >> a[i].y.x >> a[i].y.y;
add[a[i].x.y].push_back({a[i].x.x, a[i].y.x});
del[a[i].y.y].push_back({a[i].x.x, a[i].y.x});
}
res=(rll)n*n;
for(ll i = 1;i*i<=n;i++){
ll k = n/i;
if(n-k*i) continue;
ch(i, k);
if(i>1) ch(k, i);
}
cout<<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
10220 KB |
Output is correct |
2 |
Correct |
13 ms |
6380 KB |
Output is correct |
3 |
Correct |
41 ms |
8684 KB |
Output is correct |
4 |
Correct |
32 ms |
8044 KB |
Output is correct |
5 |
Correct |
47 ms |
9580 KB |
Output is correct |
6 |
Correct |
27 ms |
8044 KB |
Output is correct |
7 |
Correct |
9 ms |
5740 KB |
Output is correct |
8 |
Correct |
41 ms |
8044 KB |
Output is correct |
9 |
Correct |
63 ms |
11628 KB |
Output is correct |
10 |
Correct |
37 ms |
8940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
5 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
5 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
16 ms |
6636 KB |
Output is correct |
17 |
Correct |
39 ms |
10092 KB |
Output is correct |
18 |
Correct |
50 ms |
10476 KB |
Output is correct |
19 |
Correct |
98 ms |
10080 KB |
Output is correct |
20 |
Correct |
105 ms |
10348 KB |
Output is correct |
21 |
Correct |
37 ms |
9836 KB |
Output is correct |
22 |
Correct |
4 ms |
5100 KB |
Output is correct |
23 |
Correct |
28 ms |
7652 KB |
Output is correct |
24 |
Correct |
46 ms |
10212 KB |
Output is correct |
25 |
Correct |
9 ms |
5612 KB |
Output is correct |
26 |
Correct |
30 ms |
8300 KB |
Output is correct |
27 |
Correct |
38 ms |
9196 KB |
Output is correct |
28 |
Correct |
47 ms |
10220 KB |
Output is correct |
29 |
Correct |
21 ms |
7020 KB |
Output is correct |
30 |
Correct |
5 ms |
5228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
10220 KB |
Output is correct |
2 |
Correct |
13 ms |
6380 KB |
Output is correct |
3 |
Correct |
41 ms |
8684 KB |
Output is correct |
4 |
Correct |
32 ms |
8044 KB |
Output is correct |
5 |
Correct |
47 ms |
9580 KB |
Output is correct |
6 |
Correct |
27 ms |
8044 KB |
Output is correct |
7 |
Correct |
9 ms |
5740 KB |
Output is correct |
8 |
Correct |
41 ms |
8044 KB |
Output is correct |
9 |
Correct |
63 ms |
11628 KB |
Output is correct |
10 |
Correct |
37 ms |
8940 KB |
Output is correct |
11 |
Correct |
5 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
5 ms |
5100 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
4 ms |
5100 KB |
Output is correct |
22 |
Correct |
4 ms |
5100 KB |
Output is correct |
23 |
Correct |
4 ms |
5100 KB |
Output is correct |
24 |
Correct |
4 ms |
5100 KB |
Output is correct |
25 |
Correct |
4 ms |
5100 KB |
Output is correct |
26 |
Correct |
16 ms |
6636 KB |
Output is correct |
27 |
Correct |
39 ms |
10092 KB |
Output is correct |
28 |
Correct |
50 ms |
10476 KB |
Output is correct |
29 |
Correct |
98 ms |
10080 KB |
Output is correct |
30 |
Correct |
105 ms |
10348 KB |
Output is correct |
31 |
Correct |
37 ms |
9836 KB |
Output is correct |
32 |
Correct |
4 ms |
5100 KB |
Output is correct |
33 |
Correct |
28 ms |
7652 KB |
Output is correct |
34 |
Correct |
46 ms |
10212 KB |
Output is correct |
35 |
Correct |
9 ms |
5612 KB |
Output is correct |
36 |
Correct |
30 ms |
8300 KB |
Output is correct |
37 |
Correct |
38 ms |
9196 KB |
Output is correct |
38 |
Correct |
47 ms |
10220 KB |
Output is correct |
39 |
Correct |
21 ms |
7020 KB |
Output is correct |
40 |
Correct |
5 ms |
5228 KB |
Output is correct |
41 |
Correct |
203 ms |
12140 KB |
Output is correct |
42 |
Correct |
93 ms |
12780 KB |
Output is correct |
43 |
Correct |
126 ms |
12012 KB |
Output is correct |
44 |
Correct |
110 ms |
12652 KB |
Output is correct |
45 |
Correct |
83 ms |
13164 KB |
Output is correct |
46 |
Correct |
221 ms |
12780 KB |
Output is correct |
47 |
Correct |
81 ms |
12268 KB |
Output is correct |
48 |
Correct |
120 ms |
12396 KB |
Output is correct |
49 |
Correct |
86 ms |
12268 KB |
Output is correct |
50 |
Correct |
848 ms |
12524 KB |
Output is correct |
51 |
Correct |
974 ms |
12780 KB |
Output is correct |
52 |
Correct |
805 ms |
12396 KB |
Output is correct |
53 |
Correct |
910 ms |
12908 KB |
Output is correct |
54 |
Correct |
767 ms |
12396 KB |
Output is correct |
55 |
Correct |
880 ms |
13036 KB |
Output is correct |
56 |
Correct |
788 ms |
12140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
54 ms |
10220 KB |
Output is correct |
10 |
Correct |
13 ms |
6380 KB |
Output is correct |
11 |
Correct |
41 ms |
8684 KB |
Output is correct |
12 |
Correct |
32 ms |
8044 KB |
Output is correct |
13 |
Correct |
47 ms |
9580 KB |
Output is correct |
14 |
Correct |
27 ms |
8044 KB |
Output is correct |
15 |
Correct |
9 ms |
5740 KB |
Output is correct |
16 |
Correct |
41 ms |
8044 KB |
Output is correct |
17 |
Correct |
63 ms |
11628 KB |
Output is correct |
18 |
Correct |
37 ms |
8940 KB |
Output is correct |
19 |
Correct |
5 ms |
5100 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
4 ms |
5100 KB |
Output is correct |
22 |
Correct |
4 ms |
5100 KB |
Output is correct |
23 |
Correct |
4 ms |
5120 KB |
Output is correct |
24 |
Correct |
4 ms |
5100 KB |
Output is correct |
25 |
Correct |
4 ms |
5100 KB |
Output is correct |
26 |
Correct |
4 ms |
5100 KB |
Output is correct |
27 |
Correct |
5 ms |
5100 KB |
Output is correct |
28 |
Correct |
4 ms |
5100 KB |
Output is correct |
29 |
Correct |
4 ms |
5100 KB |
Output is correct |
30 |
Correct |
4 ms |
5100 KB |
Output is correct |
31 |
Correct |
4 ms |
5100 KB |
Output is correct |
32 |
Correct |
4 ms |
5100 KB |
Output is correct |
33 |
Correct |
4 ms |
5100 KB |
Output is correct |
34 |
Correct |
16 ms |
6636 KB |
Output is correct |
35 |
Correct |
39 ms |
10092 KB |
Output is correct |
36 |
Correct |
50 ms |
10476 KB |
Output is correct |
37 |
Correct |
98 ms |
10080 KB |
Output is correct |
38 |
Correct |
105 ms |
10348 KB |
Output is correct |
39 |
Correct |
37 ms |
9836 KB |
Output is correct |
40 |
Correct |
4 ms |
5100 KB |
Output is correct |
41 |
Correct |
28 ms |
7652 KB |
Output is correct |
42 |
Correct |
46 ms |
10212 KB |
Output is correct |
43 |
Correct |
9 ms |
5612 KB |
Output is correct |
44 |
Correct |
30 ms |
8300 KB |
Output is correct |
45 |
Correct |
38 ms |
9196 KB |
Output is correct |
46 |
Correct |
47 ms |
10220 KB |
Output is correct |
47 |
Correct |
21 ms |
7020 KB |
Output is correct |
48 |
Correct |
5 ms |
5228 KB |
Output is correct |
49 |
Correct |
203 ms |
12140 KB |
Output is correct |
50 |
Correct |
93 ms |
12780 KB |
Output is correct |
51 |
Correct |
126 ms |
12012 KB |
Output is correct |
52 |
Correct |
110 ms |
12652 KB |
Output is correct |
53 |
Correct |
83 ms |
13164 KB |
Output is correct |
54 |
Correct |
221 ms |
12780 KB |
Output is correct |
55 |
Correct |
81 ms |
12268 KB |
Output is correct |
56 |
Correct |
120 ms |
12396 KB |
Output is correct |
57 |
Correct |
86 ms |
12268 KB |
Output is correct |
58 |
Correct |
848 ms |
12524 KB |
Output is correct |
59 |
Correct |
974 ms |
12780 KB |
Output is correct |
60 |
Correct |
805 ms |
12396 KB |
Output is correct |
61 |
Correct |
910 ms |
12908 KB |
Output is correct |
62 |
Correct |
767 ms |
12396 KB |
Output is correct |
63 |
Correct |
880 ms |
13036 KB |
Output is correct |
64 |
Correct |
788 ms |
12140 KB |
Output is correct |
65 |
Correct |
4 ms |
5100 KB |
Output is correct |
66 |
Correct |
3 ms |
5100 KB |
Output is correct |
67 |
Incorrect |
721 ms |
12012 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |