博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CodeForces 1163B2 --- Cat Party [Hard Edition]】
阅读量:2038 次
发布时间:2019-04-28

本文共 1941 字,大约阅读时间需要 6 分钟。

【CodeForces 1163B2 --- Cat Party [Hard Edition]】

题目来源:

Description

This problem is same as the previous one, but has larger constraints.

Shiro’s just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her house is too small, so she can only invite one friend at a time.

For each of the n days since the day Shiro moved to the new house, there will be exactly one cat coming to the Shiro’s house. The cat coming in the i-th day has a ribbon with color ui. Shiro wants to know the largest number x, such that if we consider the streak of the first x days, it is possible to remove exactly one day from this streak so that every ribbon color that has appeared among the remaining x−1 will have the same number of occurrences.

For example, consider the following sequence of ui: [2,2,1,1,5,4,4,5]. Then x=7 makes a streak, since if we remove the leftmost ui=5, each ribbon color will appear exactly twice in the prefix of x−1 days. Note that x=8 doesn’t form a streak, since you must remove exactly one day.

Since Shiro is just a cat, she is not very good at counting and needs your help finding the longest streak.

Input

The first line contains a single integer n (1≤n≤105) — the total number of days.

The second line contains n integers u1,u2,…,un (1≤ui≤105) — the colors of the ribbons the cats wear.

Output

Print a single integer x — the largest possible streak of days.

Sample Input

13

1 1 1 2 2 2 3 3 3 4 4 4 5

Sample Output

13

AC代码1:

#include 
using namespace std;#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)#define endl '\n'const int MAXN = 1e5+5;int arr[MAXN]; int main(){
SIS; int n,x,ans=1; map
m1,m2; cin >> n; for(int i=0;i
> x; m1[x]++; m2[m1[x]]++; if(m1[x]*m2[m1[x]]==i+1 && i!=n-1) ans=i+2; else if(m1[x]*m2[m1[x]]==i) ans=i+1; } cout << ans << endl; return 0;}

转载地址:http://xsyof.baihongyu.com/

你可能感兴趣的文章
高可用的工作心得分享
查看>>
Spring Data Redis Version 1.7.1.RELEASE
查看>>
Spring-data-redis:特性与实例(redis 存储对象)
查看>>
linux下mysql配置文件my.cnf最详细解释
查看>>
js中使用jstl中的值
查看>>
eclipse的静态资源文件夹缓存问题
查看>>
Project xxx already exists Add a version or custom suffix using "Name template" in "Advanced" sett
查看>>
Linux 下 查看以及修改文件权限
查看>>
文件类型CRLF line terminators导致sh文件不能执行
查看>>
我的一些简单的shell脚本实例
查看>>
shell一个实例$(($a+1))
查看>>
Linux awk命令
查看>>
shell自定义函数及参数调用解析
查看>>
/bin,/sbin,/usr/sbin,/usr/bin 目录之简单区别
查看>>
linux wget 命令用法详解
查看>>
MySQL性能优化的最佳20+
查看>>
使用Spring Cache
查看>>
Guava Cache使用笔记
查看>>
guava试水一篇
查看>>
加速页面显示 压缩html js css
查看>>