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 < ...
随机推荐
- 【SP1811】 LCS - Longest Common Substring(后缀自动机)
题目链接 对第一个串建出\(SAM\),然后用第二个串去匹配. 如果能往下走就往下走,不能的话就跳parent tree的父亲,直到能走为止.如果跳到\(0\)了还是不能走,重新匹配. #includ ...
- 那些年,Linus torvalds大神喷过的技术
Linus Torvalds 被认为是最伟大的程序员之一,因为他写出了使用最广泛的软件,如 Linux 内核和 Git 版本控制系统.但是他这个人经常因为讲话带有情绪,甚至是因为带有脏话的意见而饱受非 ...
- Apache Commons FileUpload实现文件上传
一.Apache Commons-FileUpload简介 Apache Commons是一个专注于可重用Java组件的所有方面的 Apache 项目. Apache Commons项目由三个部分组成 ...
- mysql json字段
从 MySQL 5.7.8 开始,MySQL 支持原生的 JSON 数据类型. 一. 创建json(不可以设置长度,可以是null,不能用有默认值) mysql> CREATE TABLE ...
- 铁力项目mysql异常处理过程记录
地区:铁力 故障:2019-06-26 10:19:34 139921514837760 [ERROR] mysqld: Error writing file 'mysql-bin' (errno: ...
- Codes: MODERN ROBOTICS Ch.4_基于PoE的正运动学代码实现
%%1 基于PoE space form 的正运动学求解 % 输入M矩阵.螺旋轴列表Slist(column vector).关节角向量qlist(column vector),输出齐次变换矩阵T f ...
- 微信小程序~基础组件
(1)视图容器 名称 功能说明 movable-view 可移动的视图容器,在页面中可以拖拽滑动 cover-image 覆盖在原生组件之上的图片视图 cover-view 覆盖在原生组件之上的文本视 ...
- 零基础如何学好python之变量
想要自学python,变量(variable)是必经之路,它是学习python初始时,就会接触到的一个新的知识点,也是一个需要熟知的概念.python是一种动态类型语言,在赋值的执行中可以绑定不同类型 ...
- #《你们都是魔鬼吗》第八次团队作业:第五天Alpha冲刺
<你们都是魔鬼吗>第八次团队作业:Alpha冲刺 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 你们都是魔鬼吗 作业学习目标 完成最 ...
- SVM: 用kernels(核函数)来定义新的features,避免使用多项式,高斯kernel
应用kernels来进行非线性分类 非线性分类:是否存在好的features的选择(而不是多项式)--f1,f2,f3.... 上图是一个非线性分类的问题,前面讲过,我们可以应用多项式(feature ...