#include <iostream>
#include <cstdio>
using namespace std;
#define m_p make_pair
const int N = 100005;
struct ban
{
long long x, y;
ban(){}
ban(long long x, long long y)
{
this->x = x;
this->y = y;
}
};
long long n;
int m;
pair<ban, ban> a[N];
bool sevv(long long x, long long y, long long t)
{
x = x / t;
y = y / t;
if ((x + y) % 2 == 0)
return true;
else
return false;
}
long long sev(const pair<ban, ban>& a, long long t)
{
long long x1 = a.first.x;
long long y1 = a.first.y;
long long x2 = a.second.x;
long long y2 = a.second.y;
if (x1 == 0 && y1 == 1 && x2 == 0 && y2 == 1 && t == 3)
cout << "";
long long xm1 = (x1 / t + 1) * t;
if (x1 % t == 0)
xm1 = x1;
long long xm2 = (x2 / t) * t - 1;
if (x2 % t == t - 1)
xm2 = x2;
long long ym1 = (y1 / t + 1) * t;
if (y1 % t == 0)
ym1 = y1;
long long ym2 = (y2 / t) * t - 1;
if (y2 % t == t - 1)
ym2 = y2;
long long ans = 0;
long long xx = 0;
if (xm1 - xm2 == t + 1)
{
if (sevv(x1, y1, t))
xx = (x2 - x1 + 1);
goto kovx;
}
// x1; xm1 - 1
if (sevv(x1, y1, t))
xx += (xm1 - x1);
// xm1; xm2
if (sevv(xm1, y1, t))
xx += ((((xm2 - xm1 + 1) / t) / 2) * t);
else
xx += ((((xm2 - xm1 + 1) / t) - (((xm2 - xm1 + 1) / t) / 2)) * t);
// xm2 + 1; x2
if (sevv(xm2 + 1, y1, t))
xx += (x2 - xm2);
kovx:
if (ym1 - ym2 == t + 1)
{
ans = (xx * (y2 - y1 + 1));
goto kovy;
}
// y1; ym1 - 1
if (sevv(x1, y1, t))
ans += ((ym1 - y1) * xx);
// ym1; ym2
ans += ((((ym2 - ym1 + 1) / t) / 2) * xx * t);
ans += ((((ym2 - ym1 + 1) / t) - (((ym2 - ym1 + 1) / t) / 2)) * ((x2 - x1 + 1) - xx) * t);
// ym2 + 1; y2
if (sevv(x1, y1, t) == sevv(x1, y2, t))
ans += ((y2 - ym2) * xx);
else
ans += ((y2 - ym2) * ((x2 - x1 + 1) - xx));
kovy:
return ans;
}
long long spi(const pair<ban, ban>& a, long long t)
{
long long x1 = a.first.x;
long long y1 = a.first.y;
long long x2 = a.second.x;
long long y2 = a.second.y;
return (x2 - x1 + 1) * (y2 - y1 + 1) - sev(a, t);
}
long long ans;
void stg(long long t)
{
if (t == 3)
cout << "";
long long yans = 0;
long long g = 0;
for (int i = 0; i < m; ++i)
{
yans += (spi(a[i], t));
g += (sev(a[i], t));
}
yans += (sev(m_p(ban(0, 0), ban(n - 1, n - 1)), t) - g);
ans = min(ans, yans);
}
int main()
{
//freopen("input2.txt", "r", stdin);
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
cin >> a[i].first.x >> a[i].first.y >> a[i].second.x >> a[i].second.y;
--a[i].first.x;
--a[i].first.y;
--a[i].second.x;
--a[i].second.y;
}
ans = n * n;
for (long long i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
if (i != n)
stg(i);
if (n / i != n)
stg(n / i);
}
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
2296 KB |
Output is correct |
2 |
Incorrect |
22 ms |
888 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
2296 KB |
Output is correct |
2 |
Incorrect |
22 ms |
888 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |