codeforces 1041 c 乱搞
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 struct po { 6 int val; 7 int id; 8 }; 9 po a[200005]; 10 vector<int> ans[200005]; 11 map<int,int> mp; 12 struct node { 13 int val; 14 int wh; 15 node(int _val,int _wh) { 16 val = _val; 17 wh = _wh; 18 } 19 bool operator < (const node &b) const { 20 return val > b.val; 21 } 22 }; 23 24 bool cmp1(po x,po y) { 25 return x.val < y.val; 26 } 27 bool cmp2(po x,po y) { 28 return x.id < y.id; 29 } 30 int main() { 31 32 33 int n,m,d; 34 35 scanf("%d %d %d",&n,&m,&d); 36 37 for(int i = 1; i <= n; i++) { 38 scanf("%d",&a[i].val); 39 a[i].id = i; 40 } 41 42 43 sort(a + 1,a + n + 1,cmp1); 44 45 priority_queue<node> q; 46 47 q.push(node(a[1].val,1)); 48 ans[1].push_back(a[1].val); 49 int cnt = 1; 50 for(int i = 2; i <= n; i++) { 51 52 if(a[i].val - d > q.top().val) { 53 ans[q.top().wh].push_back(a[i].val); 54 q.push(node(a[i].val,q.top().wh)); 55 q.pop(); 56 } 57 else { 58 q.push(node(a[i].val,++cnt)); 59 ans[cnt].push_back(a[i].val); 60 } 61 } 62 63 printf("%d\n",cnt); 64 for(int i = 1; i <= cnt; i++) { 65 for(int j = 0; j < ans[i].size(); j++) { 66 mp[ans[i][j]] = i; 67 } 68 } 69 70 sort(a + 1,a + n + 1,cmp2); 71 72 for(int i = 1; i <= n; i++) { 73 printf("%d ",mp[a[i].val]); 74 } 75 76 77 78 return 0; 79 }