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\) 个中取出元素和的最小值。

\[f[i] = a[i] + min(f[j]) \ \ \ \ (sum[i - 1] - sum[j] \le mid)
\]

\(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的更多相关文章

  1. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  4. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  6. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...

  7. Codeforces Round #427 (Div. 2)——ABCD

    http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...

  8. Codeforces Round #412 (Div. 2)ABCD

    tourist的剧毒contest,题干长到让人不想做... A.看不太懂题意直接看下面input output note n组里有两数不一样的一组就rated 否则单调不增为maybe,否则unra ...

  9. Codeforces Round #315 (Div. 2) (ABCD题解)

    比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...

  10. Codeforces Round #352 (Div. 2) ABCD

    Problems     # Name     A Summer Camp standard input/output 1 s, 256 MB    x3197 B Different is Good ...

随机推荐

  1. JS服务端技术—Node.js知识点

    [版权声明]未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) https://www.cnblogs.com/cnb-yuchen/p/18031964 出自[进步*于辰的博客] 目录 1.NP ...

  2. Kubernetes客户端认证(三)—— Kubernetes使用CertificateSigningRequest方式签发客户端证书

    1.概述 在<Kubernetes客户端认证(一)-- 基于CA证书的双向认证方式>和<Kubernetes客户端认证(二)-- 基于ServiceAccount的JWTToken认 ...

  3. java基础 韩顺平老师的 面向对象(高级) 自己记的部分笔记

    373,类变量引出 代码就提到了问题分析里的3点 package com.hspedu.static_; public class ChildGame { public static void mai ...

  4. Docker技术全景:推动云原生架构的关键力量

    本文深入探讨了Docker的发展历程.核心技术.在云服务中的应用以及其庞大生态系统.通过分析Docker如何革新容器化技术.加速云服务的发展,并构建一个多元化的生态系统,本文揭示了Docker在当代云 ...

  5. KingbaseES V8R6 集群运维案例--备库timeline not contain minimum recovery point故障

    ​ 案例现象: KingbaseES V8R6集群备库启动后,加入集群失败,sys_log日志信息提示,如下图所示: 适用版本: kingbaseES V8R6 一.问题分析 在timeline对应的 ...

  6. Flume入门操作

    十一.Flume 1)开启Flume的监控端口 bin/flume-ng agent -c conf/ -n a1 -f job/flume-netcat-logger.conf -Dflume.ro ...

  7. 5W1H聊开源之Who/When/Where——谁在何时何地“发明”了开源?

    美国政治传播学家拉斯韦尔提出了5W传播模式,经过后人的不断运用和发展总结,形成了一套逐渐成熟的"5W1H"体系,即:对选定的项目.工序或操作,都要从原因(何因Why).对象(何事W ...

  8. #cdq分治,树状数组#洛谷 4169 [Violet]天使玩偶/SJY摆棋子

    题目 分析 首先如果不会\(\text{K-DTree}\)的话,那就用CDQ分治吧 这题首先要去绝对值,分四种情况讨论, 只判断左下角的点 然后考虑怎样求最大值,这里采用树状数组,反正只是单点修改单 ...

  9. Python - 字典4

    复制字典 您不能简单地通过输入 dict2 = dict1 来复制一个字典,因为 dict2 只会成为 dict1 的引用,对 dict1 的更改也会自动应用于 dict2. 有多种方法可以复制字典, ...

  10. Numpy的数组对象

    数组对象 NumPy 最重要的一个特点是其 N 维数组对象 ndarray,它是一系列同类型数据的集合,从0 开始进行集合中元素的索引:ndarray 对象是用于存放同类型元素的多维数组,其中的每个元 ...