Could you explain what the following SQL query does (no step-by-step explanation is necessary)?
WITH sample(dt, v) AS (
    VALUES
    ('2023-05-01'::date, 'active'),
    ('2023-05-02', 'active'),
    ('2023-05-03', 'active'),
    ('2023-05-04', 'inactive'),
    ('2023-05-05', 'inactive'),
    ('2023-05-06', 'inactive'),
    ('2023-05-07', 'active'),
    ('2023-05-08', 'active'),
    ('2023-05-09', 'inactive')
), group_marks AS (
    SELECT *, NULLIF(v = LAG(v) OVER (ORDER BY dt), true) AS next_group
      FROM sample
), grps AS (
    SELECT *, COUNT(next_group) OVER (ORDER BY dt) AS group_num
      FROM group_marks
)
SELECT group_num, MIN(dt) AS min_date, MAX(dt) AS max_date
  FROM grps
 GROUP BY group_num
 ORDER BY group_num;