def extract_types(elements, annotation):
    """
    Extracts the types of the identified diagram elements.

    Parameters:
        elements: A list of diagram elements.
        annotation: A dictionary of AI2D annotation.

    Returns:
         A dictionary with element types as keys and identifiers as values.
    """
    # Check for correct input type
    assert isinstance(elements, list)
    assert isinstance(annotation, dict)

    # Define the target categories for various diagram elements
    targets = ['arrowHeads', 'arrows', 'blobs', 'text', 'containers',
               'imageConsts']

    # Create a dictionary for holding element types
    element_types = {}

    # Loop over the diagram elements
    for e in elements:

        try:
            # Search for matches in the target categories
            for t in targets:

                # Get the identifiers for each element category
                ids = [i for i in annotation[t].keys()]

                # If the element is found among the identifiers, add the
                # type to the dictionary
                if e in ids:
                    element_types[e] = t

        # Skip if the category is not found
        except KeyError:
            continue

    # Return the element type dictionary
    return element_types