摘要: 题意: 选择一个t, 将t与s匹配,匹配后删除s[i+1]之前的字符,只留下s[i+1]- s[n], 并删除t的最后一个字符, 询问能最多进行几次操作。 思路: 我们要明白字符串 t 中的前缀长度越小,越要在s中出现的位置越靠后,因为t是不断缩减的,但是s是不断删除前缀的。因此我们可以遍历所有的后 阅读全文
posted @ 2025-05-26 21:48 windfallll 阅读(11) 评论(0) 推荐(0)
摘要: ull t = (bs[i]) & (bs[i-1] >> 62) & ((bs[i-1] >> 63) | (bs[i] << 1)); 对于这一步的解释 在处理临块的连续三个数时,可以发现只有两种情况,分别是 1|11和 11|1 (这里是分割线),因此我们观察第一个数(起点)只可能是上一个块的 阅读全文
posted @ 2025-04-30 22:29 windfallll 阅读(12) 评论(0) 推荐(0)
摘要: 题意: 我们需要算所有l,r组合区间中的x,y组合使得0的数量等于1的数量。 思路: 1.暴力显然不可得,容易想到计算(x,y)的贡献,最后乘上所在区间即可; 2.这里我们将0视为-1,只要前后前缀和的值相等即可判断01数量相等,即sum[x-1] == sum[y]; (用哈希表即可 3.现在来求 阅读全文
posted @ 2025-03-17 11:59 windfallll 阅读(17) 评论(0) 推荐(0)
摘要: 显然不可暴力解出,因此是到数学题。已知$$y=x * k^n$$所以我们可以利用y的区间范围$$[l1, r1]$$得出x的新的区间范围$$[l2/k^n(向上取整), r2/k^n(向下取整)]$$接着与原来的范围取交集 然后不断枚举n即可,注意k^n不可能超过y #include <iostre 阅读全文
posted @ 2024-12-16 23:15 windfallll 阅读(82) 评论(0) 推荐(0)
摘要: 思路要点: 对于第i - 1个和第i个数字,利用第i-1个数字乘以的2x,在此基础之上再进行多乘或者少乘使得第i个数字足以大于等于第i-1个数字,由此可以得到最小的步骤数(本质上也就是前缀和) #include <iostream> #define int long long using names 阅读全文
posted @ 2024-12-09 10:06 windfallll 阅读(18) 评论(0) 推荐(0)
摘要: BFS #include <iostream> #include <cstring> #include <queue> using namespace std; const int N = 1e5 + 10; int n, m, h[N], e[N], idx, ne[N], d[N]; queue 阅读全文
posted @ 2024-12-04 17:15 windfallll 阅读(21) 评论(0) 推荐(0)
摘要: 要灵活运用sort函数: 利用bmp函数对其进行自定义规则的排序 ```cpp #include <bits/stdc++.h> using namespace std; int n; string a[30]; bool bmp(const string& a, const string& b) 阅读全文
posted @ 2024-11-25 15:26 windfallll 阅读(16) 评论(0) 推荐(0)
摘要: 使用对数lg直接估算所求位数, 每次乘以2^60大大加快速度(不够60再乘以更小的) 9*2^60为10,376,293,541,461,622,784刚好不会超ull范围(18,446,744,073,709,551,616) #include <iostream> #include <cstdi 阅读全文
posted @ 2024-11-17 18:08 windfallll 阅读(15) 评论(0) 推荐(0)
摘要: #include <iostream> using namespace std; const int N = 1e6 + 10; int a[N], n; void quick_sort(int a[], int l, int r) { if (l >= r) return; int x = a[l 阅读全文
posted @ 2024-11-17 09:35 windfallll 阅读(15) 评论(0) 推荐(0)
摘要: 先递归为多个小部分再进行排序 #include <iostream> using namespace std; const int N = 1e5 + 10; int a[N], tem[N]; void merge_sort(int a[], int l, int r) { if (l >= r) 阅读全文
posted @ 2024-11-17 09:27 windfallll 阅读(22) 评论(0) 推荐(0)