```
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int left = 0, right = matrix.size(), mid;
while( left < right ) {
mid = (left + right)/2;
if( target < matrix[mid].front() ) {
right = mid;
} else if( target > matrix[mid].back()) {
left = mid+1;
} else break;
}
return *(lower_bound(matrix[mid].begin(), matrix[mid].end(), target )) == target;
}
```