#include<bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
struct eventhelp{
long long t;
long long l, r;
long long val;
long long type;
};
void add_int(long long l, long long r, long long val, long long &cnti, long long &cntp){
long long pare, impare;
long long dst = r - l + 1;
pare = dst/2;
impare = dst/2;
if(dst%2 == 1){
if(l%2 == 0)
pare++;
else
impare++;
}
cnti += 1LL * impare * val;
cntp += 1LL * pare * val;
}
vector<eventhelp> ev;
long long ans = LLONG_MAX;
long long n;
bool cmpev(eventhelp a, eventhelp b){
if(a.t == b.t)
return a.type > b.type;
return a.t < b.t;
}
long long imp[N], pr[N];
void solve(long long len){
vector<eventhelp> evc = ev;
for(long long i=len; i<=n;i+=len){
evc.push_back({i, 0, 0, 0});
}
inplace_merge(evc.begin(), evc.begin() + ev.size(), evc.end(), cmpev);
long long sumi = 0, acti = 0, sump = 0, actp = 0;
for(auto e:evc){
if(e.type != 0){
long long fgroup = (e.l - 1)/len + 1;
long long lgroup = (e.r - 1)/len + 1;
if(fgroup + 1 <= lgroup - 1){
add_int(fgroup, lgroup, 1LL* e.val * len, sumi, sump);
add_int(fgroup, lgroup, 1LL* e.type * len, acti, actp);
}
if(fgroup != lgroup){
add_int(fgroup, fgroup, 1LL * e.val * (fgroup*len - e.l + 1), sumi, sump);
add_int(fgroup, fgroup, 1LL * e.type * (fgroup*len - e.l + 1), acti, actp);
add_int(lgroup, lgroup, 1LL * e.val * (e.r - (lgroup - 1)*len), sumi, sump);
add_int(lgroup, lgroup, 1LL * e.type * (e.r - (lgroup - 1)*len), acti, actp);
}
if(fgroup == lgroup){
add_int(fgroup, fgroup, 1LL * e.val * (e.r - e.l + 1), sumi, sump);
add_int(fgroup, fgroup, 1LL * e.type * (e.r - e.l + 1), acti, actp);
}
}
else{
long long csumi, csump;
csumi = sumi - acti * (n - e.t);
csump = sump - actp * (n - e.t);
imp[e.t/len] = csumi;
pr[e.t/len] =csump;
}
}
long long fans = 0, sans = 0;
for(long long i = 1; i<=n/len;i++){
long long ci, cp;
ci = imp[i] - imp[i-1];
cp = pr[i] - pr[i -1];
long long nrp = (n/len)/2, nri = n/len - nrp;
if(i %2 == 1){
fans += 1LL*len*len*nri - ci + cp;
sans += 1LL*len*len*nrp - cp + ci;
}
else{
sans += 1LL*len*len*nri - ci + cp;
fans += 1LL*len*len*nrp - cp + ci;
}
}
ans = min(ans, sans);
ans = min(ans, fans);
}
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
long long k;
cin>>n>>k;
for(long long i=1;i<=k;i++){
long long x1, y1, x2, y2;
cin>>x1>>y1>>x2>>y2;
ev.push_back({x1, y1, y2, n - x1 + 1, 1});
ev.push_back({x2, y1, y2,-(n - x2), -1});
}
sort(ev.begin(), ev.end(), cmpev);
for(long long d = 1; d<n; d++){
if(n%d == 0)
solve(d);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 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 |
Correct |
71 ms |
15188 KB |
Output is correct |
2 |
Correct |
18 ms |
4316 KB |
Output is correct |
3 |
Correct |
52 ms |
15824 KB |
Output is correct |
4 |
Correct |
46 ms |
11220 KB |
Output is correct |
5 |
Correct |
62 ms |
13488 KB |
Output is correct |
6 |
Correct |
46 ms |
9784 KB |
Output is correct |
7 |
Correct |
12 ms |
3364 KB |
Output is correct |
8 |
Correct |
42 ms |
9768 KB |
Output is correct |
9 |
Correct |
101 ms |
21700 KB |
Output is correct |
10 |
Correct |
56 ms |
12244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
552 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
552 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
32 ms |
6896 KB |
Output is correct |
17 |
Correct |
82 ms |
20316 KB |
Output is correct |
18 |
Correct |
121 ms |
23748 KB |
Output is correct |
19 |
Correct |
403 ms |
21304 KB |
Output is correct |
20 |
Correct |
437 ms |
23864 KB |
Output is correct |
21 |
Correct |
79 ms |
19524 KB |
Output is correct |
22 |
Correct |
1 ms |
620 KB |
Output is correct |
23 |
Correct |
77 ms |
10456 KB |
Output is correct |
24 |
Correct |
109 ms |
21628 KB |
Output is correct |
25 |
Correct |
14 ms |
2420 KB |
Output is correct |
26 |
Correct |
68 ms |
13780 KB |
Output is correct |
27 |
Correct |
101 ms |
16456 KB |
Output is correct |
28 |
Correct |
115 ms |
22896 KB |
Output is correct |
29 |
Correct |
39 ms |
8280 KB |
Output is correct |
30 |
Correct |
4 ms |
1076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
15188 KB |
Output is correct |
2 |
Correct |
18 ms |
4316 KB |
Output is correct |
3 |
Correct |
52 ms |
15824 KB |
Output is correct |
4 |
Correct |
46 ms |
11220 KB |
Output is correct |
5 |
Correct |
62 ms |
13488 KB |
Output is correct |
6 |
Correct |
46 ms |
9784 KB |
Output is correct |
7 |
Correct |
12 ms |
3364 KB |
Output is correct |
8 |
Correct |
42 ms |
9768 KB |
Output is correct |
9 |
Correct |
101 ms |
21700 KB |
Output is correct |
10 |
Correct |
56 ms |
12244 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
552 KB |
Output is correct |
24 |
Correct |
1 ms |
620 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
32 ms |
6896 KB |
Output is correct |
27 |
Correct |
82 ms |
20316 KB |
Output is correct |
28 |
Correct |
121 ms |
23748 KB |
Output is correct |
29 |
Correct |
403 ms |
21304 KB |
Output is correct |
30 |
Correct |
437 ms |
23864 KB |
Output is correct |
31 |
Correct |
79 ms |
19524 KB |
Output is correct |
32 |
Correct |
1 ms |
620 KB |
Output is correct |
33 |
Correct |
77 ms |
10456 KB |
Output is correct |
34 |
Correct |
109 ms |
21628 KB |
Output is correct |
35 |
Correct |
14 ms |
2420 KB |
Output is correct |
36 |
Correct |
68 ms |
13780 KB |
Output is correct |
37 |
Correct |
101 ms |
16456 KB |
Output is correct |
38 |
Correct |
115 ms |
22896 KB |
Output is correct |
39 |
Correct |
39 ms |
8280 KB |
Output is correct |
40 |
Correct |
4 ms |
1076 KB |
Output is correct |
41 |
Correct |
373 ms |
25284 KB |
Output is correct |
42 |
Correct |
137 ms |
24480 KB |
Output is correct |
43 |
Correct |
217 ms |
24052 KB |
Output is correct |
44 |
Correct |
135 ms |
25892 KB |
Output is correct |
45 |
Correct |
114 ms |
23656 KB |
Output is correct |
46 |
Correct |
400 ms |
27584 KB |
Output is correct |
47 |
Correct |
103 ms |
21668 KB |
Output is correct |
48 |
Correct |
178 ms |
23520 KB |
Output is correct |
49 |
Correct |
126 ms |
22276 KB |
Output is correct |
50 |
Correct |
1691 ms |
26228 KB |
Output is correct |
51 |
Correct |
1752 ms |
27596 KB |
Output is correct |
52 |
Correct |
1662 ms |
26080 KB |
Output is correct |
53 |
Correct |
1768 ms |
27552 KB |
Output is correct |
54 |
Correct |
1636 ms |
25776 KB |
Output is correct |
55 |
Correct |
1825 ms |
28392 KB |
Output is correct |
56 |
Correct |
1610 ms |
25168 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 |
0 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 |
71 ms |
15188 KB |
Output is correct |
10 |
Correct |
18 ms |
4316 KB |
Output is correct |
11 |
Correct |
52 ms |
15824 KB |
Output is correct |
12 |
Correct |
46 ms |
11220 KB |
Output is correct |
13 |
Correct |
62 ms |
13488 KB |
Output is correct |
14 |
Correct |
46 ms |
9784 KB |
Output is correct |
15 |
Correct |
12 ms |
3364 KB |
Output is correct |
16 |
Correct |
42 ms |
9768 KB |
Output is correct |
17 |
Correct |
101 ms |
21700 KB |
Output is correct |
18 |
Correct |
56 ms |
12244 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
620 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
552 KB |
Output is correct |
32 |
Correct |
1 ms |
620 KB |
Output is correct |
33 |
Correct |
2 ms |
620 KB |
Output is correct |
34 |
Correct |
32 ms |
6896 KB |
Output is correct |
35 |
Correct |
82 ms |
20316 KB |
Output is correct |
36 |
Correct |
121 ms |
23748 KB |
Output is correct |
37 |
Correct |
403 ms |
21304 KB |
Output is correct |
38 |
Correct |
437 ms |
23864 KB |
Output is correct |
39 |
Correct |
79 ms |
19524 KB |
Output is correct |
40 |
Correct |
1 ms |
620 KB |
Output is correct |
41 |
Correct |
77 ms |
10456 KB |
Output is correct |
42 |
Correct |
109 ms |
21628 KB |
Output is correct |
43 |
Correct |
14 ms |
2420 KB |
Output is correct |
44 |
Correct |
68 ms |
13780 KB |
Output is correct |
45 |
Correct |
101 ms |
16456 KB |
Output is correct |
46 |
Correct |
115 ms |
22896 KB |
Output is correct |
47 |
Correct |
39 ms |
8280 KB |
Output is correct |
48 |
Correct |
4 ms |
1076 KB |
Output is correct |
49 |
Correct |
373 ms |
25284 KB |
Output is correct |
50 |
Correct |
137 ms |
24480 KB |
Output is correct |
51 |
Correct |
217 ms |
24052 KB |
Output is correct |
52 |
Correct |
135 ms |
25892 KB |
Output is correct |
53 |
Correct |
114 ms |
23656 KB |
Output is correct |
54 |
Correct |
400 ms |
27584 KB |
Output is correct |
55 |
Correct |
103 ms |
21668 KB |
Output is correct |
56 |
Correct |
178 ms |
23520 KB |
Output is correct |
57 |
Correct |
126 ms |
22276 KB |
Output is correct |
58 |
Correct |
1691 ms |
26228 KB |
Output is correct |
59 |
Correct |
1752 ms |
27596 KB |
Output is correct |
60 |
Correct |
1662 ms |
26080 KB |
Output is correct |
61 |
Correct |
1768 ms |
27552 KB |
Output is correct |
62 |
Correct |
1636 ms |
25776 KB |
Output is correct |
63 |
Correct |
1825 ms |
28392 KB |
Output is correct |
64 |
Correct |
1610 ms |
25168 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
1 ms |
364 KB |
Output is correct |
67 |
Incorrect |
1791 ms |
26976 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |