Codeforces Round #406 (Div. 2) E. Till I Collapse
来源:互联网 发布:linux进入用户命令 编辑:程序博客网 时间:2024/06/16 03:51
E. Till I Collapse
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Rick and Morty want to find MR. PBH and they can’t do it alone. So they need of Mr. Meeseeks. They Have generated n Mr. Meeseeks, standing in a line numbered from 1 to n. Each of them has his own color. i-th Mr. Meeseeks’ color is ai.
Rick and Morty are gathering their army and they want to divide Mr. Meeseeks into some squads. They don’t want their squads to be too colorful, so each squad should have Mr. Meeseeks of at most k different colors. Also each squad should be a continuous subarray of Mr. Meeseeks in the line. Meaning that for each 1 ≤ i ≤ e ≤ j ≤ n, if Mr. Meeseeks number i and Mr. Meeseeks number j are in the same squad then Mr. Meeseeks number e should be in that same squad.
Also, each squad needs its own presidio, and building a presidio needs money, so they want the total number of squads to be minimized.
Rick and Morty haven’t finalized the exact value of k, so in order to choose it, for each k between 1 and n (inclusive) need to know the minimum number of presidios needed.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 105) — number of Mr. Meeseeks.
The second line contains n integers a1, a2, …, an separated by spaces (1 ≤ ai ≤ n) — colors of Mr. Meeseeks in order they standing in a line.
Output
In the first and only line of input print n integers separated by spaces. i-th integer should be the minimum number of presidios needed if the value of k is i.
Examples
input
5
1 3 4 3 3
output
4 2 1 1 1
input
8
1 5 7 8 1 7 6 1
output
8 4 3 2 1 1 1 1
Note
For the first sample testcase, some optimal ways of dividing army into squads for each k are:
[1], [3], [4], [3, 3]
[1], [3, 4, 3, 3]
[1, 3, 4, 3, 3]
[1, 3, 4, 3, 3]
[1, 3, 4, 3, 3]
For the second testcase, some optimal ways of dividing army into squads for each k are:
[1], [5], [7], [8], [1], [7], [6], [1]
[1, 5], [7, 8], [1, 7], [6, 1]
[1, 5, 7], [8], [1, 7, 6, 1]
[1, 5, 7, 8], [1, 7, 6, 1]
[1, 5, 7, 8, 1, 7, 6, 1]
[1, 5, 7, 8, 1, 7, 6, 1]
[1, 5, 7, 8, 1, 7, 6, 1]
[1, 5, 7, 8, 1, 7, 6, 1]
题意;给出n个人的编号,要求同一组中编号不能超过k样,求当k为(1—n)时的最小分组数,要求分组连续。
题解:如果两个端点的分组数相同,则区间内的也与端点相同。
代码:
#include<bits/stdc++.h>using namespace std;int c[100007];int vis[100007];int ans[100007];int n;int get_cnt(int k){ int res=0,cnt=0; memset(vis,-1,sizeof(vis)); for(int i=1; i<=n; i++) { if(vis[c[i]]==res) continue; vis[c[i]]=res; cnt++; if(cnt>k) { res++; cnt=1; vis[c[i]]=res; } } return res+1;}void solve(int l,int r){ if(l>r) return ; int cntl=get_cnt(l); int cntr=get_cnt(r); if(cntl==cntr) { for(int i=l; i<=r; i++) ans[i]=cntl; return ; } ans[l]=cntl; ans[r]=cntr; int mid=(l+r)>>1; solve(l+1,mid); solve(mid+1,r-1);}int main(){ scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&c[i]); solve(1,n); for(int i=1; i<=n; i++) printf("%d ",ans[i]); return 0;}
- Codeforces Round #406 (Div. 2) E. Till I Collapse
- Codeforces Round #406 (Div. 1) C. Till I Collapse(主席树)
- Codeforces Round #406 (Div. 1) C. Till I Collapse(可持久化线段树)
- Codeforces 787E Till I Collapse 主席树+二分
- codeforces 786c Till I Collapse
- Codeforces 786C Till I Collapse[主席树][二分]
- Codeforces-786C-Till I Collapse(二分剪枝)
- 【题解】codeforces786C Till I Collapse
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces Round #103 (Div. 2) E题
- Codeforces Round #147 (Div. 2) E
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round #197 (Div. 2) (C~E)
- Codeforces Round #102 (Div. 2) //缺E
- Codeforces Round #104 (Div. 2) //缺E
- Codeforces Round #105 (Div. 2) //缺E
- Codeforces Round #103 (Div. 2) //缺E
- Codeforces Round #106 (Div. 2) //缺E
- Android 沉浸式状态栏的实现方法、状态栏透明
- 折半查找
- jvm_outofmemory_JavaVMStackSOF
- python正则表达式
- 关于IAR报 more than one storage class may not be specified 错误的问题
- Codeforces Round #406 (Div. 2) E. Till I Collapse
- OSG入门_场景图形与OpenSceneGraph概述02
- golang实现简易TCP服务以及TCP和UDP协议对比
- Hydra 实验学习笔记
- hibernate的核心接口
- 接上,优化滚动的效率
- 简单分析system_call中断处理过程
- java 虚拟机 参数配置
- Linux下SSH安装配置使用详解