【题目描述】

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

【题目分析】
这道题放在线段树里面我实在没有什么想法,觉得就暴力一下不可以吗?可是估计了一下时间应该会超时,在网上看到一种想法,就是二分暴力,如果区间两端答案一样那么说明中间的所有的答案都是一样的,因为答案应该是非线性递减的。
【AC代码】

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];
int vis[MAXN];
int ans[MAXN];
int n;void Read()
{scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}
}int GetAns(int k)  //模拟
{memset(vis,-1,sizeof(vis));int cnt=0,ret=1;for(int i=1;i<=n;i++){if(vis[a[i]]==ret) continue;cnt++;if(cnt>k){ret++;cnt=1;}vis[a[i]]=ret;}return ret;
}void Solve(int l,int r)    //二分
{if(l>r) return;int ansl=GetAns(l);int ansr=GetAns(r);if(ansl==ansr){for(int i=l;i<=r;i++){ans[i]=ansl;}return;}ans[l]=ansl; ans[r]=ansr;int mid=(l+r)>>1;Solve(l+1,mid); Solve(mid+1,r-1);
}void Print()
{for(int i=1;i<=n;i++){printf("%d ",ans[i]);}
}int main()
{Read();Solve(1,n);Print();return 0;
}

CodeForces - 786C——二分+模拟?相关推荐

  1. CodeForces - 1236D Alice and the Doll(贪心+二分+模拟)

    题目链接:点击查看 题目大意:给出一个n*m的矩阵,矩阵中有k个障碍物,在点(1,1)处有一个洋娃娃,洋娃娃每次的行动路线只能是直走或右拐,初始时洋娃娃面朝正右方向,问洋娃娃能否将所有方格都走一遍,并 ...

  2. CodeForces - 1491E Fib-tree(模拟)

    题目链接:点击查看 题目大意:给出一棵树,问是否为斐波那契树.斐波那契树的定义是,树的大小为斐波那契数列的其中一项,且可以通过删除掉一条边使其拆分的两个子树也为斐波那契树 题目分析:需要观察到,大小为 ...

  3. PAT (Advanced Level) 1010 Radix(二分+模拟)

    题目链接:点击查看 题目大意:给出两个数n1和n2,再给出其中一个数的进制,问另一个数能否选择一个进制,使得两个数的值相等 题目分析:首先这个题目一开始会错意了,因为题中的表示只给出了0~9以及a~z ...

  4. zoj4062 Plants vs. Zombies 二分+模拟(贪心的思维)

    题目传送门 题目大意:有n个植物排成一排,标号为1-n,每株植物有自己的生长速度ai,每对植物浇一次水,该株植物就长高ai,现在机器人从第0个格子出发,每次走一步,不能停留,每一步浇一次水,总共可以走 ...

  5. Match Points CodeForces 1156C 二分答案

    CodeForces 1156C Match Points 传送门:https://codeforces.com/problemset/problem/1156/C You are given a s ...

  6. Codeforces 650B 二分

    题目:http://codeforces.com/problemset/problem/650/B 题意: :给n张图片循环可看,每张图片的朝向为横(w)|竖(v),但是手机是竖直放置的.开始时打开的 ...

  7. 二分 + 模拟 - Carries

    Carries Problem's Link Mean: 给你n个数,让你计算这n个数两两组合相加的和进位的次数. analyse: 脑洞题. 首先要知道:对于两个数的第k位相加会进位的条件是:a%( ...

  8. codeforces 719C (复杂模拟-四舍五入-贪心)

    题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑... 转载于:https://www.cnblogs.com/A--Q/p/5 ...

  9. Codeforces 67A【模拟】

    题意: 给一个字符串代表相邻学生的比较,L代表左边多,R表示右边多,=表示左右相等. 保证每个人拿糖>=1,在分糖最少的情况下,输出每个学生所分得的糖. 思路: 模拟一下,第一个人一开始拿1个, ...

最新文章

  1. ssh升级后+sftp+java_java中使用JSCH包,SFTP及SSH2文件操作及远程命令执行(改进)...
  2. 热像仪 二次开发 c++_一种全新的红外热像仪——“可编程红外热像仪”
  3. java mkdir()和mkdirs()区别
  4. python实现的遗传算法实例(一)
  5. decimal在java中用什么类型,MYSQL数据库 的 decimal 字段类型 和 Java 的BigDecimal
  6. LeetCode Rearrange String k Distance Apart
  7. azkaban 入门简介
  8. 将中文转化为GB2312编码
  9. 国家AAAAA级旅游景区数量统计
  10. Wampserver修改默认浏览器、默认编辑器的解决办法
  11. windows2008 FTP下载“当前的安全设置不允许”的解决方法
  12. 文盲的Python入门日记:第二十八天,封装一个自定义爬虫类,用来执行日常的采集(二)
  13. jfinal jboot 拦截器过滤文件上传请求 和 跨域解决方法
  14. C# 判断有向图是否存在环
  15. 计算机网络基础试卷分析,《计算机应用基础》期末试卷分析.doc
  16. 揭个人信息黑产链条:含50多种交易大项 可私人定制
  17. 信息与智能科学导论答案_最全中科大计算机学院课程资源(含答案)
  18. 复旦大学计算机网络期末考试试题,复旦大学学习计算机科学技术学院期末试题练习题.doc...
  19. Android开发艺术探索2
  20. 2021-07-21学习笔记初识batis

热门文章

  1. 2018-05-05(在小程序中使用图标)
  2. Spark系列—02 Spark程序牛刀小试
  3. poj3335 半平面交
  4. SharePoint 2010 Form Authentication (SQL) based on existing database
  5. 10款精选的用于构建良好易用性网站的jQuery插件
  6. 一家很好的iPhone应用程序开发公司——易标科技
  7. 皖西学院计算机证书,下半年皖西学院计算机等级考试报名时间
  8. 查看 固态硬盘位置_3米防摔+人脸/指纹解锁:西数Armorlock移动固态硬盘
  9. 实训09.09:简单的彩票系统(自选多注)
  10. 可以自动撑起的html样式,好好玩:CSS3抖动样式CSS Shake让你的网页酷炫起来