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. Oracle数据库对比MySQL

    基本 Oracle默认端口:1521 默认用户:system MySQL默认端口:3306 默认用户:root 连接MySQL: mysql -u root -p -- 输入密码 -- 查询所有数据库 ...

  2. 第十三届蓝桥杯大赛软件赛省赛【Java 大学B 组】试题A: 星期计算

    1 public class Test { 2 public static void main(String args[]) { 3 double res=20.0; 4 for(int i=0 ;i ...

  3. Echarts世界地图和网页表格数据交互联动

    html布局: 1 <div class="column"> 2 <div class="panel bl bar1"> 3 <d ...

  4. #单调栈#CodeChef Meteor

    METEORAK 分析 设 \(dp[l][r]\) 表示第 \(l\) 到 \(r\) 行的答案,可以发现它由 \(f[l][r],dp[l][r+1],dp[l+1][r]\) 转移而来. 关键就 ...

  5. #prim,gcd#UVA12716 GCD XOR&洛谷 1550 [USACO08OCT]Watering Hole G

    UVA12716 GCD XOR 题目 \[\sum_{i=1}^{n}\sum_{j=i}^n[\gcd(i,j)==i\;xor\;j] \] 分析 首先来证明一下如果上式成立,那么\(i\;xo ...

  6. #Multi-SG#HDU 5795 A Simple Nim

    题目 有\(n\)堆石子,每次可以从一堆中取出若干个或是将一堆分成三堆非空的石子, 取完最后一颗石子获胜,问先手是否必胜 分析 它的后继还包含了分成三堆非空石子的SG函数,找规律可以发现 \[SG[x ...

  7. OpenHarmony系统能力SystemCapability使用指南

    一.概述 1.系统能力与 API SysCap,全称SystemCapability,即系统能力,指操作系统中每一个相对独立的特性,如蓝牙,WIFI,NFC,摄像头等,都是系统能力之一.每个系统能力对 ...

  8. CircleIndicator组件,使指示器风格更加多样化

    UI界面是应用程序可视化必不可少的部分.设计精致的UI界面可以使得整个可视化应用程序给用户留下深刻的印象,是改善用户界面体验最直接的方式. ArkUI开发框架为开发者提供了丰富的UI原生组件,如Nav ...

  9. Qt操作sqlite数据库

    代码讲解: 1.检查数据库文件是否存在,如果不存在就创建数据库文件 2.创建 person 表(等下的操作就是操作这个表) 3.查询出 person 表中所有的数据,并显示出来 Pro 文件 添加 S ...

  10. 使用Python-psycopg访问postgres、openGauss、MogDB

    摘要 Psycopg 是一种用于执行 SQL 语句的 PythonAPI,可以为 PostgreSQL.GaussDB 数据库提供统一访问接口,应用程序可基于它进行数据操作.Psycopg2 是对 l ...