#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. Codeforces 900D Unusual Sequences:记忆化搜索

    题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...

  2. Codeforces 158E Phone Talks:dp

    题目链接:http://codeforces.com/problemset/problem/158/E 题意: 你有n个电话要接,每个电话打进来的时刻为第t[i]分钟,时长为d[i]分钟. 每一个电话 ...

  3. angularjs 系列之$q和promise

    还是同一个项目,在项目中,发现多个controller之内有一个共同的服务器请求,当时只是不断的重复使用,如今,现在项目结束,代码开始走向了优化迭代的阶段: 首先,我的思路是把这个共同的请求,从con ...

  4. Linux中redis主从配置

    假设要在6380开启redis 1.添加配置文件:复制redis.conf为redis_6380.conf 2.修改配置文件:修改redis_6380.conf中port.pidfile 3.防火墙: ...

  5. 第十七章-异步IO

    异步IO的出现源自于CPU速度与IO速度完全不匹配 一般的可以采用多线程或者多进程的方式来解决IO等待的问题 同样异步IO也可以解决同步IO所带来的问题 常见的异步IO的实现方式是使用一个消息循环, ...

  6. 搭建 Http Dynamic Streaming 点播/直播服务器

    1.        HTTP Origin Module的处理数据流: a)         客户端发送媒体索引请求到Apache.例如: http://www.example.com/media/  ...

  7. bzoj1002轮状病毒

    高精度练习题 根据什么什么基尔霍夫矩阵 反正就是高精度练习 #include<iostream> #include<cstdio> using namespace std; s ...

  8. 1068 Find More Coins (30)(30 分)

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

  9. 配置 VS Code 调试 PHP

    配置 VS Code 调试 PHP 1.下载 xampp 集成服务器wampserver3.1.0-Apache2.4.7_PHP5.6.3-7.0.23-7.1.19_MySQL5.7.19_Mar ...

  10. Tensorflow Summary用法

    本文转载自:https://www.cnblogs.com/lyc-seu/p/8647792.html Tensorflow Summary用法 tensorboard 作为一款可视化神器,是学习t ...