C

把 \(a,b\) 全拆开然后比较即可(因为分裂和合并是互逆的)

注意开 long long .

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
int n, m, k;
vector<pii> a, b, c, d;
inline void solve()
{
a.clear(); b.clear(); c.clear(); d.clear();
scanf("%d%d", &n, &k);
for (int i=1, x; i<=n; i++)
{
scanf("%d", &x);
int c = x;
while (!(c % k)) c /= k;
int cc = x / c;
a.emplace_back(make_pair(c, cc));
}
int l = a.size();
for (int i=1; i<l; i++)
if (a[i].first == a[i-1].first){a[i].second += a[i-1].second; a[i-1].second = 0;}
for (pii x : a) if (x.second) c.emplace_back(x);
scanf("%d", &m);
for (int i=1, x; i<=m; i++)
{
scanf("%d", &x);
int c = x;
while (!(c % k)) c /= k;
int cc = x / c;
b.emplace_back(make_pair(c, cc));
}
l = b.size();
for (int i=1; i<l; i++)
if (b[i].first == b[i-1].first){b[i].second += b[i-1].second; b[i-1].second = 0;}
for (pii x : b) if (x.second) d.emplace_back(x);
if (c == d) puts("Yes");
else puts("No");
}
int main()
{
int T; scanf("%d", &T);
while (T--) solve();
return 0;
}

D

两种想法 .

第一种是类似笛卡尔树,显而易见一段区间内的最大值和最小值必然被经过,于是分治即可,\(O(n)\) .

第二种是贪心,令 \(r_i\) 表示最大的 \(p\) 满足 \(\forall t\in(i,p],a_t<a_i\),这个可以直接用一个栈维护或者二分 + ST 表 .

然后每个 \(i\) 的转移点必然是 \(\displaystyle \underset{j\in(i,r_i]}{\arg\min}\{a_j\}\)(cnblogs 竟然不支持 \argmin),直接 ST 表找即可 .

这样的时间复杂度是 \(O(n\log n)\) .

然而 EI 大师写了一份暴力跳的就过了 /yun 复杂度竟然是对的 .

魔改 EI 版:

using namespace std;
constexpr int N = 3e5 + 233, P = 1e9 + 7;
typedef pair<int, int> pii;
typedef long long ll;
int n, a[N], st[N], nxtL[N], nxtS[N]; // st --> stack
inline void solve()
{
scanf("%d", &n);
for (int i=1; i<=n; i++) scanf("%d", a+i);
int sz = 0; st[0] = n+1;
for (int i=n; i; i--)
{
while (sz && (a[st[sz]] < a[i])) --sz;
nxtL[i] = st[sz];
st[++sz] = i;
}
sz = 0;
for (int i=n; i; i--)
{
while (sz && (a[st[sz]] > a[i])) --sz;
nxtS[i] = st[sz];
st[++sz] = i;
}
int p = 1, step = 0, nxt = 114514;
while (p < n)
{
if (a[p] < a[p+1])
{
nxt = p;
while (nxtL[nxt] < nxtS[p]) nxt = nxtL[nxt];
p = nxt;
}
else
{
nxt = p;
while (nxtS[nxt] < nxtL[p]) nxt = nxtS[nxt];
p = nxt;
}
++step;
} printf("%d\n", step);
}
int main()
{
int T; scanf("%d", &T);
while (T--) solve();
return 0;
}

E

首先读题得答案是

\[ans=\sum_{i=0}^n\sum_{j=0}^{a_i-1}\dbinom{i+j}j
\]

根据平行求和法可得

\[ans=\sum_{i=0}^n\dbinom{i+a_i}{i+1}
\]

预处理逆元直接算即可,时间复杂度 \(O(n+\max\limits_i\{a_i\})\) .


一些说明:

令 \(F_{i,j}\) 表示在 \((i,j)\) 放一个关键点最少操作多少次能把关键点移出白格,于是有转移

\[F_{i,j}=F_{i+1,j}+F_{i,j+1}
\]

可以转换为格路计数问题,于是 \(F_{i,j}\) 就变成了 \((0,0)\) 到 \((i,j)\) 的路径数量 .

于是 \(F_{i,j}=\dbinom{i+j}j\) .

答案即 \(\displaystyle \sum_{i=0}^n\sum_{j=0}^{a_i-1}F_{i,j}
\) .

