# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97842 | RezwanArefin01 | Job Scheduling (CEOI12_jobs) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 1e5 + 10;
vector<int> p[N];
int t[N << 2], sz[N] = {1e9}, n, d, m, x, ans;
void build(int node, int l, int r) {
t[node] = l;
if(l == r) return;
int m = l + r >> 1;
build(node << 1, l, m);
build(node << 1 | 1, m + 1, r);
}
int query(int node, int l, int r, int i, int j) {
if(r < i || l > j) return 0;
if(i <= l && r <= j) return t[node];
int m = l + r >> 1;
int q1 = query(node << 1, l, m, i, j);
int q2 = query(node << 1 | 1, m + 1, r, i, j);
return sz[q1] <= sz[q2] ? q1 : q2;
}
void update(int node, int l, int r, int i, int id) {
if(l == r) {
ans = max(ans, ++sz[l]);
p[l].push_back(id);
return;
}
int m = l + r >> 1;
if(i <= m) update(node << 1, l, m, i, id);
else update(node << 1 | 1, m + 1, r, i, id);
int q1 = t[node << 1], q2 = t[node << 1 | 1];
t[node] = sz[q1] <= sz[q2] ? q1 : q2;
}
int main() {
scanf("%d %d %d", &n, &d, &m);
build(1, 1, n);
for(int i = 1; i <= m; i++) {
scanf("%d", &x);
update(1, 1, n, query(1, 1, n, x, x + d), i);
}
printf("%d\n", ans);
for(int i = 1; i <= n; i++) {
for(int x : p[i]) printf("%d ", x);
puts("0");
}
}