杭电2018多校赛第一场 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 (l≤i<j≤r), ai≠ajholds.
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

Source

2018 Multi-University Training Contest 1

Recommend

liuyiding   |   We have carefully selected several similar problems for you:  6318 6317 6316 6315 6314 

r数组记录该点最大要求不相同的区间的右端点,ok记录上一次起始的位置,now记录上一次结尾的位置

#include<bits/stdc++.h>

using namespace std;

const int MAXN = 100000 + 10;
int a[MAXN], r[MAXN];
priority_queue<int, vector<int>, greater<int> >que;

int main()
{
    int T;
    scanf("%d", &T);
    while(T --)
    {
        int n, q;
        //cout << "!!!" << endl;
        //cout << que.size() << endl;
        while(!que.empty())
            que.pop();
        //cout << "!!!!" << endl;
        scanf("%d %d", &n, &q);
        for(int i = 1; i <= n; i ++)
        {
            r[i] = i;
            que.push(i);
        }
        int x, y;
        while(q --)
        {
            scanf("%d %d", &x, &y);
            r[x] = max (r[x], y);
        }
        int ok = 1, now = 0;
        for(int i = 1; i <= n; i ++)
        {
            if(now >= r[i])
                continue;

            while(ok < i)
            {
                que.push(a[ok]);
                ok ++;
            }
            //cout << "!" << que.size() << endl;
            while(now < r[i])
            {
                now ++;
                a[now] = que.top();
                que.pop();
            }
        }
        printf("%d", a[1]);
        for(int i = 2; i <= n ;i ++)
            printf(" %d", a[i]);
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Ant_e_zz/article/details/81221703