#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. Delphi Stringlist Delimiter如何区分TAB和空格

    var st: TStrings; begin st := TStringList.Create; st.StrictDelimiter := True;//这个多少人用过? st.Delimiter ...

  2. 使用CSS3制作酷炫防苹果复选框 自行测试!

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. WebElement接口获取值

    通过WebElement接口获取值 size 获取元素的尺寸 text 获取元素的文本 get_attribute(name) 获取属性值 location 获取元素坐标,先找到要获取的元素,再调用该 ...

  4. JavaUtil_07_HttpUtil_使用Hutool 封装的 HttpUtil

    二.参考资料 1.[Hutool]Hutool工具类之Http工具——HttpUtil

  5. Linux-shell 练习题(一)

    1.实现批量添加20个用户,用户名为user1-20,密码为user+123 #!/bin/bash count=$ if [ -n "$count" ] then ;i<= ...

  6. linux命令学习笔记(21):find命令之xargs

    xargs是一条Unix和类Unix操作系统的常用命令.它的作用是将参数列表转换成小块分段传递给其他命令,以避免参数列表过长的问题 xargs的作用一般等同于大多数Unix shell中的反引号,但更 ...

  7. yarn 官方配置推荐

    http://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.6.4/bk_installing_manually_book/content/rpm-chap ...

  8. C#实现根据传入时间段,找出时间段内日期,并生成相对应文件路径

    [1]获取固定日期范围内的所有日期,以数组形式返回 /// <summary>        /// 获取固定日期范围内的所有日期,以数组形式返回        /// </summ ...

  9. 洛谷【P1080】国王游戏

    我对贪心的理解:https://www.cnblogs.com/AKMer/p/9776293.html 题目传送门:https://www.luogu.org/problemnew/show/P10 ...

  10. Linux使用tcpdump抓取网络数据包示例

    tcpdump是Linux命令行下常用的的一个抓包工具,记录一下平时常用的方式,测试机器系统是ubuntu 12.04. tcpdump的命令格式 tcpdump的参数众多,通过man tcpdump ...