QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656490 | #7010. Rikka with A Long Colour Palette | Ashbourne | TL | 482ms | 7468kb | C++20 | 901b | 2024-10-19 13:11:55 | 2024-10-19 13:11:56 |
Judging History
answer
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
struct qj{
int l,r,id;
};
qj p[200005];
bool cmp(qj a,qj b)
{
return a.l<b.l;
}
const int inf=1e9+5;
int answ[200005];
inline void solve()
{
int n,k;
cin>>n>>k;
priority_queue<pair<int,int>> pq;
for(int i=1;i<=n;i++) cin>>p[i].l,cin>>p[i].r,p[i].id=i;
for(int i=1;i<=k;i++) pq.push(mp(0,i));
sort(p+1,p+n+1,cmp);
int ans=0;
int lastr=0;
for(int i=1;i<=n;i++)
{
int L=p[i].l,R=p[i].r,id=p[i].id;
answ[id] = pq.top().second;
int lsr=-pq.top().first;
if(lsr < R)
{
pq.pop();
pq.push(mp(-R,answ[id]));
}
int r0=-pq.top().first;
if(r0 >= L)
{
ans+=r0-max(lastr,L);
lastr=r0;
}
}
cout<<ans<<endl;
for(int i=1;i<n;i++) cout<<answ[i]<<" ";
cout<<answ[n]<<endl;
}
int main()
{
ios::sync_with_stdio(0);
int T;
cin>>T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
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: 15ms
memory: 5584kb
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: 482ms
memory: 7468kb
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: -100
Time Limit Exceeded
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 199597 198034 199024 199927 198181 198971 198522 198619 199873 198041 199090 198044 199231 198029 199043 199306 198258 199133 198997 199377 199744 199652 199847 198782 199694 199979 199191 198845 199570 199809 198467 199972 199841 198794 199901 199319 198105 199257 198388 199092 198671 199329 1987...