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 ...
随机推荐
- KingbaseES 与 Oracle XML 语法比较
KingbaseES 内置支持 XML 相关操作,也可以通过xml2 插件进行扩展支持.以下通过例子介绍 KingbaseES XML 与Oracle 在用法上存在的一些差异. 一.数据准备 crea ...
- #Dijkstra#洛谷 4943 密室
题目 分析 考虑答案只可能是分别到或者哈利一个人到两个房间, 那么在罗恩的时候先不建不可走的边,等到哈利走的时候再建边 代码 #include <cstdio> #include < ...
- Python从 requirements.txt 安装库
pip install -r requirements.txt
- EZHTTP(一键安装Nginx Apache PHP MySQL Memcached Pureftpd)安装【测试ing】
EZHTTP(一键安装Nginx Apache PHP MySQL Memcached Pureftpd)安装 [复制链接] 本帖最后由 梁国平 于 2014-2-11 22:47 编辑 简介 ...
- 免费报表工具零代码零基础轻松搞定 web 报表
话说,能制作清单式报表的方式有千千万: 骨灰级的 Excel 控,如果能轻车熟路驾驭 VBA,也能玩出各种花来,再不济借助图表插件外援也能秒杀一众小白选手: 传说中的编程控,只要需求明确没什么做不了的 ...
- python中的赋值、浅拷贝、深拷贝的区别
赋值: 可变类型:赋值前后id不会变,赋值后的数据会随源数据变化: 不可变类型:赋值前后id不会变,赋值后的数据不会随源数据变化: 浅拷贝(copy): 可变类型:copy前后id会变,可变类型中存储 ...
- 国产gowin开发板GW1NR-9K的PSRAM使用说明
开发板子采用GW1NNR-LV9LQ144PC6/I5 FPGA器件.具有低功耗,瞬时启动,高安全性,低成本,方便扩展等特点.本开发板价格价格便宜,板子扩张性容易,帮助用户比较快速进入国产FPGA学习 ...
- Consul的服务注册与发现(简单介绍)
Consul的注册中心的安装及配置 1.consul下载 2.开发模式启动consul consul agent -dev 3.验证测试 通过以下地址可以访问Consul的首页: http://loc ...
- 力扣585(MySQL)-2016年的投资(中等)
题目: 写一个查询语句,将 2016 年 (TIV_2016) 所有成功投资的金额加起来,保留 2 位小数. 对于一个投保人,他在 2016 年成功投资的条件是: 他在 2015 年的投保额 (TIV ...
- HarmonyOS NEXT应用开发之深色模式适配
介绍 本示例介绍在开发应用以适应深色模式时,对于深色和浅色模式的适配方案,采取了多种策略如下: 固定属性适配:对于部分组件的颜色属性,如背景色或字体颜色,若保持不变,可直接设定固定色值或引用固定的资源 ...