QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625671 | #7010. Rikka with A Long Colour Palette | 树上的忍者 (Jun Tao, Pengcheng Geng, Haoran Song )# | AC ✓ | 1426ms | 24704kb | C++20 | 2.6kb | 2024-10-09 20:21:26 | 2024-10-09 20:21:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct Set{
priority_queue<int,vector<int>,greater<int>>qu1,qu2;
int siz=0;
void flush(){
while(!qu1.empty()&&!qu2.empty()&&qu1.top()==qu2.top())qu1.pop(),qu2.pop();
}
void insert(int x){
qu1.push(x);siz++;
}
void erase(int x){
qu2.push(x);siz--;
}
int size(){
return siz;
}
int top(){
flush();
return qu1.top();
}
};
void solve()
{
int n,k;cin>>n>>k;
vector<pair<int,int>>a(n);
vector<int> id;
for(int i=0;i<n;i++){
cin>>a[i].first>>a[i].second;
id.push_back(a[i].first);
id.push_back(a[i].second);
}
sort(id.begin(),id.end());
id.resize(unique(id.begin(),id.end())-id.begin());
auto getid = [&](int x){
return lower_bound(id.begin(),id.end(),x)-id.begin();
};
vector<vector<int>> add(id.size()),del(id.size());
for(int i=0;i<n;i++){
a[i].first=getid(a[i].first);
a[i].second=getid(a[i].second);
add[a[i].first].push_back(i);
del[a[i].second].push_back(i);
}
vector<int> ans(n,-1);
vector<int> hav(k+1),seg(n),in(n);
Set nothav;//color
Set notcol_seg;//segment
int segs=0;
for(int i=1;i<=k;i++)nothav.insert(i);
auto insert = [&](int col){
nothav.erase(col);
};
auto erase = [&](int col){
nothav.insert(col);
};
int tot_len=0;
for(int i=0;i<id.size()-1;i++){
for(auto it:add[i]){
notcol_seg.insert(it);
}
for(auto it:del[i]){
if(seg[it])seg[it]=0,erase(ans[it]),segs--;
else notcol_seg.erase(it);
}
// cout<<"i="<<i<<" x="<<id[i]<<endl;
// cout<<"seg :";for(auto it:seg)cout<<it<<" ";;cout<<endl;
// cout<<"notcol_seg :";for(auto it:notcol_seg)cout<<it<<" ";;cout<<endl;
if(segs+notcol_seg.size()>=k){
tot_len+=id[i+1]-id[i];
while(segs<k){
int seg_id=notcol_seg.top();notcol_seg.erase(seg_id);
int col = nothav.top();
// cout<<"seg_id = "<<seg_id<<" col="<<col<<endl;
ans[seg_id]=col;
insert(col);
seg[seg_id]=1;
segs++;
}
}
}
for(int i=0;i<n;i++)if(ans[i]==-1)ans[i]=1;
cout<<tot_len<<"\n";
for(int i=0;i<n;i++)cout<<ans[i]<<" \n"[i==n-1];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;cin>>T;
while(T--)solve();
}
/*
2
3 2
1 5
2 4
3 6
4 2
1 4
5 8
3 6
9 10
*/
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
1 3 2 1 5 2 4 3 6
output:
3 1 2 2
result:
ok 1 cases
Test #2:
score: 0
Accepted
time: 39ms
memory: 3880kb
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 1 1 1 1 2 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 2 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 2 99 1 2 1 1 1 1 1 2 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 ...
result:
ok 1000 cases
Test #3:
score: 0
Accepted
time: 1344ms
memory: 24704kb
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: 1426ms
memory: 6440kb
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 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 1 1 1 1 ...
result:
ok 1000 cases