QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282253#1173. Knowledge Is..._LAP_WA 8ms56024kbC++141.8kb2023-12-11 16:55:472023-12-11 16:55:47

Judging History

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

  • [2023-12-11 16:55:47]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:56024kb
  • [2023-12-11 16:55:47]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;
int n, m, ans[N]; pair<int, int> A[N];
vector<int> vec[N], lsh;
vector<int> C[N];

int main() {
    ios::sync_with_stdio(false), cin.tie(0);

    cin >> n >> m;
    for(int i = 1; i <= n; i ++) {
        int l, r; cin >> l >> r;
        A[i] = {l, r};
        lsh.emplace_back(l), lsh.emplace_back(r);
    }
    sort(lsh.begin(), lsh.end()), lsh.erase(unique(lsh.begin(), lsh.end()), lsh.end());
    for(int i = 1; i <= n; i ++) {
        A[i].first = lower_bound(lsh.begin(), lsh.end(), A[i].first) - lsh.begin() + 1;
        A[i].second = lower_bound(lsh.begin(), lsh.end(), A[i].second) - lsh.begin() + 1;
        vec[A[i].first].emplace_back(i);
    }

    vector<int> single;
    int tot = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;
    for(int i = 1; i <= 2 * n; i ++) {
        for(auto id : vec[i]) {
            int r = A[id].second;
            if(!single.empty()) {
                int u = single.back(); single.pop_back();
                ans[u] = ++tot; ans[id] = ans[u];
                Q.push({r, id});
            } else if(!Q.empty() && Q.top().second < r) {
                int u = Q.top().first; Q.pop();
                swap(ans[u], ans[id]); Q.push({id, r});
                if(A[u].second < i) single.emplace_back(u);
                else C[A[u].second].emplace_back(u);
            } else C[r].emplace_back(id);
        }
        while(!C[i].empty()) single.emplace_back(C[i].back()), C[i].pop_back();
    }
    while(tot < m && !single.empty()) ans[single.back()] = ++tot, single.pop_back();
    for(int i = 1; i <= n; i ++)
        if(ans[i] <= m) cout << ans[i] << ' ';
        else cout << "0" << ' ';
    cout << '\n';

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 56024kb

input:

7 5
9 10
7 9
3 4
9 10
2 6
8 9
5 8

output:

3 2 1 1 2 4 3 

result:

ok answer = 7

Test #2:

score: 0
Accepted
time: 8ms
memory: 51192kb

input:

2 2
1 2
3 4

output:

1 1 

result:

ok answer = 2

Test #3:

score: 0
Accepted
time: 4ms
memory: 52252kb

input:

2 1
1 2
2 3

output:

0 1 

result:

ok answer = 1

Test #4:

score: 0
Accepted
time: 4ms
memory: 53892kb

input:

1 1
4 26

output:

1 

result:

ok answer = 1

Test #5:

score: 0
Accepted
time: 8ms
memory: 53628kb

input:

500 258
1 3
3 5
2 4
3 5
4 5
4 5
1 4
1 2
3 5
2 5
2 5
4 5
4 5
4 5
2 3
1 4
1 4
1 4
4 5
4 5
2 3
4 5
3 5
3 5
1 5
1 4
2 5
1 5
3 5
3 4
4 5
2 3
3 5
3 5
4 5
2 3
1 5
1 5
2 3
2 3
3 4
3 5
3 4
1 3
1 2
1 5
4 5
2 3
2 4
1 3
4 5
4 5
4 5
1 3
3 5
4 5
3 5
1 5
1 2
1 2
3 5
3 5
4 5
3 4
3 5
2 3
2 5
2 4
2 5
3 5
2 3
1 5
4 5
...

output:

39 1 0 2 39 40 0 1 3 156 157 41 42 43 71 0 0 0 44 45 72 46 4 5 119 0 158 120 6 7 47 73 8 9 48 74 121 122 75 76 10 11 12 40 2 123 49 77 0 41 50 51 52 42 13 53 14 124 3 4 15 16 54 17 18 78 159 0 160 19 79 125 55 0 0 43 56 20 126 57 58 0 5 6 7 59 21 22 23 60 161 0 24 61 25 26 0 127 27 62 28 8 0 29 162 ...

result:

ok answer = 376

Test #6:

score: -100
Wrong Answer
time: 7ms
memory: 52272kb

input:

500 242
8 9
9 10
2 9
8 10
9 10
6 10
4 8
4 5
2 6
7 10
3 8
1 8
1 6
5 9
7 8
8 10
8 9
8 10
2 9
2 3
6 8
3 10
5 9
1 3
6 8
4 10
9 10
8 9
8 10
1 9
3 9
3 7
2 3
6 10
3 6
6 10
3 4
3 6
9 10
5 7
8 10
6 10
5 6
5 7
7 8
1 3
4 7
9 10
4 9
2 4
8 9
1 3
8 10
3 4
9 10
4 9
5 10
8 9
1 3
1 5
8 10
3 4
8 9
3 9
3 6
3 10
6 7
7 ...

output:

108 148 0 109 200 45 5 6 77 67 1 148 67 21 68 110 111 112 0 13 46 2 22 5 47 7 150 113 114 0 3 4 14 48 90 49 34 91 151 23 115 50 24 25 69 6 8 152 9 27 116 7 117 35 153 10 26 118 8 45 119 36 120 0 92 195 51 70 0 154 78 71 11 72 124 155 52 158 117 0 73 74 156 12 157 121 108 75 53 13 14 54 154 196 122 5...

result:

wrong answer participant answer = 427, judge answer = 471