E. Increasing by Modulo
E. Increasing by Modulo
题意
一个长度为 n n n 的数组a
,每次可以选择一部分 a i a_i ai ,使得 a i = ( a i + 1 ) m o d m a_i = (a_i + 1)\space mod \space m ai=(ai+1) mod m ,求最少需要几次操作使得这个数组单调不减。
题解
- 二分操作次数;
- 每个数都有 m i d mid mid 次操作机会,保证单调递增的同时尽量让当前的数尽可能的小。
代码
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, a, n) for (int i = n; i >= a; --i)
#ifdef LOCAL
#include "Print.h"
#define de(...) W('[', #__VA_ARGS__,"] =", __VA_ARGS__)
#else
#define de(...)
#endif
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 5;
int n, m, a[maxn];
bool judge(int mid) {int mx = 0;rep(i, 1, n) {if (a[i] > mx) {if (mx + m - a[i] > mid) mx = a[i];} else {if (mx - a[i] > mid) return 0;}}return 1;
}
int solve() {scanf("%d%d", &n, &m);rep(i, 1, n) scanf("%d", &a[i]);int l = 0, r = m;while (l < r) {int mid = (l + r) >> 1;if (judge(mid)) r = mid;else l = mid + 1;}printf("%d\n", r);return 0;
}
int main() {#ifdef LOCALfreopen("in.in", "r", stdin);freopen("out.out", "w", stdout);
#endifint T = 1;// scanf("%d", &T);while (T--) solve();return 0;
}
E. Increasing by Modulo相关推荐
- CF1169C. Increasing by Modulo(二分)
linkkkkk 题意: 给出 n , k n,k n,k和数组 a a a,每次都可以选出若干个元素让他们的值变成 ( a i + 1 ) m o d k (a_i+1)\mod k (ai+1) ...
- php 顺时针打印矩阵,这题
浅谈狄利克雷相关题目套路2021-03-25 21:58:20 啥都不知道,被yyc D爆了/kk 扔道题 P2714 四元组统计 乍一看,就想推式子,结果发现自己是个憨批 莫反就两条式子 考虑第二种 ...
- Codeforces Round #716 (Div. 2) C. Product 1 Modulo N
problem C. Product 1 Modulo N time limit per test1 second memory limit per test256 megabytes inputst ...
- [WARNING] unable to add QUERY_STRING=XXXX to uwsgi packet, consider increasing buffer size
1. 问题现象 在用 flask uwsgi api 报文发送 GET 请求时,请求参数的 value 值 "XXX" 太长时,会报下面的错误. [WARNING] unable ...
- LeetCode 300. Longest Increasing Subsequence--O(n log n)--Java,C++,Python解法
题目地址: Given an unsorted array of integers, find the length of longest increasing subsequence. Exampl ...
- LeetCode 673. Number of Longest Increasing Subsequence--O(N log N )--Java,C++,Python解法
题目地址:Number of Longest Increasing Subsequence - LeetCode 做这道题目前建议先做:Longest Increasing Subsequence - ...
- LeetCode 674. Longest Continuous Increasing Subsequence--python,Java,C++解法
此题链接:Longest Continuous Increasing Subsequence - LeetCode Given an unsorted array of integers, find ...
- HPU第三次积分赛-D:Longest Increasing Subsequence(DP)
Longest Increasing Subsequence 描述 给出一组长度为n的序列,a1,a2,a3,a4...an, 求出这个序列长度为k的严格递增子序列的个数 输入 第一行输入T ...
- LeetCode-334. Increasing Triplet Subsequence
Description: Given an unsorted array return whether an increasing subsequence of length 3 exists or ...
最新文章
- 开源,是一种新的平台之战
- Windows中打开方式...无法指定程序的解决办法
- 软件项目管理0824:标书中疫情条款
- /etc/shadow文件
- 低代码从技术走向产品,用友发布自动化设计工具“码前”
- es6 什么是async函数
- 程序员怒斥:虎牙HR真奇葩,通知我面试,又何必当面羞辱我一番?
- [ 转载 ] Handler详解
- 中国科学院沈阳计算机夏令营,中国科学院沈阳计算技术研究所2018年推免夏令营通知...
- 常用命令之svn命令
- 骑士CMS01 74cms v4.2.111 后台getshell漏洞复现
- 教你如何用通道来快速抠图的方法
- 少年宫计算机活动总结改进措施,少年宫乒乓球的活动总结
- 第一节 细胞是生命活动的基本单位
- iOS Technical Support 苹果技术支持
- 计算2个GPS坐标的距离
- 地球引擎中级教程——地球引擎对象(含练习)
- K8S Yaml 详细说明及简单样例
- 【张朝阳的物理课笔记】 2. 能量守恒,动量守恒,第二宇宙速度
- Scala入门_开发环境安装
热门文章
- Vue出现弹出层时,禁止底部页面跟随滑动
- SCU - 4573 和 POJ 3904 Sky Code 【思维 + 容斥定理 or 反演】
- 八道经典的面试链表题--------快乐人的java巩固日记[1]
- DCQCN+QCN+DCTCP
- 父子进程之间的共享资源
- grep命令Binary file
- Python项目实战学习案例--股票模拟交易系统
- 【Python常见面试题】统计字符串中 n 的出现次数
- php判断图片有没有ps过,鉴别P图,如何鉴别图片是否被P过
- openGL包含gl.h/glu.h/glaux.h/glut.h/报错