Codeforces Global Round 13 C
C. Pekora and Trampoline
数据范围:数组大小n
:[1,5000][1,5000][1,5000] 元素大小 a[i]
:[1,109][1,10^9][1,109]
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
const int N = 5010;
int a[N], n;
using namespace std;void SetLeft(vector<int>& b, int j) //当数组出现新的1时,去更新该1及相邻的左边的1的跳转点
{b[j] = b[j + 1];for (int i = j - 1; i >= 1; i--){if (a[i] == 1) b[i] = b[i + 1];else return;}
}int main()
{fastio();int t;cin >> t;while (t--){cin >> n;for (size_t i = 1; i <= n; i++) cin >> a[i];ll ans = 0;vector<int> b(n + 2);b[n + 1] = n + 1; //使最后一个元素a[n]为1时跳到n+1(即超出数组范围)for (int i = n; i >= 1; i--){if (a[i] != 1) b[i] = i;else b[i] = b[i + 1];}while (1){int beg = b[1]; //每次从最左端出发(最优性待证明)if (beg > n) break; //此时说明数组全为1if (a[beg] > max(n - beg, 1)) //批量处理超出数组范围的部分{ans += a[beg] - max(n - beg, 1); //max函数避免当beg=n时出现0a[beg] = max(n - beg, 1);if (a[beg] == 1) SetLeft(b, beg);continue;}int j = beg, k;while (j <= n){if (a[j] == 1) k = b[j]; //元素为1时快速跳转else k = j + a[j];if (a[j] == 2) SetLeft(b, j); //此时说明将数组出现新的1a[j] = max(a[j] - 1, 1);j = k; }ans++;}cout << ans << "\n";}return 0;
}
Codeforces Global Round 13 C相关推荐
- Codeforces Global Round 13 E. Fib-tree
E. Fib-tree 题意: 给你一棵树,问是不是斐波那契树: 这棵树要满足 1.本身的结点个数为斐波那契数. 2.断掉一条边,变成两棵树,两棵树的大小分别都是斐波那契数. 问能不能通过不断断掉一条 ...
- Codeforces Global Round 13 A-E题解
A 01序列,一个操作对某一位取反,一个操作问你当前第k大是多少 维护一个当前最后一个1所在排名 #include <cstdio> using namespace std; const ...
- Codeforces Global Round 1 晕阙记
Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- Codeforces Global Round 14 F. Phoenix and Earthquake 思维 + 并查集
传送门 文章目录 题意: 思路: 题意: 给你nnn个点,mmm条边,限制xxx,每个点都有沥青aia_iai,定义合并两个点即两点之间有边且au+av≥xa_u+a_v\ge xau+av≥x ...
- Codeforces Global Round 1
Codeforces Global Round 1 题解:The Editorial of the First Codeforces Global Round A:其实mod 2计算一下就行了 B:删 ...
- 【Codeforces Global Round 23】B. Rebellion
Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...
- Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)
题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...
- codeforces global round 23
constest :codeforces global round 23 contest time:2022.10.16 contest grade: 2800 contest rating chan ...
最新文章
- 数据预处理常用技巧 | 数据分析中如何处理缺失值?(文末福利)
- [转载] 淘宝旺铺扶植版如何添加背景音乐
- html表单验证元素必填,AngularJS表单验证:向用户指示必填字段
- 原创:centos7.1下 ZooKeeper 集群安装配置+Python实战范例
- 启动计算机引导win10,教您win10引导项丢失怎么办
- 纯做技术是自娱自乐 抛开技术做技术才是出路
- select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET
- JavaScript常用算法
- OpenCV3学习(2.2)——图像Mat矩阵操作与常用函数
- basename函数 中文问题
- 设置元素浮动的几种方式
- rem + vw 布局
- c语言 归一化图片大小,OpenCV学习笔记(1)——resize函数实现图像大小归一化
- Android各版本号及其英文别名
- Arduino ide配置esp32硬件支持(配置esp32的arduino开发环境)
- QT图形显示和处理5
- 上海车牌拍卖突破7.5万元
- 地理信息系统(GIS)的发展历程
- Pony.ai 自动驾驶
- 从自己挖的坑里爬出来