Distinct Values(不同价值)

题目链接
Problem Description
Chiaki has an array of n positive integers. You are told some facts about the array: for every two elements ai and aj in the subarray al..r (1≤i≤r,1≤j≤r,j>i), ai≠aj holds.
Chiaki would like to find a lexicographically minimal array which meets the facts.

Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains two integers n and m (1≤n,m≤105) – the length of the array and the number of facts. Each of the next m lines contains two integers li and ri (1≤li≤ri≤n).
It is guaranteed that neither the sum of all n nor the sum of all m exceeds 106.

Output
For each test case, output n integers denoting the lexicographically minimal array. Integers should be separated by a single space, and no extra spaces are allowed at the end of lines.

Sample Input
3
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4

Sample Output
1 2
1 2 1 2
1 2 3 1 1
题意分析:
给出一个数组长度和数据组数,每组数据有个l和r,al~ar中不能有任何两个数据是相等的,且都为整数,故应从1开始放入,使用迭代器set或者优先数列都是可以的。
注意:
哇,这题提交的时候真的是费了我不少力气
首先,杭电是不吃“bit/stdc++.h”这个万能头文件的,其次,杭电还不吃min和max的小函数(不能快捷使用min和max),所以一直编译错误….还有,题目上说的数据是10的6次方,数组要开的足够大才能过….不多说了,看代码吧..
代码篇:

#include <iostream>
#include <set>
#include <cstdio>
using namespace std;
int a[10010],pre[10010];
int main()
{
    int n,m,i,l,r,t;
    cin >> t;
    while(t--)
    {
        int flag=1;
        set<int>s;
        cin >> n >> m;
        for(i=1; i<=n; i++)
        {
            pre[i]=i;///初始化为1.2.3.....
            s.insert(i);///set里面也是
        }
        while(m--)
        {
            cin >> l >> r;
            pre[r]=(pre[r]<l)?pre[r]:l;///进入小的
        }
        for(i=n-1; i>=1; i--)
            pre[i]=(pre[i]<pre[i+1])?pre[i]:pre[i+1];///左界的推移
        for(i=1; i<=n; i++)
        {
            while(flag < pre[i])
            {
                s.insert(a[flag]);
                flag++;
            }
            a[i]=*s.begin();///赋值
            s.erase(a[i]);///擦除
        }
        cout << a[1];
        for(i=2; i<=n; i++)
        {
            printf(" %d",a[i]);
        }
        cout << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值