using namespace std;
const int N = 4e5 + 233, P = 1e9 + 7;
typedef long long ll;
typedef pair<ll, ll> pii;
int n, a[N], fac[N], infac[N];
int qpow(int a, int n)
{
int ans = 1;
while (n)
{
if (n & 1) ans = 1ll * ans * a % P;
a = 1ll * a * a % P; n >>= 1;
} return ans;
}
void init()
{
fac[0] = 1;
for (int i=1; i<N; i++) fac[i] = 1ll * fac[i-1] * i % P;
infac[N-1] = qpow(fac[N-1], P-2);
for (int i=N-2; i>=0; i--) infac[i] = 1ll * infac[i+1] * (i+1) % P;
}
int binom(int n, int m)
{
if (n < m) return 0;
return 1ll * fac[n] * infac[m] % P * infac[n-m] % P;
}
int main()
{
init(); scanf("%d", &n);
for (int i=0; i<=n; i++) scanf("%d", a+i);
int ans = 0;
for (int i=0; i<=n; i++) (ans += binom(i + a[i], i + 1)) %= P;
printf("%d\n", ans);
return 0;
}

G

设原序列为 \(\{A\}\) .

\(f(A)\) 可以表示为线性规划(\(a_0=b_0=0\))

\[\begin{aligned}&\operatorname{minimize}\,\sum_{i=1}^n(a_i+b_i)\\&s.t.\begin{cases}\forall i\in[1,n],x\cdot a_i+y\cdot b_i+x\cdot b_{i-1}+y\cdot a_{i-1}\ge A_i\\y\cdot a_{n-1}+x\cdot b_{n-1}\ge a_n\\\forall i\in[1,n],a_i\ge 0, b_i\ge 0\end{cases}\end{aligned}
\]

的解 .

对偶,得

\[\begin{aligned}&\operatorname{maximize}\,\sum_{i=1}^nA_ix'_i\\&s.t.\begin{cases}\forall i\in[1,n), x\cdot x'_{i}+y\cdot x'_{i+1}\le 1\\\forall i\in[1,n), y\cdot x'_{i}+x\cdot x'_{i+1}\le 1\\\forall i\in[1,n], x'_i\ge 0\end{cases}\end{aligned}
\]

