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 ...
随机推荐
- 【FastDFS】面试官:如何实现文件的大规模分布式存储?(全程实战)
写在前面 在<[FastDFS]小伙伴们说在CentOS 8服务器上搭建FastDFS环境总报错?>一文中,详细的介绍了如何在CentOS 8服务器行搭建FastDFS环境.在生产环境中, ...
- KingbaseES数据库-生产环境慢查询性能优化案例
一.背景 在生产环境中,慢查询不仅影响系统.业务的正常处理.同时严重影响用户的使用感受. 二.表相关信息 2.1 表结构及索引: Table "yktcore.t_dtl_ymt" ...
- mybatis添加maven依赖
1 <dependencies> 2 <!--导入Mybatis依赖包--> 3 <dependency> 4 <groupId>org.mybatis ...
- 企业数据清洗项目实践day1
今天先把国标excel表的数据在Python里转化成了字典类型, 暂时定共分为四层,层层分类. 代码 1 def std_excel(): 2 dict={"A":{"0 ...
- Rust 实现日志记录功能
目录 log 日志库标准 简单示例 使用方法 库的开发者 应用开发者 日志库开发者 使用 log4rs 添加依赖 配置文件 运行项目 参考文章 log 日志库标准 log 是 Rust 的日志门面库, ...
- 【WCH以太网接口系列芯片】CH9121\9120、CH395\392以太网系列芯片的硬件电路注意事项
本篇基于沁恒微电子官方的以太网接口芯片的DEMO参考原理图进行分析,对一些注意事项进行标注,如果硬件设计上出现问题可以对照参考. CH912x系列: 1.CH9121:建议设计中可以将31脚RUN脚预 ...
- #排列组合#CF1081C Colorful Bricks
题目 一共 \(n\) 块砖排成一排,把每块砖涂成 \(m\) 种颜色中的一种, 其中恰有 \(k\) 块颜色与其左边的那块砖不同(不包括第一块),问涂色方案数,对 \(998244353\) 取模. ...
- SQL 中的 NULL 值:定义、测试和处理空数据,以及 SQL UPDATE 语句的使用
SQL NULL 值 什么是 NULL 值? NULL 值是指字段没有值的情况.如果表中的字段是可选的,那么可以插入新记录或更新记录而不向该字段添加值.此时,该字段将保存为 NULL 值.需要注意的是 ...
- 使用IDEA直接连接数据库报错:Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.
错误详情:使用IDEA直接连接数据库报错:Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' ...
- openGauss/MogDB数据库安装部署之xlog目录设置
openGauss/MogDB 数据库安装部署之 xlog 目录设置 本文出处:https://www.modb.pro/db/176915 关于 xlog xlog 文件是一个记录事务日志的文件,它 ...