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. Oracle regexp_replace 手机号脱敏

    select '18012345678',regexp_replace('18012345678','(.){4}','****',4,1) from dual;

  2. verilog之原语设计

    verilog之原语设计 1.原语作用 在一般的verilog设计中,一般采用数字逻辑设计,由软件将数字逻辑转化为特定的数字电路.但是,对于某些特殊的领域,有可能需要用户直接自定义数字电路以达到对指定 ...

  3. 【已解决】Android----java.lang.NullPointerException:---java.lang.NullPointerException:

    2021-03-06 13:26:12.274 8544-8544/com.example.helloworld E/AndroidRuntime: FATAL EXCEPTION: main Pro ...

  4. 王莉:将开发文档英文化和本地化,我们努力让OpenHarmony走向全球

    编者按:在 OpenHarmony 生态发展过程中,涌现了大批优秀的代码贡献者,本专题旨在表彰贡献.分享经验,文中内容来自嘉宾访谈,不代表 OpenHarmony 工作委员会观点. 王莉 华为技术有限 ...

  5. 使用pillow制作长图

    这是来自一个妹子的需求,需要将多张图片拼接成一张长图 我是使用pillow这个库来实现的,下面的简单的代码,操作比较简单,代码还有优化的空间 def test(dirpath): ims = [Ima ...

  6. Native Drawing开发指导,实现HarmonyOS基本图形和字体的绘制

      场景介绍 Native Drawing模块提供了一系列的接口用于基本图形和字体的绘制.常见的应用场景举例: ● 2D图形绘制. ● 文本绘制. 接口说明 接口名 描述 OH_Drawing_Bit ...

  7. Hive 查看,删除分区

    查看所有分区 show partitions 表名; 删除一般会有两种方案 1.直接删除hdfs文件 亲测删除hdfs路径后 查看分区还是能看到此分区 可能会引起其他问题 此方法不建议 2. 使用删除 ...

  8. go切片和指针切片

    转载请注明出处: 在Go语言中,切片(Slice)和指针的切片(即切片中每个元素都是指向某种数据类型的指针)是两个不同的概念,它们各自具有特定的用途和优势. 切片(Slice) 切片是对数组的一个连续 ...

  9. Leetcode-队列得最大值

    请定义一个队列并实现函数 max_value 得到队列里的最大值,要求函数max_value.push_back 和 pop_front 的均摊时间复杂度都是O(1).若队列为空,pop_front ...

  10. Tailwind CSS 使用指南

    0x01 概述 (1)简介 Tailwind CSS 官网:https://www.tailwindcss.cn/ Tailwind CSS 是一个 CSS 框架,使用初级"工具" ...