可以证明 \(x'_i\) 的取值只可能是 \(\dfrac 1{\max(x, y)}, \dfrac 1{x+y}, 0\) 三种(具体看官方题解).

于是可以分类 DP,令 \(dp_{i,0/1/2}\) 表示 \(1\dots i\) 的最优解,其中 \(x_i\) 取可以取到的第 \(0/1/2\) 种值 .

预处理出转移矩阵,多组询问只需要线段树维护即可 .

时间复杂度 \(O(n+q\log n)\) .

using namespace std;
const int N = 2e5 + 233;
const double INF = 1e18;
typedef long long ll;
typedef pair<ll, ll> pii;
int n, q, x, y, a[N];
struct Node
{
double dp[3][3];
Node(double n = 0)
{
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
if (i + j <= 2) dp[i][j] = (j ? 1. * n / ((j == 1) ? x + y : y) : 0);
else dp[i][j] = -INF;
}
Node operator + (const Node& rhs) const
{
Node ans;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
{
ans.dp[i][j] = -INF;
for (int k=0; k<3; k++) chkmax(ans.dp[i][j], dp[i][k] + rhs.dp[k][j]);
}
return ans;
}
};
struct SMT
{
#define ls (u << 1)
#define rs (u << 1 | 1)
struct{int l, r; Node s;}tr[4*N];
inline void pushup(int u){tr[u].s = tr[ls].s + tr[rs].s;}
inline void build(int u, int l, int r)
{
tr[u].l = l; tr[u].r = r;
if (l == r){tr[u].s = a[l]; return ;}
int mid = (l + r) >> 1;
build(ls, l, mid); build(rs, mid+1, r);
pushup(u);
}
inline void change(int u, int pos, const Node& v)
{
if (tr[u].l == tr[u].r){tr[u].s = v; return ;}
int mid = (tr[u].l + tr[u].r) >> 1;
if (pos <= mid) change(ls, pos, v);
else change(rs, pos, v);
pushup(u);
}
inline Node query(int u, int l, int r)
{
int L = tr[u].l, R = tr[u].r;
if ((l > R) || (L > r)) return Node();
if ((l <= L) && (R <= r)) return tr[u].s;
return query(ls, l, r) + query(rs, l, r); // 不用单位元 & + 没有交换律
}
#undef rs
#undef ls
}T;
int main()
{
scanf("%d%d%d%d", &n, &q, &x, &y);
if (x > y) swap(x, y);
for (int i=1; i<=n; i++) scanf("%d", a+i);
T.build(1, 1, n);
int opt, x, y;
while (q--)
{
scanf("%d%d%d", &opt, &x, &y);
if (opt == 1) T.change(1, x, y);
else printf("%.15f\n", (T.query(1, x, y) + Node()).dp[0][0]);
} return 0;
}

CF Global Round 21 题解 (CDEG)的更多相关文章

  1. [题解向] CF#Global Round 1の题解(A $\to$ G)

    这里是总链接\(Link\). \(A\) 题意:求\(\sum_{i=1}^{k} a_i\times b^{k-i}\)的奇偶性, \(k = \Theta(n \log n)\) --其实很容易 ...

  2. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  3. Codeforces Global Round 3 题解

    这场比赛让我上橙了. 前三题都是大水题,不说了. 第四题有点难想,即使想到了也不能保证是对的.(所以说下面D的做法可能是错的) E的难度是 $2300$,但是感觉很简单啊???说好的歪果仁擅长构造的呢 ...

  4. Codeforces Global Round 4 题解

    技不如人,肝败吓疯…… 开场差点被 A 题意杀了,幸好仔细再仔细看,终于在第 7 分钟过掉了. 跟榜.wtf 怎么一群人跳题/倒序开题? 立刻紧张,把 BC 迅速切掉,翻到了 100+. 开 D.感觉 ...

  5. cf div2 round 688 题解

    爆零了,自闭了 小张做项目入职字节 小李ak wf入职ms 我比赛爆零月薪3k 我们都有光明的前途 好吧,这场感觉有一点难了,昨天差点卡死在B上,要不受O爷出手相救我就boom zero了 第一题,看 ...

  6. Codeforces Global Round 16题解

    E. Buds Re-hanging 对于这个题该开始还是没想法的,但这显然是个思维题,还是要多多动手推样例,实践一下. 简化题意:给定一个有根树,规定某个点为树干,当且仅当这个点不是根,且这个点至少 ...

  7. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  8. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  9. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

随机推荐

  1. 基于DEM的坡度坡向分析

    坡度坡向分析方法 坡度(slope)是地面特定区域高度变化比率的量度.坡度的表示方法有百分比法.度数法.密位法和分数法四种,其中以百分比法和度数法较为常用.本文计算的为坡度百分比数据.如当角度为45度 ...

  2. CSAPP 之 AttackLab 详解

    前言 本篇博客将会介绍 CSAPP 之 AttackLab 的攻击过程,利用缓冲区溢出错误进行代码注入攻击和 ROP 攻击.实验提供了以下几个文件,其中 ctarget 可执行文件用来进行代码注入攻击 ...

  3. PostgreSQL 13支持增量排序(Incremental Sorting)

    PostgreSQL 13支持增量排序(Incremental Sorting) PostgreSQL 13一个重要的功能是支持增量排序,使用order by 时可以加速排序,SQL如下 select ...

  4. django框架12

    内容概要 csrf相关装饰器 基于中间件思想编写项目 auth认证模块 auth模块方法大全 auth扩展表字段 项目开发流程 bbs数据表分析 内容详情 csrf相关装饰器 基于中间件思想编写项目 ...

  5. Linux 运行升讯威在线客服系统:同时支持 SQL Server 和 MySQL 的实现方法

    前段时间我发表了一系列文章,开始介绍基于 .net core 的在线客服系统开发过程. 有很多朋友一直提出希望能够支持 MySQL 数据库,考虑到已经有朋友在用 SQL Server,我在升级的过程中 ...

  6. 技术分享 | app自动化测试(Android)--元素定位方式与隐式等待

    原文链接 元素定位是 UI 自动化测试中最关键的一步,假如没有定位到元素,也就无法完成对页面的操作.那么在页面中如何定位到想要的元素,本小节讨论 Appium 元素定位方式. Appium的元素定位方 ...

  7. BUUCTF-你竟然赶我走

    你竟然赶我走 首先看到这个图片没啥感觉,直接用16进制打开了.拖到最下面果然有flag flag{stego_is_s0_bor1ing}

  8. Idea创建文件夹自动合成一个

    在idea中创建文件夹时,它们总是自动合成一个,如下图: 文件夹自动折叠真的很影响效率,可能会引发一些不经意的失误 解决方法: 取消这个地方的勾选 这样就可以正常创建文件夹了

  9. go Cobra命令行工具入门

    简介 Github:https://github.com/spf13/cobra Star:26.5K   Cobra是一个用Go语言实现的命令行工具.并且现在正在被很多项目使用,例如:Kuberne ...

  10. Android multiple back stacks导航的几种实现

    Android multiple back stacks导航 谈谈android中多栈导航的几种实现. 什么是multiple stacks 当用户在app里切换页面时, 会需要向后回退到上一个页面, ...