Educational Codeforces Round 67 (Rated for Div. 2)
A
考虑之前选中没有一个的,那么结果就是\(min(n-s,n-t)\)
那么能选中的第一次就是这个结果\(+1\),但需要拥有两个
\((s>t)\)考虑一开始选不中\(t\),则但选中\(t\)时\(s\)也一定被选中了\((\)最坏的情况为\(s\)与\(t\)并集最小\()\)
\(ans=n-min(s,t)+1\)
B
简单想的复杂度高的算法:先\(sum_{i,j}\)表示文本串前\(i\)个字符\(j\)字符的个数
匹配串也用\(a\)统计每个字符的个数,二分一下判是否满足\(O(26n+\sum t_i+mlogn)\)复杂度下界
开个桶\(a_{i,j}\)表示文本串\(i\)字符第\(j\)个的位置
匹配串统计每个字符的个数,再在\(a\)里比较一下最大值\(O(n+26m)\)
C
题意:需要构造一个数组,有\(m\)个约束\((t,l,r)\)
\(t=1,a_{l,r}\)非严格递增;\(t=0,a_{l,r}\),至少有一对连续的位置\(a_{i}>a_{i+1}\)
思考怎么则不合理:唯一的情况为至少有一组\(t=0\)包含在\(t=1\)中
将\(t=1\)当做限制,\(t=0\)当做判断
一开始将数组严格递减构造,显然这样满足所有的\(t=0\);将\(t=1\)记录下来,按左区间的位置升序排序;
每次对于\((t=1,l,r)\)将\([l,r]\)的值赋为\(a_{l}\)
D
想到平衡树的做法不记得用\(STL\)结果打崩了
考虑前\(i-1\)已经匹配了,\(a_i≠b_i\),那么怎么移过来呢?假设远处有一个位置\(x\),满足\(a_x=b_i\)
能移动过来的条件为\(min[i,x]=b_i\)
平衡树则需要支持:区间最小值查询,单点查询,单点删除与添加,直接打崩
考虑用\(set+\)线段树实现:我们发现单点往前移有一个特点,移过的点都不会用到了
把\((a_i,i)\)放到\(set\)里,线段树维护区间最小值查询,我们需要使得线段树仅维护单点修改就能实现之前的状态
每次用\(set\)找出第一个符合大于等于的:
就相当于如果\(set\)里还有第一个关键字为\(b_i\),找到第二个关键字\((\)原数组位置\(x)\)最小的
找到后将\(x\)在线段树值为\(inf\),并在\(set\)里删去\((\)因为\(i\)这个点之后没有用了\()\),也就是相对位置不变如果没有就失败
\(rank2's code\)
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 3 * (int)1e5 + 100;
int b[maxN];
int t[4 * maxN];
int a[maxN];
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = a[tl];
return;
}
int tm = (tl + tr) / 2;
build(v + v, tl, tm);
build(v + v + 1, tm + 1, tr);
t[v] = min(t[v + v], t[v + v + 1]);
}
void upd(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
t[v] = val;
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm) upd(v + v, tl, tm, pos, val);
else upd(v + v + 1, tm + 1, tr, pos, val);
t[v] = min(t[v + v], t[v + v + 1]);
}
const int INF = (int)1e9 + 100;
int get(int v, int tl, int tr, int l, int r) {
if (l > r) return INF;
if (tl == l && tr == r) {
return t[v];
}
int tm = (tl + tr) / 2;
return min(get(v + v, tl, tm, l, min(r, tm)), get(v + v + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("input.txt", "r", stdin);
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
set < pair < int, int > > s;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s.insert(make_pair(a[i], i));
}
bool ok = true;
build(1, 1, n);
for (int i = 1; i <= n; i++) {
cin >> b[i];
if (!ok) continue;
auto it = s.lower_bound(make_pair(b[i], -1));
if (it == s.end() || ((it -> first) != b[i])) {
ok = false;
continue;
}
int ind = (it -> second);
s.erase(it);
if (b[i] != get(1, 1, n, 1, ind)) {
ok = false;
}
upd(1, 1, n, ind, INF);
}
if (ok) cout << "YES" << '\n';
else cout << "NO" << '\n';
}
return 0;
}
E
很裸的换根
考虑\(1\)作为点,\(ans=\sum size_i\),只需要考虑从\(u\)移到\(v\)u和\(v\)的子树大小变化就好了
F
Educational Codeforces Round 67 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 67 (Rated for Div. 2) B题【前缀+二分】【补题ING系列】
题意:给出一个字符串s, 可以从左往右拿走s的字符, 至少要到s的第几个位置才能拼成t 思路:用二维数组记录前缀,然后二分即可. #include<bits/stdc++.h> using ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- 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 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 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 < ...
随机推荐
- 网页包抓取工具Fiddler工具简单设置
当下载好fiddler软件后首先通过以下简单设置,或者有时候fiddler抓取不了浏览器资源了.可以通过以下设置. 设置完成后重启软件.打开网络看看有没有抓取到包.
- 12 Mapping查询
查看 某个index下所有type的mapping GET /beauties/_mapping 查看 指定index.指定type的mapping GET /beauties/_mapping/cn
- 删除Ubuntu的UEFI启动项
bcdedit 删除 千万不要手贱用diskpart之类的命令直接删除文件夹,大写的没,有,用! 感谢这个视频的up主,youtube看不到请翻墙.https://www.youtube.com/wa ...
- Spark运行原理【史上最详细】
https://blog.csdn.net/lovechendongxing/article/details/81746988 Spark应用程序以进程集合为单位在分布式集群上运行,通过driver程 ...
- 解决通过vue-router打开tab页,下次进入还是上次history缓存的界面状态的问题
一.问题描述: 1. 跳转模式:界面A-->界面B(界面A中通过 this.$router.push({name:'组件B名称', params: {参数}}) 通过打开新tab页的方式打开界面 ...
- zabbix4.2监控nginx
项目环境: 操作系统 主机名 IP地址 Centos7.6 x86_64 zabbix-server 192.168.1.18 Centos7.6 x86_64 zabbix-client 192.1 ...
- 关于类型为numpy,TensorFlow.tensor,torch.tensor的shape变化以及相互转化
https://blog.csdn.net/zz2230633069/article/details/82669546 2018年09月12日 22:56:50 一只tobey 阅读数:727 1 ...
- 通过visual studio制作类库的文档
java的集成开发工具,可以导出jar的文档. visual studio 也可以生成类库的文档,邮件项目属性,生成,输出下,选择XML文档文件.然后生成项目,就会再bin下面生成一个xml文件. 将 ...
- IDEA实用教程(九)—— 创建Servlet
4. 创建Servlet 1) 第一步 2) 第二步 3) 第三步 4) 第四步 由于新创建的Web项目, 没有Tomcat环境, 所以创建的Servlet会发生导包错误,如下图所示 : 因此我们需要 ...
- RBF神经网络——直接看公式,本质上就是非线性变换后的线性变化(RBF神经网络的思想是将低维空间非线性不可分问题转换成高维空间线性可分问题)
Deeplearning Algorithms tutorial 谷歌的人工智能位于全球前列,在图像识别.语音识别.无人驾驶等技术上都已经落地.而百度实质意义上扛起了国内的人工智能的大旗,覆盖无人驾驶 ...