Pagini recente » Istoria paginii runda/baraj_lasm_cl_xi_xii | Cod sursa (job #1689973) | Cod sursa (job #1304864) | Cod sursa (job #2192068) | Cod sursa (job #125746)
Cod sursa(job #125746)
#include <cstdio>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
const int N = 300000;
int n,d;
pair<int,int> a[N];
int m[N];
bool pair_cmp_second ( const pair<int,int> &a, const pair<int,int> &b ) { return a.second < b.second; }
int main() {
freopen("partitie.in","rt",stdin);
freopen("partitie.out","wt",stdout);
scanf("%d %d",&n,&d);
for (int i = 0; i < n; ++i) {
scanf("%d",&a[i].first);
a[i].second = i;
}
sort(a,a+n);
// A walk in the park :)
deque<int> deq;
set<int> ok;
int max = 2;
m[0] = 1; deq.push_back(0); ok.insert(2);
int ds = 1;
for (int i = 1; i < n; ++i) {
while (ds != 0 && a[deq.front()].first <= a[i].first-d) {
ok.insert(m[deq.front()]);
deq.pop_front();
--ds;
}
if (ok.empty()) {
++max;
ok.insert(max);
}
m[i] = (*(ok.begin()));
ok.erase(ok.find(m[i]));
deq.push_back(i);
++ds;
}
// Back home
for (int i = 0; i < n; ++i) a[i].first = i;
sort(a,a+n,pair_cmp_second);
printf("%d\n",max);
bool maxisthere = false;
for (int i = 0; i < n; ++i) {
maxisthere = maxisthere || m[a[i].first] == max;
printf("%d\n",m[a[i].first]);
}
if (!maxisthere) for (;;);
return 0;
}