随笔分类 -  字符串#字典树

摘要:// Problem: CF817E Choosing The Commander // Contest: Luogu // URL: https://www.luogu.com.cn/problem/CF817E // Memory Limit: 250 MB // Time Limit: 200 阅读全文
posted @ 2021-08-03 12:14 OvO1 阅读(45) 评论(0) 推荐(0)
摘要:link #思路: 将序列转化为前缀和的异或数组,问题就转化成了寻找两个数使得异或值大于等于$k$并且距离最小。 考虑用$01$字典树维护,枚举一遍右端点,求他之前的所有数与他的异或值的最大值,如果$>=k$的话就尝试更新答案。然后将该端点加入字典树。 #代码: #include<bits/stdc 阅读全文
posted @ 2021-07-22 20:17 OvO1 阅读(133) 评论(0) 推荐(0)
摘要:link #思路: 求异或的最大值容易想到01字典树,只需要再维护删除操作就好。 加一个$a$数组记录一下有多少个节点经过了这个点,删除的时候如果这是最后一个经过该点的节点,就删除他的父节点向下指的指针。用map维护一下每个数出现的次数,字典树只维护种类。 注意要先将0插入字典树,集合里没有数的时候 阅读全文
posted @ 2021-07-21 20:57 OvO1 阅读(88) 评论(0) 推荐(0)
摘要:link #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll>PLL; typedef pair<int, int 阅读全文
posted @ 2021-07-21 11:48 OvO1 阅读(35) 评论(0) 推荐(0)
摘要:题单:https://www.luogu.com.cn/training/9372 P3879 [TJOI2010]阅读理解 题型:字符串检索 空间卡的很紧,普通的trie会MLE const int maxn=5e5+100; bool st[maxn][1010]; int nex[maxn][ 阅读全文
posted @ 2021-07-19 10:35 OvO1 阅读(140) 评论(0) 推荐(0)
摘要:#模板 struct trie{ int nex[maxn][26],idx; bool exist[maxn]; // 该结点结尾的字符串是否存在 void insert(string s,int l){ // 插入字符串 int p=0; for(int i=0;i<l;i++){ int c= 阅读全文
posted @ 2021-07-19 09:14 OvO1 阅读(46) 评论(0) 推荐(0)