QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#39308#238. Distinct Valuesznk2373065134WA 215ms2892kbC++1.6kb2022-07-09 11:53:292022-07-09 11:53:31

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-09 11:53:31]
  • 评测
  • 测评结果:WA
  • 用时:215ms
  • 内存:2892kb
  • [2022-07-09 11:53:29]
  • 提交

answer

#include <stdio.h>
#include <string.h>
#include <algorithm>

const int MAXN = 100010;
int T, n, m, maxr, a[MAXN];
bool book[MAXN];

struct seg{
    int l, r;
};
seg p[MAXN];

bool operator < (seg x, seg y) {
    return x.l == y.l ? x.r > y.r : x.l < y.l;
}

int main() {
    // freopen("k.in", "r", stdin);
    // freopen("k.out", "w", stdout);
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; ++i) a[i] = 0;
        for (int i = 1; i <= m; ++i) {
            scanf("%d%d", &p[i].l, &p[i].r);
        }
        std::sort(p + 1, p + m + 1);
        maxr = 0;
        for (int i = 1; i <= m; ++i) {
            if (p[i].r <= maxr) continue;
            if (p[i].l > maxr) {
                for (int j = 1, pos = p[i].l; pos <= p[i].r; ++j, ++pos) {
                    a[pos] = j;
                }
            } else {
                for (int j = 1; j <= (p[i].r - p[i].l + 1) + (maxr - p[i].l + 1); ++j) {
                    book[j] = false;
                }
                for (int pos = p[i].l; pos <= maxr; ++pos) {
                    book[a[pos] == 0 ? 1 : a[pos]] = true;
                }
                for (int j = 1, pos = maxr + 1; pos <= p[i].r; ++j) {
                    if (book[j]) continue;
                    a[pos] = j;
                    book[j] = true;
                    pos++;
                }
            }
            maxr = std::max(maxr, p[i].r);
        }
        for (int i = 1; i <= n; ++i) {
            printf("%d", a[i] == 0 ? 1 : a[i]);
            if (i < n) printf(" ");
            else printf("\n");
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 215ms
memory: 2892kb

input:

11116
10 2
5 5
5 6
10 1
7 10
10 1
2 6
10 1
2 5
10 1
6 7
10 2
8 9
7 10
10 2
1 4
6 10
10 4
8 8
10 10
3 6
1 5
10 3
8 8
10 10
8 10
10 4
6 10
1 5
2 6
1 2
10 3
4 4
4 8
4 8
10 4
1 5
1 2
5 5
2 4
10 4
2 5
9 10
6 7
2 4
10 1
5 6
10 4
10 10
8 10
2 5
10 10
10 1
1 2
10 4
7 8
5 6
7 9
10 10
10 4
3 7
6 6
8 10
3 4
10...

output:

1 1 1 1 1 2 1 1 1 1
1 1 1 1 1 1 1 2 3 4
1 1 2 3 4 5 1 1 1 1
1 1 2 3 4 1 1 1 1 1
1 1 1 1 1 1 2 1 1 1
1 1 1 1 1 1 1 2 3 4
1 2 3 4 1 1 2 3 4 5
1 2 3 4 5 1 1 1 1 1
1 1 1 1 1 1 1 1 2 3
1 2 3 4 5 1 2 3 4 5
1 1 1 1 2 3 4 5 1 1
1 2 3 4 5 1 1 1 1 1
1 1 2 3 4 1 2 1 1 2
1 1 1 1 1 2 1 1 1 1
1 1 2 3 4 1 1 1 2 3
...

result:

wrong answer 11112th lines differ - expected: '1 1 2 3 4 5 6 7 8 9 10 11 12 1...6 99887 99888 99889 99890 99891', found: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...3 15764 15765 15766 15767 15768'