题目描述
Alice has an array a of n integers. You are told some facts about the array: for every two elements ai and aj in the subarray al..r (l≤i<j≤r),ai ≠aj holds.
You need find a array with minimum number of distinct integers which meets the facts.
输入
There are multiple test cases. The first line of input contains an integerT indicating the number of test cases. For each test case:
The first line contains two integers n and m(1 ≤n≤ 109, 0 ≤m≤ 105). The next m lines, each contains two integers li and ri(1 ≤li ≤ri ≤n).
输出
For each test cases, output an integer denoting the answer.
样例输入
3 3 1 1 1 6 3 2 3 4 6 3 6 5 3 4 5 2 2 3 3
样例输出
1 4 2
提示
Possible solution for the samples: {1, 1, 1}, {3, 3, 2, 3, 1, 4}, {1, 1, 1, 1, 2}
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1e5+5;
int main()
{
int T;
scanf("%d",&T);
while(T--){
int n,m;
int cnt=0;
int a,b;
// memset(c,0,sizeof(c));
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
scanf("%d%d",&a,&b);
if(cnt<(b-a+1)){
cnt=b-a+1;
}
}
if(m==0){
cnt=1;
}
printf("%d\n",cnt);
}
}