#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. python 正则表达式(二)

    下面列举了Python3的所有符号用法,别背,千万别背,用到时来查就行. 字符 含义 . 表示匹配除了换行符外的任何字符注:通过设置 re.DOTALL 标志可以使 . 匹配任何字符(包含换行符) | ...

  2. Runtime Error(ACCESS_VIOLATION)

    1.     while(scanf("%d",&n) )// 错误,会出现  Runtime Error(ACCESS_VIOLATION) while(scanf(&q ...

  3. Python--基础文件读写操作

    1,open(),对文件进行读写操作之前,要先打开文件,获取文件的句柄: 懒人专用方法,文件打开后不用关闭 with open(r'somefile.txt','r+',encoding='utf8' ...

  4. 【论文笔记】基于图机构的推荐系统:Billion-scale Commodity Embedding for E-commerce Recommendation in Alibaba

    论文:https://arxiv.org/abs/1803.02349    题外话: 阿里和香港理工联合发布的这篇文章,整体来说,还挺有意思的. 刚开始随便翻翻看看结构图的时候,会觉得:这也能发文章 ...

  5. 学习完Spring MVC体会

    学习完spring mvc感觉很不错,万事开头难,付出定有回报,坚持必将成功

  6. C++0X 学习之 auto

    auto并不是一个新关键词,是一个把旧关键词赋予新的作用,新的作用修饰变量声明,指示编译器根据变量的初始化表达式推导变量应有的类型.auto 声明的变量必须“在声明处完成初始化”,编译器才可根据初始化 ...

  7. android:layout_weight的真实含义/android:layout_gravity的条件

    用layout_weight的时候,不要把宽度(或是高度,你想分配weight的那个)设成match_parent. android:layout_weight只适用于LinearLayout and ...

  8. 在Windows下编译WebRTC

    前言 这篇文章的目的在于为你节省生命中宝贵的10小时(甚至更多),或者浪费你10分钟.作为Google更新频繁的大型跨平台基础库,WebRTC的编译一直被人称为噩梦.如果恰巧你偏要在Windows下编 ...

  9. 【转】 Pro Android学习笔记(七一):HTTP服务(5):多线程调用HttpClient

    目录(?)[-] 应用共享HttpClient对象的同步问题 创建共享HttpClient代码 创建共享对象 创建可共享的HttpClient对象 使用共享HttpClient对象的代码 基础代码 修 ...

  10. LVS实战1

    (一).NAT模式:NAT模型:地址转换类型,主要是做地址转换,类似于iptables的DNAT类型,它通过多目标地址转换,来实现负载均衡:特点和要求: 1.LVS(Director)上面需要双网卡: ...