long long is not really necessary
Posted by
ASK 17 Nov 2010 21:21
unsigned is enough:
template <typename T, typename G>
void psort(T& a, T& b, T& c, T& d, G gt){
if(gt(a, b)) swap(a, b);
if(gt(c, d)) swap(c, d);
if(gt(a, c)){ swap(a, c); swap(b, d); }
}
inline unsigned intersection_length(int a, int b, int c, int d){
psort(a, b, c, d, greater<int>());
if(c > b){ cout << 0 << endl; exit(0); }
return min(b, d) - c;
}