#include<bits/stdc++.h>
using namespace std;
int a[100007];
int cnt[100007];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
     scanf("%d",&a[i]);
 int ans=1;
 set<int>s,num;//数字出现的次数,数字
 map<int,int>vis;//记录数字出现的次数的个数
 cnt[a[1]]++;
 s.insert(cnt[a[1]]);
 num.insert(a[1]);
 vis[cnt[a[1]]]++;
 for(int i=2;i<=n;++i){
  vis[cnt[a[i]]]--;
  if(!vis[cnt[a[i]]])
            s.erase(s.find(cnt[a[i]]));
  cnt[a[i]]++;
  vis[cnt[a[i]]]++;
  s.insert(cnt[a[i]]);
  num.insert(a[i]);
  if(s.size()==2){
   if(*s.rbegin()-*s.begin()==1&&vis[*s.rbegin()]==1||*s.begin()==1&&vis[1]==1)//有一个数字多出现了一次或者有一个数字只出现了一次
    ans=i;
  }
  else if(s.size()==1&&(num.size()==1||*s.begin()==1))//只有一个数字或者都只出现了一次
   ans=i;
 }
 printf("%d",ans);
    return 0;
}

Codeforces Round #558 (Div. 2)B(SET,模拟)的更多相关文章

  1. Codeforces Round #558 (Div. 2)

    目录 Codeforces Round #558 (Div. 2) 题解 A Eating Soup B Cat Party C Power Transmission D Mysterious Cod ...

  2. Codeforces Round #558 (Div. 2)-Cat Party (Hard Edition)-(前缀和 + 模拟)

    http://codeforces.com/problemset/problem/1163/B2 题意:有n天,每天有一个颜色,截取前x天,随便抽掉一天,使剩下的各个颜色出现的次数相等. 解题,也可以 ...

  3. Codeforces Round #558 (Div. 2)C(计算几何,排列组合,模拟)

    #include<bits/stdc++.h>using namespace std;typedef struct{ double k,b;}node;node k[1000007];bo ...

  4. Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

    A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  5. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  6. Codeforces Round #543 (Div. 2) D 双指针 + 模拟

    https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...

  7. Codeforces Round #398 (Div. 2) A. Snacktower 模拟

    A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...

  8. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

  9. Codeforces Round #371 (Div. 2) C 大模拟

    http://codeforces.com/contest/714/problem/C 题目大意:有t个询问,每个询问有三种操作 ①加入一个数值为a[i]的数字 ②消除一个数值为a[i]的数字 ③给一 ...

随机推荐

  1. SQLite connection strings

    Basic Data Source=c:\mydb.db;Version=3; Version 2 is not supported by this class library. SQLite In- ...

  2. idea中java异常

    1. Compilation failed: internal java compiler error 解决方案:File-->Setting...-->Build,Execution,D ...

  3. kylin_学习_01_kylin安装部署

    一.环境准备 根据官方文档,kylin是需要运行在hadoop环境下的,如下图: 1.hadoop环境搭建 参考:hadoop_学习_02_Hadoop环境搭建(单机) 2.hbase环境搭建 参考: ...

  4. Tomcat启动分析(我们为什么要配置CATALINA_HOME环境变量)

    原文:http://www.cnblogs.com/heshan664754022/archive/2013/03/27/2984357.html Tomcat启动分析(我们为什么要配置CATALIN ...

  5. java - BigDecimal的format()方法和setScale()方法格式字符串

    1.BigDecimal.setScale()方法用于格式化小数点 setScale(1)表示保留一位小数,默认用四舍五入方式 setScale(1,BigDecimal.ROUND_DOWN)直接删 ...

  6. 1_Command 游戏开发命令模式

    A dead simple implementation looks like: ``` // simple void InputHandler::handleInput() { if (isPres ...

  7. git克隆某一个branch

    git clone -b <branch> <remote_repo> 例如: git clone -b 指定的分支名字

  8. [转]_int64、long long 的区别

    大学生程序代写 C++的64位整数[原]by 赤兔 http://baike.baidu.com/view/1235293.htm 在做ACM题时,经常都会遇到一些比较大的整数.而常用的内置整数类型常 ...

  9. Poj 1936,3302 Subsequence(LCS)

    一.Description(3302) Given a string s of length n, a subsequence of it, is defined as another string ...

  10. 杂项:Webpack

    ylbtech-杂项:Webpack 本质上,webpack 是一个现代 JavaScript 应用程序的静态模块打包器(module bundler).当 webpack 处理应用程序时,它会递归地 ...