아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Two covers

시간 제한3초메모리 제한1024 MB

요약
수퍼스트링에 정렬된 조각들과 k가 주어질 때, x-k부터 덮는 조각과 x+k까지 덮는 다른 조각이 모두 있는 위치가 아닌 곳의 개수를 센다.
난이도

보통10점 중 5점

유형
구간, 누적 합
정답자
아직 제출이 없습니다

문제

In a typical genome assembly problem, we are given set of small strings called pieces and our task is to find their superstring with some reasonable properties. In this problem, you are given one such superstring and a collection of pieces aligned to that superstring. Your task is to evaluate one particular property.

You are given the length of the superstring ℓ, a list of n pieces, and a number k. The positions in the superstring are numbered from 1 to ℓ. For each piece i you are given the positions (b**i, e**i) of its beginning and end.

The letter at position x in the superstring is well-covered if:

  • There is a piece (b**i, e**i) such that b**i ≤ x − k and x ≤ e**i.
  • There is a different piece (b**j, e**j) such that b**j ≤ x and x + k ≤ e**j.

Your task is to count the number of letters which are not well-covered.

입력

The first line of the input file contains an integer t specifying the number of test cases. Each test case is preceded by a blank line.

Each test case starts with a line containing three integers: ℓ, n, and k. Each of the following n lines contains two integers b**i and e**i (1 ≤ b**i ≤ e**i ≤ ℓ): the indices of the endpoints of a piece. The pairs (b**i, e**i) are all distinct.

출력

For each test case, output a single line with a single integer – the number of letters that are not well-covered.

힌트

The well-covered letters are at positions 3, 4, and 5. Note that the letter at position 6 is not well-covered.

예제1

  1. 예제 1

    입력
    1
    
    8 3 2
    1 4
    3 5
    4 8
    
    예상 출력
    5