Distinct

题目描述

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);
    }   
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值