Created
February 16, 2015 14:18
-
-
Save akouryy/f1e83ed7102ee833389c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define times(n, i) uptil(0, n, i) | |
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i <= _##i; i++) | |
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i < _##i; i++) | |
#define downto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i >= _##i; i--) | |
#define downtil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i > _##i; i--) | |
#define unless(c) if(!(c)) | |
#define until(c) while(!(c)) | |
#define loop while(true) | |
int main(){ | |
int L, N; | |
scanf("%d %d", &L, &N); | |
vector<int> s0, s1, b0, b1; // /:s \:b | |
times(N, i){ | |
int X, Y; | |
scanf("%d %d", &X, &Y); | |
if(X % 2 == Y % 2){ | |
s0.push_back(X - Y); | |
b0.push_back(X + Y - (L - 1)); | |
}else{ | |
s1.push_back(X - Y); | |
b1.push_back(X + Y - (L - 1)); | |
} | |
} | |
#define unique_sort(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()) | |
unique_sort(s0); | |
unique_sort(s1); | |
unique_sort(b0); | |
unique_sort(b1); | |
long long ans = 0; | |
times(s0.size(), i){ | |
ans += L - abs(s0[i]); | |
} | |
times(b0.size(), i){ | |
ans += L - abs(b0[i]) - distance(upper_bound(s0.begin(), s0.end(), -L + abs(b0[i])), | |
lower_bound(s0.begin(), s0.end(), L - abs(b0[i]))); | |
} | |
times(s1.size(), i){ | |
ans += L - abs(s1[i]); | |
} | |
times(b1.size(), i){ | |
ans += L - abs(b1[i]) - distance(upper_bound(s1.begin(), s1.end(), -L + abs(b1[i])), | |
lower_bound(s1.begin(), s1.end(), L - abs(b1[i]))); | |
} | |
printf("%lld\n", ans); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment