A

直接模拟,注意细节

#include<bits/stdc++.h>
#define ll long long using namespace std; ll p[15] = {1}; void solve() {
ll x;
cin >> x;
int len = 0;
while(x / p[len + 1]) ++ len;
for(int i = 1; i <= len; ++ i) {
ll a = x / p[i];
ll b = x % p[i];
if(b >= p[i - 1] && b > a) {
return cout << a << ' ' << b << '\n', void();
}
}
cout << "-1\n";
} int main() {
for(int i = 1; i <= 10; ++ i) p[i] = p[i - 1] * 10;
int T;
cin >> T;
while(T --) solve();
return 0;
}

B

一道很直观的贪心,用总共的0和1去构造答案,一旦失败,输出答案

void solve() {
string s;
cin >> s;
int cnt[2] = {0, 0};
for(auto ch : s) cnt[1] += ch == '1', cnt[0] += ch == '0';
for(int i = 0; i < s.length(); ++ i) {
if(s[i] == '0') {
if(-- cnt[1] < 0) return cout << s.length() - i << '\n', void();
}
else if(-- cnt[0] < 0) {
return cout << s.length() - i << '\n', void();
}
}
cout << "0\n";
}

C

开一个\(f\)数组统计某一位出现的次数

注意第\(i\)位能被两个\(i - 1\)位合成

检验时从低到高位遍历,同时计算\(f\)数组内部低位对高位的贡献

#include<bits/stdc++.h>

using namespace std;

int f[40], g[40];

bool check(int x) {
memcpy(g, f, sizeof f);
for(int i = 0; i <= 30; ++ i) {
if(x >> i & 1) {
if(g[i]) {
g[i + 1] += (g[i] - 1) / 2;
}
else return 0;
}
else g[i + 1] += g[i] / 2;
}
return 1;
} int main() {
ios :: sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int m;
cin >> m;
while(m --) {
int op, x;
cin >> op >> x;
if(op == 1) ++ f[x];
else {
cout << (check(x) ? "YES" : "NO") << '\n';
}
}
return 0;
}

D. Array Collapse

考虑分治。

设 \(f[l, r]\) 为区间 \([l, r]\) 能够通过操作得到的子序列数。

设 \([l, r]\) 内最小元素的下标为 \(p\)。

如果只考虑 \([l, r]\) 内部的所有情况,因为无论怎么操作 \(a[p]\) 都无法被删除,所以有 \(f[l][r] = f[l][p - 1] \cdot f[p + 1][r]\)。

考虑外部元素对 \(f[l][r]\) 的贡献。

显然,任意一个比 \(a[p]\) 大的数都不能使 \([l,r]\) 内有新的子序列出现。

如果 \(\exists i < l\),\(a[i] < a[p]\),那么我们可以把 \([l,p]\) 删掉,剩下 \([p + 1, r]\),新贡献为 \(f[p + 1][r]\)。

如果 \(\exists j > r\),\(a[j] < a[p]\),那么我们可以把 \([p,r]\) 删掉,剩下 \([l, p - 1]\),新贡献为 \(f[l][p - 1]\)。

如果上述 \(i,j\) 都存在,我们发现两者重复计算了 \([l,r]\) 全部删掉的方案,则 \(f[l][r]\) 减一。

考虑递归边界。

如果 \(l > r\),只存在空集这一种方案。

如果 \(l = r\) 且左右两边至少有一个小于 \(a[l]\) 的元素,则有 \(\phi\) 和 \(a[l]\) 两种,否则只有 \(a[l]\) 一种。

code

其中 \(f[i][j]\) 存的是 \([i, i + (1 << j) - 1]\) 内最小元素的位置。

\(L\_less\) 表示左边是否存在比区间最小值小的元素,\(R\_less\) 表示右边是否存在比区间最小值小的元素。

