#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,q;cin>>n>>q;
vector<int> v;
vector<int> a[2];
for(int i=1;i<n;i++){
if(n%i==0){
v.push_back(i);
int p=n/i;
if(p&1){
a[0].push_back((p*p-1)*i*i/2);
a[1].push_back((p*p+1)*i*i/2);
}
else{
a[0].push_back(n*n/2);
a[1].push_back(n*n/2);
}
}
}
int sz=v.size();
for(int i=0;i<q;i++){
int c,d;
cin>>c>>d>>c>>d;
c--;d--;
for(int j=0;j<sz;j++){
int k=v[j];
int c1=c/k;
int d1=d/k;
c1%=2;
d1%=2;
c1^=d1;
if(c1){
a[0][j]--;
a[1][j]++;
}
else{
a[0][j]++;
a[1][j]--;
}
}
}
int ans=n*n;
for(int j=0;j<sz;j++){
ans=min(ans,a[0][j]);
ans=min(ans,a[1][j]);
}
cout<<ans<<endl;
return 0;
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
456 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
1372 KB |
Output is correct |
4 |
Correct |
12 ms |
1116 KB |
Output is correct |
5 |
Correct |
15 ms |
1628 KB |
Output is correct |
6 |
Correct |
9 ms |
1116 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
9 ms |
1112 KB |
Output is correct |
9 |
Correct |
22 ms |
2480 KB |
Output is correct |
10 |
Correct |
13 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
6 ms |
348 KB |
Output is correct |
17 |
Correct |
17 ms |
456 KB |
Output is correct |
18 |
Correct |
22 ms |
452 KB |
Output is correct |
19 |
Correct |
47 ms |
436 KB |
Output is correct |
20 |
Correct |
53 ms |
428 KB |
Output is correct |
21 |
Correct |
16 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
12 ms |
348 KB |
Output is correct |
24 |
Correct |
20 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
460 KB |
Output is correct |
26 |
Correct |
17 ms |
348 KB |
Output is correct |
27 |
Correct |
20 ms |
460 KB |
Output is correct |
28 |
Correct |
26 ms |
456 KB |
Output is correct |
29 |
Correct |
8 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
456 KB |
Output is correct |
2 |
Correct |
4 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
1372 KB |
Output is correct |
4 |
Correct |
12 ms |
1116 KB |
Output is correct |
5 |
Correct |
15 ms |
1628 KB |
Output is correct |
6 |
Correct |
9 ms |
1116 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
9 ms |
1112 KB |
Output is correct |
9 |
Correct |
22 ms |
2480 KB |
Output is correct |
10 |
Correct |
13 ms |
1368 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
452 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
6 ms |
348 KB |
Output is correct |
27 |
Correct |
17 ms |
456 KB |
Output is correct |
28 |
Correct |
22 ms |
452 KB |
Output is correct |
29 |
Correct |
47 ms |
436 KB |
Output is correct |
30 |
Correct |
53 ms |
428 KB |
Output is correct |
31 |
Correct |
16 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
12 ms |
348 KB |
Output is correct |
34 |
Correct |
20 ms |
348 KB |
Output is correct |
35 |
Correct |
4 ms |
460 KB |
Output is correct |
36 |
Correct |
17 ms |
348 KB |
Output is correct |
37 |
Correct |
20 ms |
460 KB |
Output is correct |
38 |
Correct |
26 ms |
456 KB |
Output is correct |
39 |
Correct |
8 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
49 ms |
2352 KB |
Output is correct |
42 |
Correct |
26 ms |
2596 KB |
Output is correct |
43 |
Correct |
32 ms |
2384 KB |
Output is correct |
44 |
Correct |
31 ms |
2616 KB |
Output is correct |
45 |
Correct |
24 ms |
2652 KB |
Output is correct |
46 |
Correct |
52 ms |
2608 KB |
Output is correct |
47 |
Correct |
21 ms |
2388 KB |
Output is correct |
48 |
Correct |
31 ms |
2368 KB |
Output is correct |
49 |
Correct |
23 ms |
2352 KB |
Output is correct |
50 |
Correct |
186 ms |
2388 KB |
Output is correct |
51 |
Correct |
199 ms |
3252 KB |
Output is correct |
52 |
Correct |
186 ms |
2604 KB |
Output is correct |
53 |
Correct |
196 ms |
2608 KB |
Output is correct |
54 |
Correct |
182 ms |
2644 KB |
Output is correct |
55 |
Correct |
203 ms |
2644 KB |
Output is correct |
56 |
Correct |
177 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
15 ms |
456 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
10 ms |
1372 KB |
Output is correct |
12 |
Correct |
12 ms |
1116 KB |
Output is correct |
13 |
Correct |
15 ms |
1628 KB |
Output is correct |
14 |
Correct |
9 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
9 ms |
1112 KB |
Output is correct |
17 |
Correct |
22 ms |
2480 KB |
Output is correct |
18 |
Correct |
13 ms |
1368 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
452 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
6 ms |
348 KB |
Output is correct |
35 |
Correct |
17 ms |
456 KB |
Output is correct |
36 |
Correct |
22 ms |
452 KB |
Output is correct |
37 |
Correct |
47 ms |
436 KB |
Output is correct |
38 |
Correct |
53 ms |
428 KB |
Output is correct |
39 |
Correct |
16 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
12 ms |
348 KB |
Output is correct |
42 |
Correct |
20 ms |
348 KB |
Output is correct |
43 |
Correct |
4 ms |
460 KB |
Output is correct |
44 |
Correct |
17 ms |
348 KB |
Output is correct |
45 |
Correct |
20 ms |
460 KB |
Output is correct |
46 |
Correct |
26 ms |
456 KB |
Output is correct |
47 |
Correct |
8 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
49 ms |
2352 KB |
Output is correct |
50 |
Correct |
26 ms |
2596 KB |
Output is correct |
51 |
Correct |
32 ms |
2384 KB |
Output is correct |
52 |
Correct |
31 ms |
2616 KB |
Output is correct |
53 |
Correct |
24 ms |
2652 KB |
Output is correct |
54 |
Correct |
52 ms |
2608 KB |
Output is correct |
55 |
Correct |
21 ms |
2388 KB |
Output is correct |
56 |
Correct |
31 ms |
2368 KB |
Output is correct |
57 |
Correct |
23 ms |
2352 KB |
Output is correct |
58 |
Correct |
186 ms |
2388 KB |
Output is correct |
59 |
Correct |
199 ms |
3252 KB |
Output is correct |
60 |
Correct |
186 ms |
2604 KB |
Output is correct |
61 |
Correct |
196 ms |
2608 KB |
Output is correct |
62 |
Correct |
182 ms |
2644 KB |
Output is correct |
63 |
Correct |
203 ms |
2644 KB |
Output is correct |
64 |
Correct |
177 ms |
2384 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |