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

solve

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

  1. Educational Codeforces Round 67 (Rated for Div. 2) B题【前缀+二分】【补题ING系列】

    题意:给出一个字符串s, 可以从左往右拿走s的字符, 至少要到s的第几个位置才能拼成t 思路:用二维数组记录前缀,然后二分即可. #include<bits/stdc++.h> using ...

  2. 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 ...

  3. 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 ...

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

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

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

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

  6. 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 ...

  7. 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 ...

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

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

  9. 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 < ...

随机推荐

  1. 前端开发 vue,angular,react框架对比2

    在过去一年里,前端开发发展迅速,前端工程师的薪资亦是水涨船高.2019 更是热度不减,而作为近年来尤为热门的前端框架,Vue.js 自是积累了大量关注.那么,Vue.js 是适合你的框架吗?     ...

  2. ORM 对表操作 详解

    目录 ORM对表操作详解 表结构 ORM对表的 增 删 改 查 基于对象的跨表查询 -- 类似于子查询 基于双下划的跨表查询 -- 连表 join ORM对表的操作示例 正向查 与 反向查 relat ...

  3. HTML5 结构标签

    一.定义标题栏:header header 元素是一种具有引导和导航作用的结构元素,通常用来放置整个页面或页面内的一个内容区块的标题,但也可以包含其他内容,因此整个页面的标题应该放在页面的开头. he ...

  4. oracle in和exists区别

    in和exists http://oraclemine.com/sql-exists-vs-in/ https://www.techonthenet.com/oracle/exists.php htt ...

  5. springboot学习入门简易版七---springboot2.0使用@Async异步执行方法(17)

    1启动类开启异步调用注解 @SpringBootApplication @EnableAsync //开启异步调用 public class StartApplication { 不开启则异步调用无效 ...

  6. robot framework笔记(二):在RF中自定义chrome启动参数

    (一)在RF中自定义chrome启动参数 这里主要是实现下面2个功能 1.禁用chrome正受自动测试软件控制的提示 2.设置默认的下载路径(一些导出.下载类的功能,将文件下载到指定路径下) 自定义一 ...

  7. redhat6.7环境下oracle11gR2 RAC静默安装

    (一)基础环境 虚拟机环境 :vmware workstation 12 操作系统    : redhat6.7 - 64bit 数据库版本 :11.2.0.4 (二)安装前的环境准备 (2.1)配置 ...

  8. Host is not allowed to connect to this MySQL server

    解决方法: [root@GYQ-Prod-Zabbix ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Com ...

  9. kubernetes 集群添加node节点

    kubernetes 集群添加node节点 注意,我们并不需要把新增的node ip加入到证书里重新生成!!! 下面我们以添加node03为例 一.添加集群里个节点的hostname并设置好对应主机名 ...

  10. ORA-01031:insufficient privileges 解决方法

    使用sys或system帐号登录plSql时,提示ORA-01031:insufficient privileges 错误.使用其他的帐号能正常登录,在cmd命令中用system帐号也是可以正常登录. ...