QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276827#7010. Rikka with A Long Colour Paletteucup-team1209#WA 26ms7716kbC++201.5kb2023-12-06 11:22:112023-12-06 11:22:11

Judging History

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

  • [2023-12-06 11:22:11]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:7716kb
  • [2023-12-06 11:22:11]
  • 提交

answer

#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
using pi = pair <int, int> ;

cs int N = 4e5 + 5; 

int n, k, T; 
struct seg {
    int l, r, c;
    bool operator < (cs seg & x) cs {
        return l < x.l; 
    }
} a[N];

int pos[N];
int ans[N];
int b[N], m; 

void Main() {
    cin >> n >> k; 
    m = 0; 
    for(int i = 1; i <= n; i++) {
        cin >> a[i].l >> a[i].r; 
        a[i].c = i; 
        b[++ m] = a[i].l;
        b[++ m] = a[i].r;
    }
    sort(b + 1, b + m + 1);
    m = unique(b + 1, b + m + 1) - b - 1;
    sort(a + 1, a + n + 1);
    priority_queue <pi> q; 
    for(int i = 1; i <= k; i++) q.push({pos[i] = 0, i});
    for(int i = 1; i <= n; i++) {
        auto [l, r, c] = a[i];
        auto [k, color] = q.top();
        q.pop();
        k = max(-k, r);
        ans[c] = color;
        q.push({-k, color}); 
    }
    vector <int> d(m + 1);
    for(int i = 1; i <= n; i++) {
        a[i].l = lower_bound(b + 1, b + m + 1, a[i].l) - b;
        a[i].r = lower_bound(b + 1, b + m + 1, a[i].r) - b; 
        ++ d[a[i].l];
        -- d[a[i].r];
    }
    int sum = 0; 
    for(int i = 1; i < m; i++) {
        d[i] += d[i - 1];
        if(d[i] >= k) sum += b[i + 1] - b[i];
    }
    cout << sum << '\n';
    for(int i = 1; i <= n; i++) cout << ans[i] << ' '; cout << '\n';
}

int main() {
    #ifdef zqj
    freopen("1.in","r",stdin);
    #endif
    ios :: sync_with_stdio(0), cin.tie(0);
    cin >> T; 
    while(T--) {
        Main();
    }
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7716kb

input:

1
3 2
1 5
2 4
3 6

output:

3
2 1 1 

result:

ok 1 cases

Test #2:

score: -100
Wrong Answer
time: 26ms
memory: 7712kb

input:

1000
100 2
22 75
26 45
72 81
29 47
2 97
25 75
82 84
17 56
2 32
28 37
39 57
11 18
6 79
40 68
16 68
40 63
49 93
10 91
55 68
31 80
18 57
28 34
55 76
21 80
22 45
11 67
67 74
4 91
34 35
65 80
21 95
1 52
25 31
2 53
22 96
89 99
7 66
2 32
33 68
75 92
10 84
28 94
12 54
9 80
21 43
51 92
20 97
7 25
17 67
38 10...

output:

99
2 2 2 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 
99
1 2 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 1 1 1 2 1 2 2 2 2 2 1 2 1 2 1 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2...

result:

wrong output format Expected EOLN