Codeforces Round 887 (Div. 2)
C. Ntarsis' Set
(\(1 \leq n,k \leq 2 \cdot 10^5\))
题解:思维 + 二分
- 我们不妨反向考虑
- 由于答案最后一次一定在第一个位置
- 所以答案上一轮一定在第一个空的位置,假设这个位置为\(x\)
- 那么如果说要使得答案在位置\(x\),那么上上一轮答案一定在第\(x\)个空的位置
- 我们可以预处理空位置数量的前缀和
- 然后枚举\(k\)即可,每次枚举二分找到空位置
const int N = 2e5 + 10, M = 4e5 + 10;
int n, k;
int a[N];
int pre[N];
void solve()
{
cin >> n >> k;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
pre[i] = pre[i - 1] + a[i] - a[i - 1] - 1;
}
if (a[1] > 1)
{
cout << 1 << endl;
return;
}
int ans = 1;
for (int i = 1; i <= k; ++i)
{
int p = lower_bound(pre + 1, pre + n + 1, ans) - pre;
ans = a[p - 1] + (ans - pre[p - 1]);
}
cout << ans << endl;
}
Codeforces Round 887 (Div. 2)的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- 后缀数组,SA
主要是 \(O(n\log n)\) 倍增求 SA. (为什么这么短) const int N = 1e6 + 9; int n; int sa[N], sa_tmp[N], rk[N], ork[N ...
- Vue3 比 Vue2 快的体现-第一部分
Vue3 比 Vue2 快的原因 首先体现在 Diff算法的优化上, Vue2 中的 虚拟DOM对比采用全量对比策略,这样的话每次渲染也就把静态dom节点做对比了.在Vue3 中 Diff算法 优化了 ...
- 安全 – CSP (Content Security Policy)
前言 之前讲过 CSRF.防 Cookie hacking 的. 也介绍过防 XSS 的 HtmlSanitizer. 今天再介绍 CSP. 参考 Content Security Policy 介绍 ...
- JavaScript Library – Swiper
前言 官网已经有很好的教程了, 这篇只是记入一些我用过的东西和冷门知识. 参考 官网安装 官网 Demo 安装 yarn add swiper JS import Swiper from 'swipe ...
- CSS & JS Effect – Hamburger Menu
效果 参考: Youtube – Responsive Navigation Menu Bar + Hamburger Menu Toggle - Only with CSS Youtube – Ma ...
- SQL Management studio copy paste result out (string_agg line break)
refer : https://stackoverflow.com/questions/59283754/string-agg-with-line-break string agg char(10) ...
- 【墨天轮专访第四期】华为云GaussDB苏光牛:发挥生态优势,培养应用型DBA
导读: 随着5G互联网时代的来临,各行各业对于数据库的依赖程度也在逐步提高.由于国内在数据库行业的发展起步较晚,数据库的市场份额长期被Oracle,微软等美国公司所控制.但是伴随着国内IT技术栈的不断 ...
- vue前端开发仿钉图系列(5)右侧编辑页面的开发详解
右侧编辑页面主要有两个入口,一是添加marker或者线面双击结束的时候,新建数据信息:二是点击底部数据的单元行或者查看编辑或者点击地图上的marker以及线面,编辑相关数据.整理总结不易,如需全部代码 ...
- px 、em、rem 的选取依据
1. px 像素(Pixel).绝对单位.像素px是相对于显示器屏幕分辨率而言的,是一个虚拟长度单位,是计算机系统的数字化图像长度单位,如果 px要换算成物理长度,需要 指定精度 DPI. 2. em ...
- Exchange限制邮箱用户每天/每分钟的发送邮件数量和速率
Exchange限制邮箱用户每天/每分钟的发送邮件数量和速率 近期遇到部分Exchange客服反馈内部邮箱账号密码被盗,给内部其他同事和外部邮箱发送大量钓鱼和诈骗邮件:对公司造成很大负面影响和经济损失 ...
