QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276889 | #7010. Rikka with A Long Colour Palette | ucup-team1209# | AC ✓ | 883ms | 19412kb | C++20 | 2.0kb | 2023-12-06 12:19:48 | 2023-12-06 12:19:50 |
Judging History
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 ans[N];
int b[N], m;
void Main() {
cin >> n >> k;
m = 0;
k = min(n + 1, k);
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({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);
static vector <int> e[N];
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];
// e[a[i].l].pb(ans[a[i].c]);
// e[a[i].r].pb(-ans[a[i].c]);
}
int sum = 0;
// vector <int> bin(k + 1);
int FLAG = 0;
for(int i = 1; i < m; i++) {
// for(auto x : e[i]) {
// if(x > 0) FLAG += bin[x] == 0, bin[x] ++;
// else bin[- x] --, FLAG -= bin[-x] == 0;
// }
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];
if(i < n) cout << ' ';
else cout << '\n';
}
for(int i = 0; i <= n * 2; i++) ans[i] = 0, b[i] = 0;
}
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;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 17860kb
input:
1 3 2 1 5 2 4 3 6
output:
3 2 1 1
result:
ok 1 cases
Test #2:
score: 0
Accepted
time: 25ms
memory: 15444kb
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:
ok 1000 cases
Test #3:
score: 0
Accepted
time: 879ms
memory: 19412kb
input:
910 2000 1 291106515 907601188 257183002 580226984 677669535 703754379 578360426 581095542 555843963 776993944 590501585 787712383 268406144 715107805 67868779 956936247 805517214 820489184 673778237 728344625 320030940 533725999 412875077 899787237 376585734 712537132 203142903 420447884 58970816 3...
output:
999533742 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 910 cases
Test #4:
score: 0
Accepted
time: 883ms
memory: 18428kb
input:
1000 2000 200000 114320346 414198300 865005596 959003090 308399397 989829253 20993741 74598817 703749014 929597776 326260003 367629651 500954265 989504336 465349215 518791173 33679837 905990625 847419333 879685651 285496458 697635762 845139062 964850697 235259972 953405425 872309480 898530420 302629...
output:
0 1598 35 1025 1928 182 972 523 620 1874 42 1091 45 1232 30 1044 1307 259 1134 998 1378 1745 1653 1848 783 1695 1980 1192 846 1571 1810 468 1973 1842 795 1902 1320 106 1258 389 1093 672 1330 734 1143 94 1739 1460 1059 1527 499 1182 1394 1322 741 1326 732 1964 1251 283 199 1819 166 1716 1955 792 223 ...
result:
ok 1000 cases