#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<long long> vl;
typedef pair<long long, long long > pl;
const int N = 1e6 + 1;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 1e18
#define MIN -1e18
#define per(i,a,b) for(ll i=b;i>=a;i--)
#define con continue
#define freopen freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628
//typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
template< typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n, m, ans, mid, mn, mx, cnt, sum, h1, h2, arr[3234567],arr1[1234567], sz, k, i, j, h, a, w, x, y, z,par[1234567];
bool used[1234567];
ll dx[4]={-1,1,0,0},dy[4]={0,0,-1,1},c1[123][123];
vector<ll> edge[1234567];
ll jump[22][223456];
ll lvl[1234567];
//ll bit[1234567];
//ll timer;
//ll st[1234567],endd[1234567];
//ll dp[5005][5005];
ll power(ll base, ll val, ll mod) {
ll res = 1;
while (val) {
if (val % 2 == 1) {
res = res * base;
}
base = base * base;
base %= mod;
res %= mod;
val /= 2;
}
return res;
}
bool comp(pl x,pl y){
if(x.ff>y.ff)return true;
return false;
}
ll find(ll x){
if(x==par[x])return x;
else return par[x]=find(par[x]);
}
void process_LCA(){
for(int i=1;(1<<i)<=n;i++){
for(int j=1;j<=n;j++){
jump[i][j] = jump[i-1][jump[i-1][j]];
}
}
}
ll LCA(ll x,ll y){
if(lvl[x] < lvl[y])swap(x,y);
ll diss = lvl[x] - lvl[y];
for(int i=21;i>=0;i--){
if((1<<i)&diss){
x = jump[i][x];
}
}
if(x==y)return x;
for(int i=21;i>=0;i--){
if(jump[i][x] != jump[i][y]){
x = jump[i][x];
y = jump[i][y];
}
}
return jump[0][x];
}
ll find(ll x, ll d){
return x / (2 * d) * d + min(x % (2 * d), d);
}
class A {
public:
static void funcA(){
cin>>n>>k;
vl vec;
vec.pb(1);
for(ll i = 2; i * i <= n; i++){
if(n % i == 0){
vec.pb(i);
if(i * i != n) vec.pb(n / i);
}
}
ll dif[1234567];
for(ll i = 0; i < vec.size(); i++)
dif[i] = n * n - n * n / (vec[i] * vec[i]) / 2 * (vec[i] * vec[i]);
while(k--){
ll x1, x2, y1, y2;
cin>>x1>>y1>>x2>>y2;
x1--;
y1--;
for(ll i = 0; i < vec.size(); i++){
ll xx,x3,yy,y3;
xx = find(x2, vec[i]) - find(x1, vec[i]);
x3 = x2 - x1 - xx;
yy = find(y2, vec[i]) - find(y1, vec[i]);
y3 = y2 - y1 - yy;
dif[i] += xx * y3 + yy * x3 - xx * yy - x3 * y3;
}
}
ans=MAX;
for(int i=0;i<vec.size();i++){
ans=min(ans , min(dif[i],n*n-dif[i]));
}
cout<<ans;
}
}lol;
void solve() {
A::funcA();
}
int main() {
ll T = 1;
//cin>>T;
boost;
while (T--) {
solve();
}
}
Compilation message
chessboard.cpp: In static member function 'static void A::funcA()':
chessboard.cpp:100:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(ll i = 0; i < vec.size(); i++)
| ~~^~~~~~~~~~~~
chessboard.cpp:107:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for(ll i = 0; i < vec.size(); i++){
| ~~^~~~~~~~~~~~
chessboard.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for(int i=0;i<vec.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
38860 KB |
Output is correct |
2 |
Correct |
19 ms |
38960 KB |
Output is correct |
3 |
Correct |
19 ms |
38972 KB |
Output is correct |
4 |
Correct |
23 ms |
38936 KB |
Output is correct |
5 |
Correct |
19 ms |
38960 KB |
Output is correct |
6 |
Correct |
23 ms |
38856 KB |
Output is correct |
7 |
Correct |
19 ms |
38860 KB |
Output is correct |
8 |
Correct |
19 ms |
38952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
38860 KB |
Output is correct |
2 |
Correct |
36 ms |
39316 KB |
Output is correct |
3 |
Correct |
54 ms |
39856 KB |
Output is correct |
4 |
Correct |
53 ms |
39808 KB |
Output is correct |
5 |
Correct |
71 ms |
40240 KB |
Output is correct |
6 |
Correct |
60 ms |
39804 KB |
Output is correct |
7 |
Correct |
26 ms |
39076 KB |
Output is correct |
8 |
Correct |
51 ms |
39768 KB |
Output is correct |
9 |
Correct |
97 ms |
40988 KB |
Output is correct |
10 |
Correct |
64 ms |
40008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
38932 KB |
Output is correct |
2 |
Correct |
23 ms |
38860 KB |
Output is correct |
3 |
Correct |
23 ms |
38888 KB |
Output is correct |
4 |
Correct |
25 ms |
38860 KB |
Output is correct |
5 |
Correct |
20 ms |
38948 KB |
Output is correct |
6 |
Correct |
21 ms |
38972 KB |
Output is correct |
7 |
Correct |
19 ms |
38944 KB |
Output is correct |
8 |
Correct |
19 ms |
38964 KB |
Output is correct |
9 |
Correct |
19 ms |
38860 KB |
Output is correct |
10 |
Correct |
19 ms |
38860 KB |
Output is correct |
11 |
Correct |
20 ms |
38860 KB |
Output is correct |
12 |
Correct |
18 ms |
38860 KB |
Output is correct |
13 |
Correct |
19 ms |
38944 KB |
Output is correct |
14 |
Correct |
19 ms |
38912 KB |
Output is correct |
15 |
Correct |
20 ms |
38972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
38932 KB |
Output is correct |
2 |
Correct |
23 ms |
38860 KB |
Output is correct |
3 |
Correct |
23 ms |
38888 KB |
Output is correct |
4 |
Correct |
25 ms |
38860 KB |
Output is correct |
5 |
Correct |
20 ms |
38948 KB |
Output is correct |
6 |
Correct |
21 ms |
38972 KB |
Output is correct |
7 |
Correct |
19 ms |
38944 KB |
Output is correct |
8 |
Correct |
19 ms |
38964 KB |
Output is correct |
9 |
Correct |
19 ms |
38860 KB |
Output is correct |
10 |
Correct |
19 ms |
38860 KB |
Output is correct |
11 |
Correct |
20 ms |
38860 KB |
Output is correct |
12 |
Correct |
18 ms |
38860 KB |
Output is correct |
13 |
Correct |
19 ms |
38944 KB |
Output is correct |
14 |
Correct |
19 ms |
38912 KB |
Output is correct |
15 |
Correct |
20 ms |
38972 KB |
Output is correct |
16 |
Correct |
41 ms |
39388 KB |
Output is correct |
17 |
Correct |
75 ms |
40264 KB |
Output is correct |
18 |
Correct |
104 ms |
40464 KB |
Output is correct |
19 |
Correct |
126 ms |
40356 KB |
Output is correct |
20 |
Correct |
139 ms |
40596 KB |
Output is correct |
21 |
Correct |
72 ms |
40232 KB |
Output is correct |
22 |
Correct |
19 ms |
38856 KB |
Output is correct |
23 |
Correct |
56 ms |
39568 KB |
Output is correct |
24 |
Correct |
83 ms |
40336 KB |
Output is correct |
25 |
Correct |
26 ms |
39084 KB |
Output is correct |
26 |
Correct |
61 ms |
39832 KB |
Output is correct |
27 |
Correct |
71 ms |
39956 KB |
Output is correct |
28 |
Correct |
87 ms |
40408 KB |
Output is correct |
29 |
Correct |
42 ms |
39484 KB |
Output is correct |
30 |
Correct |
20 ms |
38988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
38860 KB |
Output is correct |
2 |
Correct |
36 ms |
39316 KB |
Output is correct |
3 |
Correct |
54 ms |
39856 KB |
Output is correct |
4 |
Correct |
53 ms |
39808 KB |
Output is correct |
5 |
Correct |
71 ms |
40240 KB |
Output is correct |
6 |
Correct |
60 ms |
39804 KB |
Output is correct |
7 |
Correct |
26 ms |
39076 KB |
Output is correct |
8 |
Correct |
51 ms |
39768 KB |
Output is correct |
9 |
Correct |
97 ms |
40988 KB |
Output is correct |
10 |
Correct |
64 ms |
40008 KB |
Output is correct |
11 |
Correct |
23 ms |
38932 KB |
Output is correct |
12 |
Correct |
23 ms |
38860 KB |
Output is correct |
13 |
Correct |
23 ms |
38888 KB |
Output is correct |
14 |
Correct |
25 ms |
38860 KB |
Output is correct |
15 |
Correct |
20 ms |
38948 KB |
Output is correct |
16 |
Correct |
21 ms |
38972 KB |
Output is correct |
17 |
Correct |
19 ms |
38944 KB |
Output is correct |
18 |
Correct |
19 ms |
38964 KB |
Output is correct |
19 |
Correct |
19 ms |
38860 KB |
Output is correct |
20 |
Correct |
19 ms |
38860 KB |
Output is correct |
21 |
Correct |
20 ms |
38860 KB |
Output is correct |
22 |
Correct |
18 ms |
38860 KB |
Output is correct |
23 |
Correct |
19 ms |
38944 KB |
Output is correct |
24 |
Correct |
19 ms |
38912 KB |
Output is correct |
25 |
Correct |
20 ms |
38972 KB |
Output is correct |
26 |
Correct |
41 ms |
39388 KB |
Output is correct |
27 |
Correct |
75 ms |
40264 KB |
Output is correct |
28 |
Correct |
104 ms |
40464 KB |
Output is correct |
29 |
Correct |
126 ms |
40356 KB |
Output is correct |
30 |
Correct |
139 ms |
40596 KB |
Output is correct |
31 |
Correct |
72 ms |
40232 KB |
Output is correct |
32 |
Correct |
19 ms |
38856 KB |
Output is correct |
33 |
Correct |
56 ms |
39568 KB |
Output is correct |
34 |
Correct |
83 ms |
40336 KB |
Output is correct |
35 |
Correct |
26 ms |
39084 KB |
Output is correct |
36 |
Correct |
61 ms |
39832 KB |
Output is correct |
37 |
Correct |
71 ms |
39956 KB |
Output is correct |
38 |
Correct |
87 ms |
40408 KB |
Output is correct |
39 |
Correct |
42 ms |
39484 KB |
Output is correct |
40 |
Correct |
20 ms |
38988 KB |
Output is correct |
41 |
Correct |
133 ms |
40848 KB |
Output is correct |
42 |
Correct |
110 ms |
41092 KB |
Output is correct |
43 |
Correct |
113 ms |
40944 KB |
Output is correct |
44 |
Correct |
105 ms |
41096 KB |
Output is correct |
45 |
Correct |
107 ms |
41236 KB |
Output is correct |
46 |
Correct |
146 ms |
41156 KB |
Output is correct |
47 |
Correct |
105 ms |
41004 KB |
Output is correct |
48 |
Correct |
108 ms |
40980 KB |
Output is correct |
49 |
Correct |
101 ms |
40860 KB |
Output is correct |
50 |
Correct |
348 ms |
41028 KB |
Output is correct |
51 |
Correct |
373 ms |
41156 KB |
Output is correct |
52 |
Correct |
347 ms |
41000 KB |
Output is correct |
53 |
Correct |
368 ms |
41240 KB |
Output is correct |
54 |
Correct |
351 ms |
41028 KB |
Output is correct |
55 |
Correct |
379 ms |
41236 KB |
Output is correct |
56 |
Correct |
328 ms |
40980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
38860 KB |
Output is correct |
2 |
Correct |
19 ms |
38960 KB |
Output is correct |
3 |
Correct |
19 ms |
38972 KB |
Output is correct |
4 |
Correct |
23 ms |
38936 KB |
Output is correct |
5 |
Correct |
19 ms |
38960 KB |
Output is correct |
6 |
Correct |
23 ms |
38856 KB |
Output is correct |
7 |
Correct |
19 ms |
38860 KB |
Output is correct |
8 |
Correct |
19 ms |
38952 KB |
Output is correct |
9 |
Correct |
78 ms |
38860 KB |
Output is correct |
10 |
Correct |
36 ms |
39316 KB |
Output is correct |
11 |
Correct |
54 ms |
39856 KB |
Output is correct |
12 |
Correct |
53 ms |
39808 KB |
Output is correct |
13 |
Correct |
71 ms |
40240 KB |
Output is correct |
14 |
Correct |
60 ms |
39804 KB |
Output is correct |
15 |
Correct |
26 ms |
39076 KB |
Output is correct |
16 |
Correct |
51 ms |
39768 KB |
Output is correct |
17 |
Correct |
97 ms |
40988 KB |
Output is correct |
18 |
Correct |
64 ms |
40008 KB |
Output is correct |
19 |
Correct |
23 ms |
38932 KB |
Output is correct |
20 |
Correct |
23 ms |
38860 KB |
Output is correct |
21 |
Correct |
23 ms |
38888 KB |
Output is correct |
22 |
Correct |
25 ms |
38860 KB |
Output is correct |
23 |
Correct |
20 ms |
38948 KB |
Output is correct |
24 |
Correct |
21 ms |
38972 KB |
Output is correct |
25 |
Correct |
19 ms |
38944 KB |
Output is correct |
26 |
Correct |
19 ms |
38964 KB |
Output is correct |
27 |
Correct |
19 ms |
38860 KB |
Output is correct |
28 |
Correct |
19 ms |
38860 KB |
Output is correct |
29 |
Correct |
20 ms |
38860 KB |
Output is correct |
30 |
Correct |
18 ms |
38860 KB |
Output is correct |
31 |
Correct |
19 ms |
38944 KB |
Output is correct |
32 |
Correct |
19 ms |
38912 KB |
Output is correct |
33 |
Correct |
20 ms |
38972 KB |
Output is correct |
34 |
Correct |
41 ms |
39388 KB |
Output is correct |
35 |
Correct |
75 ms |
40264 KB |
Output is correct |
36 |
Correct |
104 ms |
40464 KB |
Output is correct |
37 |
Correct |
126 ms |
40356 KB |
Output is correct |
38 |
Correct |
139 ms |
40596 KB |
Output is correct |
39 |
Correct |
72 ms |
40232 KB |
Output is correct |
40 |
Correct |
19 ms |
38856 KB |
Output is correct |
41 |
Correct |
56 ms |
39568 KB |
Output is correct |
42 |
Correct |
83 ms |
40336 KB |
Output is correct |
43 |
Correct |
26 ms |
39084 KB |
Output is correct |
44 |
Correct |
61 ms |
39832 KB |
Output is correct |
45 |
Correct |
71 ms |
39956 KB |
Output is correct |
46 |
Correct |
87 ms |
40408 KB |
Output is correct |
47 |
Correct |
42 ms |
39484 KB |
Output is correct |
48 |
Correct |
20 ms |
38988 KB |
Output is correct |
49 |
Correct |
133 ms |
40848 KB |
Output is correct |
50 |
Correct |
110 ms |
41092 KB |
Output is correct |
51 |
Correct |
113 ms |
40944 KB |
Output is correct |
52 |
Correct |
105 ms |
41096 KB |
Output is correct |
53 |
Correct |
107 ms |
41236 KB |
Output is correct |
54 |
Correct |
146 ms |
41156 KB |
Output is correct |
55 |
Correct |
105 ms |
41004 KB |
Output is correct |
56 |
Correct |
108 ms |
40980 KB |
Output is correct |
57 |
Correct |
101 ms |
40860 KB |
Output is correct |
58 |
Correct |
348 ms |
41028 KB |
Output is correct |
59 |
Correct |
373 ms |
41156 KB |
Output is correct |
60 |
Correct |
347 ms |
41000 KB |
Output is correct |
61 |
Correct |
368 ms |
41240 KB |
Output is correct |
62 |
Correct |
351 ms |
41028 KB |
Output is correct |
63 |
Correct |
379 ms |
41236 KB |
Output is correct |
64 |
Correct |
328 ms |
40980 KB |
Output is correct |
65 |
Correct |
17 ms |
38948 KB |
Output is correct |
66 |
Correct |
19 ms |
38956 KB |
Output is correct |
67 |
Correct |
363 ms |
41108 KB |
Output is correct |
68 |
Correct |
358 ms |
41112 KB |
Output is correct |
69 |
Correct |
326 ms |
40856 KB |
Output is correct |
70 |
Correct |
355 ms |
41028 KB |
Output is correct |
71 |
Correct |
347 ms |
41008 KB |
Output is correct |
72 |
Correct |
352 ms |
41008 KB |
Output is correct |
73 |
Correct |
336 ms |
40972 KB |
Output is correct |
74 |
Correct |
360 ms |
41108 KB |
Output is correct |
75 |
Correct |
346 ms |
41072 KB |
Output is correct |
76 |
Correct |
378 ms |
41204 KB |
Output is correct |
77 |
Correct |
139 ms |
41228 KB |
Output is correct |
78 |
Correct |
106 ms |
40992 KB |
Output is correct |
79 |
Correct |
145 ms |
40848 KB |
Output is correct |
80 |
Correct |
122 ms |
41228 KB |
Output is correct |
81 |
Correct |
121 ms |
40860 KB |
Output is correct |
82 |
Correct |
122 ms |
41104 KB |
Output is correct |
83 |
Correct |
105 ms |
41012 KB |
Output is correct |
84 |
Correct |
257 ms |
41284 KB |
Output is correct |
85 |
Correct |
376 ms |
41232 KB |
Output is correct |
86 |
Correct |
18 ms |
38952 KB |
Output is correct |
87 |
Correct |
19 ms |
38952 KB |
Output is correct |
88 |
Correct |
393 ms |
41236 KB |
Output is correct |
89 |
Correct |
89 ms |
39364 KB |
Output is correct |
90 |
Correct |
17 ms |
38860 KB |
Output is correct |