예제 #1
0
// Give the duration of the interval between begin and end in seconds
long long int duration(const int* begin, const int* end)
{
	int b[6];
	int e[6];

	// Fill in missing values appropriately
	upperbound(begin, b);
	lowerbound(end, e);

	// Lowerbound both where both had -1
	for (int i = 0; i < 6; ++i)
		if (begin[i] == -1 && end[i] == -1)
			b[i] = e[i] = (i == 1 || i == 2) ? 1 : 0;

	// Find the smaller year, to use as a reference for secondsfrom
	int y = b[0] < e[0] ? b[0] : e[0];
	return secondsfrom(y, e) - secondsfrom(y, b);
}
 vector<int> searchRange(int A[], int n, int target) {
     int start = lowerbound(A, n, target);
     int end = upperbound(A, n, target);
     if (start != -1) {
         if (A[start] != target)
             start = -1;
     }
     if (end == -1) {
         if (A[n-1] == target)
             end = n-1;
     } else {
         if (A[end-1] == target)
             end--;
         else
             end = -1;
     }
     vector<int> result(2);
     result[0] = start;
     result[1] = end;
     return result;
 }