#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. c版基于链表的插入排序(改进版)

    1. [代码][C/C++]代码 /** * @todo    c版基于链表的插入排序 * @author  Koma **/#include<stdio.h>#include<st ...

  2. GridView设置多个DatakeyNames

    1.aspx页面GridView直接绑定DataKeyNames aspx设置: <asp:GridView ID="grvGrid" runat="server& ...

  3. linux应用之ntpdate命令联网同步时间

    当Linux服务器的时间不对的时候,可以使用ntpdate工具来校正时间. 安装:yum install ntpdate ntpdate简单用法: # ntpdate ip # ntpdate 210 ...

  4. python3与Redis连接操作

    Python3之redis使用   简介 redis是一个key-value存储系统,和Memcache类似,它支持存储的value类型相对更多,包括string(字符串),list(链表),set( ...

  5. Java钉钉开发_02_免登授权(身份验证)

    源码已上传GitHub: https://github.com/shirayner/DingTalk_Demo 一.本节要点 1.免登授权的流程 (1)签名校验 (2)获取code,并传到后台 (3) ...

  6. L103

    Give everyday the chance to become the most beautiful day of your life.把每天都过成你生命中最美好的一天.competence 能 ...

  7. C++中类型转换

    static_cast            静态类型转换. 在编译的时候C++编译器会做类型检查,基本类型能转换,指针类型不进行转换. C语言中隐式类型转换的地方均可以使用static_cast. ...

  8. sql根据坐标算距离

    CREATE FUNCTION ConvertXYToDistance(@la1 DECIMAL,@lo1 DECIMAL,@la2 DECIMAL,@lo2 DECIMAL)RETURNS FLOA ...

  9. sqlite表结构动态读取工具(Chole ORM框架)

    Chole ORM框架 sqlIte于嵌入式数据库读取比较有利,不需要安装office也可以进行,可以在服务器系统当中使用. 所以我开发了这款工具,然后就是为了动态的读取表结构,然后根据表结构加载所有 ...

  10. HEOI2017题解

    Day 1 : T1 : 期末考试 很水的一道题,但是自己搞了大半天过不了大样例. 最后还A了... 主要思想就是枚举最后一个完成的任务的时间 然后对两部分的代价分类讨论统计一下. (考试代码,略丑) ...