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. 线上gc问题-SpringActuator的坑

    整体复盘: 一个不算普通的周五中午,同事收到了大量了cpu异常的报警.根据报警表现和通过arthas查看,很明显的问题就是内存不足,疯狂无效gc.而且结合arthas和gc日志查看,老年代打满了,gc ...

  2. C++设计模式 - 抽象工厂(Abstract Factory)

    对象创建模式 通过"对象创建" 模式绕开new,来避免对象创建(new)过程中所导致的紧耦合(依赖具体类),从而支持对象创建的稳定.它是接口抽象之后的第一步工作. 典型模式 Fac ...

  3. OpenHarmony 分布式硬件关键技术

    本文转载自 OpenHarmony TSC 官方微信公众号<峰会回顾第8期 | OpenHarmony 分布式硬件关键技术> 演讲嘉宾 | 李   刚 回顾整理 | 廖   涛 排版校对  ...

  4. SQL 中的 NULL 值:定义、测试和处理空数据,以及 SQL UPDATE 语句的使用

    SQL NULL 值 什么是 NULL 值? NULL 值是指字段没有值的情况.如果表中的字段是可选的,那么可以插入新记录或更新记录而不向该字段添加值.此时,该字段将保存为 NULL 值.需要注意的是 ...

  5. pprof - 在现网场景怎么用

    如何使用 pprof 来定位现网 Golang 问题,已经是一名 Gopher 所需要掌握的必备技能了.我们在实际工作中也经常使用它来定位现网问题.网上有很多文章来描述 pprof 的使用,但是实际的 ...

  6. 【FAQ】HarmonyOS SDK 闭源开放能力 —Push Kit

    1.问题描述 升级到4.0.0.59版本后,通过pushService.getToken获取华为的token时报如下错误:Illegal application identity. 解决方案 Mate ...

  7. Linux获取摄像头VID,PID的两种方式

    第一种方式,是直接查询设备的vid.pid文件,来获取vid,pid 第二种方式,是查询设备信息,自己去解析对应的vid和pid 正常情况下,第一种方式就可以了,但是今天遇到一个ARM架构的kylin ...

  8. 教你构建一个优秀的SD Prompt

    构建一个优秀的Prompt 在使用Stable Diffusion AI时,构建一个有效的提示(Prompt)是至关重要的第一步.这个过程涉及到创造性的尝试和对AI行为的理解.这里我会对如何构建一个好 ...

  9. DevEco Studio 3.1差异化构建打包,提升多版本应用开发效率

     原文:https://mp.weixin.qq.com/s/8XtgZ-k0mGXCjKHfSXFoOg,点击链接查看更多技术内容.     HUAWEI DevEco Studio是开发Harmo ...

  10. Spring Cloud Sleuth:分布式请求链路跟踪

    Spring Cloud Sleuth:分布式请求链路跟踪 SpringCloud学习教程 SpringCloud Spring Cloud Sleuth 是分布式系统中跟踪服务间调用的工具,它可以直 ...