稀疏表常用于解决RMQ问题(区间最大/小值查询问题),稀疏表仅支持高效的查询操作,并不支持动态修改操作。其实现主要基于倍增思想和动态规划。 稀疏表最主要的思想就是将区间分为两个子区间,例如[l,r]分成[l,l+2^k-1]和[r-2^k+1,r],其中k=log2(r-l+1)向下取整。 其本质上就是用两个长度为 2^k 的重叠区间覆盖 [l,r…
读入带空格的字符串 char str[1024]; scanf("%[^\n]",&str); // 读取到'\n'为止,不读入'\n' getchar(); // 清除'\n' int num; string str; cin >> num; // 读取数字 …
acwing799最长连续不重复子序列 #include<bits/stdc++.h> using namespace std; const int N=1e5+10; int n; int q[N]; int cnt[N]; int main() { std::ios::sync_with_stdio(0); std::cin.tie…
原题单链接:https://www.luogu.com.cn/training/111#problems AcWing789. 数的范围 #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, q, a[N]; int bs1(i…
原题单链接:https://rentry.org/ozd34yrn 例题 重述问题 找到最后一步 去掉最后一步,是否能划分出子问题 考虑边界 746. 使用最小花费爬楼梯 const int N=1010; class Solution { public: int mem[N]; int dfs(vector<int>& cos…
#include <bits/stdc++.h> using namespace std; const int N = 10010; int fa[N]; inline void init(int n) { for (int i = 1; i <= n; i++) fa[i] = i; } inline int find(int …
#include<bits/stdc++.h> using namespace std; const int N = 10010; int a[N], s[N]; int n; int main(){ cin >> n; for (int i = 1; i <= n; i ++ ){ cin >> a[i]…
01背包问题 #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 1010; int n, m; int v[N], w[N]; int f[N]; int g[N]; int…
原题单链接:https://rentry.org/2f76axt4 见到很有意思的问题 : 以往见过许多教材,对动态规划(DP)的引入属于“奉天承运,皇帝诏曰”式:不给出一点引入,见面即拿出一大堆公式吓人;学生则死啃书本,然后突然顿悟。针对入门者的教材不应该是这样的。(看到一位知乎的大佬说的, 深有感悟~) 动态规划 就是 : 给定一个问…
C++的cin和cout加快读写速度,用以下代码: std::ios::sync_with_stdio(false); std::cin.tie(0);