Codeforces Round #922 (Div. 2) ABCD
A. Brick Wall
很直白的贪心,显然就是全放横着的砖最优,每行中最多能放 \(\lfloor \dfrac{m}{2} \rfloor\) 个,答案为 \(n \cdot \lfloor \dfrac{m}{2} \rfloor\)。
B. Minimize Inversions
\(A : a \ \ \ \ \ xa,xb \ \ \ \ \ b \ \ \ \ \ ya,yb\)
\(B : c \ \ \ \ \ xc,xd \ \ \ \ \ d \ \ \ \ \ yc,yd\)
xa 为 ab 之间小于 a 的个数,ya 为 b 之后小于 a 的个数。
交换前的逆序对数 \(w1 = [(xa + ya) + yb] + [((xc + yc) + yd)]\)。
交换前的逆序对数 \(w2 = [(xb + yb) + ya] + [((xd + yd) + yc)]\)。
若交换后更优,则 \(xa + xc > xb + xd\)。
按照此规律排序能够做到 \(O(n^2\log n)\)。
构造一种方案满足 \(\forall a,\ b,\ c,\ d \ \ \ \ xa + xc \le xb + xd\)。
设 \(cnt\) 为 \(a, b\) 间元素总个数。
显然有 \(\forall x \in [0, cnt]\)。
如果 A 有序,则 \(xa = 0, xb = cnt\)。
此时 \(xc \le cnt + xd\),满足条件。
void solve() {
int n; cin >> n;
vector<int> a(n);
vector<int> b(n);
vector<int> c(n);
for(int &x : a) cin >> x;
for(int &x : b) cin >> x;
iota(All(c), 0);
sort(All(c), [&](int x, int y){
return a[x] < a[y];
});
for(int x : c) cout << a[x] << ' '; cout << '\n';
for(int x : c) cout << b[x] << ' '; cout << '\n';
}
D. Blocking Elements
题意:在 \(a\) 中取 \(m\) 个元素,将原数组划分为 \(m + 1\) 个子段(可以为空),问 \(m\) 个元素和与子段和中的最大值最小为多少。
二分答案。
考虑 \(f[i]\) 表示取第 \(i\) 个元素,且在前 \(i\) 个中取出元素和的最小值。
\]
\(sum\) 为前缀和。
单调队列 \(O(n)\) 维护即可。
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); ++ i)
#define per(i, a, b) for(int i = (a); i >= (b); -- i)
#define pb emplace_back
#define All(X) X.begin(), X.end()
using namespace std;
using ll = long long;
constexpr int N = 1e5 + 5;
ll n, a[N], f[N];
int q[N], hh, tt;
bool check(ll v) {
ll ans = 1e15;
q[0] = 0;
hh = tt = 0;
rep(i, 1, n) {
while(hh <= tt && a[i - 1] - a[q[hh]] > v) ++ hh;
f[i] = a[i] - a[i - 1] + f[q[hh]];
if(a[n] - a[i] <= v) ans = min(ans, f[i]);
while(hh <= tt && f[i] <= f[q[tt]]) -- tt;
q[++ tt] = i;
}
return ans <= v;
}
void solve() {
cin >> n;
rep(i, 1, n) cin >> a[i], a[i] += a[i - 1];
ll l = 0, r = 1e15;
while(l < r) {
ll mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
cout << l << '\n';
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
cin >> T;
while(T --) solve();
return 0;
}
Codeforces Round #922 (Div. 2) ABCD的更多相关文章
- Codeforces Round #258 (Div. 2)[ABCD]
Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)
比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...
- Codeforces Round #427 (Div. 2)——ABCD
http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #412 (Div. 2)ABCD
tourist的剧毒contest,题干长到让人不想做... A.看不太懂题意直接看下面input output note n组里有两数不一样的一组就rated 否则单调不增为maybe,否则unra ...
- Codeforces Round #315 (Div. 2) (ABCD题解)
比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #352 (Div. 2) ABCD
Problems # Name A Summer Camp standard input/output 1 s, 256 MB x3197 B Different is Good ...
随机推荐
- 金仓数据库kbcrypto 插件实现sm加密算法
首先介绍一下sm4 算法 SM4 算法是对称加密算法,国标 GB/T 32907 对 SM4 对称加密算法进行了详细描述.SM4 算法密钥长度固定为128bit,加密解密采用相同的密钥,加解密速度较快 ...
- 【毕业设计】基于springboot的大学生综合素质测评管理系统
前言 [毕业设计]大学生综测管理系统 个人主页:@MIKE笔记 文章专栏:毕业设计源码合集 联系博主: wx:mikenote 毕设目录 项目名 文章地址 下载 1.基于springboot的大学生综 ...
- jQuery AJAX 常见属性
1 jQuery.ajax(...) 2 部分参数: 3 url:请求地址 4 type:请求方式,GET.POST(1.9.0之后用method) 5 headers:请求头 6 data:要发送的 ...
- 如何自动申请免费的HTTPS证书?
在购买域名的时候我相信很多人都遇到了对于证书的问题,之前我也是使用阿里云的免费一年的证书,那时候感觉还好,一年更换一次,但是近期阿里云对于证书的过期时间直接砍到了三个月!让我难以接受,所以我在想吧他直 ...
- #线段树,组合计数,二项式定理#CF266E More Queries to Array
洛谷传送门 CF266E传送门 分析 首先区间修改区间查询首选线段树 要找突破口,\((i-l+1)^k\)中\(i\)不是定值, 显然得拆开,而且\(k\)很小,根据二项式定理, \[\sum_{i ...
- 【直播回顾】OpenHarmony知识赋能五期第四课——子系统音频解读
5月12日晚上19点,知识赋能第五期第四节课<OpenHarmony标准系统多媒体子系统之音频解读>,在OpenHarmony开发者成长计划社群内成功举行. 本期课程,由深开鸿资深技术专家 ...
- C 语言注释和变量详解
C 语言中的注释 C语言中可以使用注释来解释代码并使其更具可读性.它还可以在测试替代代码时防止执行. 单行注释 单行注释以两个斜杠 (//) 开头. // 和行末之间的任何文本都会被编译器忽略(不会被 ...
- 第一视角看方法调用时的jvm
关于比较学术的jvm每个内存区域我之前都写过,就不重复赘述了,这里附上链接:https://www.cnblogs.com/gmt-hao/p/13603534.html, https://www.c ...
- RabbitMQ 10 头部模式
头部模式是根据头部信息来决定的,在发送的消息中是可以携带一些头部信息的(类似于HTTP),可以根据这些头部信息来决定路由到哪一个消息队列中. 定义配置类. import org.springframe ...
- 鸿蒙开发套件之DevEco Profiler助您轻松分析应用性能问题
作者:shizhengtao,华为性能调优工具专家 应用的性能优化一直以来都是开发者所面临的一大难题,在2023HDC大会上全新亮相的HarmonyOS NEXT开发者预览版,其中鸿蒙开发套件Dev ...