intmain(){ n = read(); for (int i = 1; i <= n; i++) a[i] = read(); int l = 1, r = 1, kmax = 0; for (int i = 1; i <= n; i++) { if (!book[a[i]]) { kmax++; book[a[i]] = 1; } } memset(book, 0, sizeof(book)); for (int k = 1; k < kmax; k++) { cnt = 1, l = 1; memset(c, 0, sizeof(c)); memset(book, 0, sizeof(book)); for (int i = 1; i <= n;) { if (book[a[i]]) update(book[a[i]], -1); update(i, 1); book[a[i]] = i; if (getsum(i) - getsum(l - 1) > k) l = i,cnt++; //记录分成了几条项链 else i++; } printf("%d ", cnt); } for (int i = kmax; i <= n; i++) printf("1 "); return0; }
intquery(int x){ int p = 0, s = 0; for (int i = 20; i != -1; i--) { if (p + (1 << i) > n) continue; if (s + tree[p + (1 << i)] <= x) s += tree[p += 1 << i]; } return p + 1; }
intmain(){ n = read(); for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= n; i++) { if (!last[a[i]]) update(i, 1); else nxt[last[a[i]]] = i; last[a[i]] = i; } for (int i = 1; i <= n; i++) q[1].push_back(i); //vector[i]里存的是要以i为左端点进行计算的k for (int i = 1; i <= n; i++) {//枚举所有左端点 int len = q[i].size(); for (int j = 0; j < len; j++) { //枚举所有要计算的k int x = q[i][j]; ans[x]++; //query(x)为能找到的最大的右端点 + 1 q[query(x)].push_back(x); } update(i, -1); if (nxt[i]) update(nxt[i], 1); }
for (int i = 1; i <= n; i++) printf("%d ", ans[i]); return0; }