void init() {
for(int i = 1; i <= n; ++ i) f[i][0] = i;
for(int j = 1; j < 20; ++ j) {
for(int i = 1; i + (1 << j) - 1 <= n; ++ i) {
if(a[f[i][j - 1]] < a[f[i + (1 << j - 1)][j - 1]]) f[i][j] = f[i][j - 1];
else f[i][j] = f[i + (1 << j - 1)][j - 1];
}
}
} int get_pos(int l, int r) {
int len = log2l(r - l + 1);
if(a[f[l][len]] < a[f[r - (1 << len) + 1][len]]) return f[l][len];
else return f[r - (1 << len) + 1][len];
} ll get_val(int l, int r, bool L_less, bool R_less) {
if(l > r) return 1;
if(l == r && (L_less || R_less)) return 2;
if(l == r) return 1; int p = get_pos(l, r);
ll left = get_val(l, p - 1, L_less, true);
ll right = get_val(p + 1, r, true, R_less); ll ret = left * right % P;
if(L_less) ret += right;
if(R_less) ret += left;
if(L_less && R_less) -- ret;
return (ret % P + P) % P;
} void solve() {
cin >> n;
for(int i = 1; i <= n; ++ i) cin >> a[i];
init();
cout << get_val(1, n, 0, 0) << '\n';
}

Educational Codeforces Round 160 (Rated for Div. 2)的更多相关文章

  1. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  3. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  4. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  5. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

随机推荐

  1. Anaconda使用教程

    0 写在前面 以下命令都是在命令行模式下进行操作,macOS和Linux用户可以直接打开Terminal终端,Windows用户如果配置了环境变量则可以直接打开cmd,否则需要打开Anaconda P ...

  2. Linux开发相关命令整理

    1. 反转shell 2. ldd 3. objdump 4. ldconfig 5. telnet 6. nc 7. netstat 8. ss 9. tcpdump 10. lsof 11. st ...

  3. KingbaseES V8R3 运维案例 -- 单实例环境升级用户认证sha-256

    案例说明: 默认KingbaseES V8R3用户认证采用md5加密,有的生产环境对安全要求较高,需要将md5升级到sha-256:如果口令使用 scram-sha-256 设置加密,那么它可以被用于 ...

  4. 使用OHOS SDK构建ogg

    参照OHOS IDE和SDK的安装方法配置好开发环境. 从github下载源码. 执行如下命令: git clone --depth=1 https://github.com/xiph/ogg 进入源 ...

  5. 本周四晚19:00知识赋能第六期第5课丨OpenHarmony WiFi子系统

    OpenAtom OpenHarmony(以下简称"OpenHarmony")开源开发者成长计划项目自 2021 年 10 月 24 日上线以来,在开发者中引发高度关注. 成长计划 ...

  6. 深入学习 XML 解析器及 DOM 操作技术

    所有主要的浏览器都内置了一个XML解析器,用于访问和操作XML XML 解析器 在访问XML文档之前,必须将其加载到XML DOM对象中 所有现代浏览器都有一个内置的XML解析器,可以将文本转换为XM ...

  7. C 语言指针完全指南:创建、解除引用、指针与数组关系解析

    C 语言中的指针 创建指针 我们可以使用引用运算符 & 获取变量的内存地址: int myAge = 43; // 一个 int 变量 printf("%d", myAge ...

  8. opengauss-jdbc问题整理

    opengauss-jdbc问题整理(更新中) 问题 1 jdbc 批量执行 insert 语句时返回结果不符合 Spring jpa 预期 问题描述: jdbc 执行查询时,可以使用prepares ...

  9. (数据科学学习手札159)使用ruff对Python代码进行自动美化

    本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 大家好我是费老师,在日常编写Python代码的过 ...

  10. Unity-PC 端调用SpVoice语音 (文字转语音)

    第一步引用文件 在VS当中 点击项目->添加引用-> 搜索Microsoft Speech Objecet Library 然后选中前面的白色方块点击确定就行了 插入之后 你的引用库中会多 ...