【Codeforces Round #450 (Div. 2) C】Remove Extra One
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
枚举删除第i个数字。
想想删掉这个数字后会有什么影响?
首先,如果a[i]如果是a[1..i]中最大的数字
那么record会减少1.
其次。
对于任意一个a[j],且i则我们可以预处理一下。
遍历a
对于a[i]
看看它是不是a[1..i]中第二小的数字。
那么标记cnt[a[1..i]中最大的数字]++;
然后再重新遍历一遍a;
对于a[i]
还是看它是不是a[1..i]中第二小的数字。
如果是的话,标记cnt[a[1..i]中最大的数字]--;
同时temp = cnt[a[i]] - (a[i]==max{a[1..i]}?1:0);
这里的temp就是去掉数字a[i]后,record的变化量.
取temp最大的a[i]就好
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
map<int,int> dic;
int n,a[N+10],ma[N+10],ma2[N+10];
int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i];
ma[1] = a[1];
ma2[1] = -1;
for (int i = 2;i <= n;i++){
if (a[i]>ma[i-1]){
ma2[i] = ma[i-1];
ma[i] = a[i];
}else{
ma[i] = ma[i-1];
if (ma2[i-1]<a[i]){
ma2[i] = a[i];
}else ma2[i] = ma2[i-1];
}
if (a[i]!=ma[i] && a[i]==ma2[i]){
dic[ma[i]]++;
}
}
int tot = -1e6,idx = -1;
for (int i = 1;i <= n;i++){
if (a[i]!=ma[i] && a[i]==ma2[i]) dic[ma[i]]--;
int temp = dic[a[i]];
if (a[i]==ma[i]) temp--;
if (temp>tot){
tot = temp;
idx = a[i];
}else if (temp==tot){
idx = min(idx,a[i]);
}
}
cout << idx << endl;
return 0;
}
【Codeforces Round #450 (Div. 2) C】Remove Extra One的更多相关文章
- 【Codeforces Round #450 (Div. 2) A】Find Extra One
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟. 看看Y左边或右边的点个数是否<=1 [代码] #include <bits/stdc++.h> using ...
- 【Codeforces Round #450 (Div. 2) B】Position in Fraction
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找循环节就好. ->其实可以不用找出来整个循环节. 有找到c就直接输出. 找到了循环节还没找到的话,直接输出无解. [代码] ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- Chromium Graphics : GPU Accelerated Compositing in Chrome
GPU Accelerated Compositing in Chrome Tom Wiltzius, Vangelis Kokkevis & the Chrome Graphics team ...
- JS的解析与执行过程—函数预处理
声明:之所以分为全局预处理与函数预处理,只是为了理解方便,其实在实际运行中二者是不分先后的. 函数预处理阶段与全局预处理的差别: 函数每调用一次,就会产生一个LexicalEnviroment对象,在 ...
- WebAssembly学习(一):认识WebAssembly
WebAssembly作为一门新兴起的技术,在 JavaScript 圈非常的火!人们都在谈论它多么多么快,怎样怎样改变 Web 开发领域,被各大巨头所推广,这篇文章对其做一个简单的了解认识,本文非原 ...
- 树莓派3b+ wifi无线连接
一.配置文件启动wifi 配置 /etc/network/interfaces 文件实现,但在图形界面上并没有wifi图标可以选择,这种方法不够灵活,后面连接其它的wifi都要去修改配置文件 首先打开 ...
- SSH无password登陆配置
摘录一 在192.168.42.142机器上 1)执行:ssh-keygen -t rsa 2)然后拍两下回车(均选择默认) 3)执行: ssh-copy-id -i /root/.ssh/id_rs ...
- es64 const
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [Codeforces558E]A Simple Task 线段树
链接 题意:给定一个长度不超过 \(10^5\) 的字符串(小写英文字母),和不超过5000个操作. 每个操作 L R K 表示给区间[L,R]的字符串排序,K=1为升序,K=0为降序. 最后输出最终 ...
- Zabbix + Grafana
Grafana 简介 Grafana自身并不存储数据,数据从其它地方获取.需要配置数据源 Grafana支持从Zabbix中获取数据 Grafana优化了图形的展现,可以用来做监控大屏 Grafana ...
- Ansible学习记录五:PlayBook学习
0.介绍 Playbooks 是 Ansible 管理配置.部署应用和编排的语言,可以使用 Playbooks 来描述你想在远程主机执行的策略或者执行的一组步骤过程等 类似于一组任务集,定义好像项目, ...
- 洛谷——P2695 骑士的工作
https://www.luogu.org/problem/show?pid=2695 题目背景 你作为一个村的村长,保卫村庄是理所当然的了.今天,村庄里来了一只恶龙,他有n个头,恶龙到处杀人放火.你 ...