#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define z return 0;
using namespace std;
const int N = 1e5 + 5, inf = 1e9 + 1; //
int main(){
ios::sync_with_stdio(0), cin.tie(0);
int n, k;
cin >> n >> k;
int a[k], b[k], c[k], d[k];
for (int i = 0; i < k; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
ll ans = inf;
for (int l = 1; l < n; l++){
if (n % l) continue;
int l2 = n / l;
ll tmp = 1ll * l * l * (1ll * l2 * l2 / 2), tmp2 = tmp + 1ll * l * l * (l2 % 2);
swap(tmp, tmp2);
int d0[n + 2]{}, d1[n + 2]{}, pre[n + 1]{};
for (int i = 1; i <= n; i++){
pre[i] = pre[i - 1] + (i % (l * 2) > 0 and i % (l * 2) <= l);
}
for (int i = 0; i < k; i++){
int p = pre[c[i]] - pre[a[i] - 1], p2 = c[i] - a[i] + 1 - p;
d0[b[i]] += p;
d0[d[i] + 1] -= p;
d1[b[i]] += p2;
d1[d[i] + 1] -= p2;
}
ll pre0 = 0, pre1 = 0;
for (int i = 1; i <= n; i++){
pre0 += d0[i], pre1 += d1[i];
if (i % (l * 2) > 0 and i % (l * 2) <= l){
tmp += pre1 - pre0;
tmp2 += pre0 - pre1;
}
else{
tmp2 += pre1 - pre0;
tmp += pre0 - pre1;
}
}
ans = min({ans, tmp, tmp2});
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
2028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
10 ms |
1260 KB |
Output is correct |
17 |
Correct |
26 ms |
3052 KB |
Output is correct |
18 |
Correct |
33 ms |
3436 KB |
Output is correct |
19 |
Correct |
53 ms |
3180 KB |
Output is correct |
20 |
Correct |
48 ms |
3436 KB |
Output is correct |
21 |
Correct |
26 ms |
2924 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
15 ms |
1644 KB |
Output is correct |
24 |
Correct |
32 ms |
3180 KB |
Output is correct |
25 |
Correct |
4 ms |
620 KB |
Output is correct |
26 |
Correct |
19 ms |
2156 KB |
Output is correct |
27 |
Correct |
25 ms |
2668 KB |
Output is correct |
28 |
Correct |
30 ms |
3440 KB |
Output is correct |
29 |
Correct |
11 ms |
1388 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
2028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Incorrect |
25 ms |
2028 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |