键入以搜索…
匹配算法:把输入按空格拆分,单独匹配每一段输入(不区分大小写,仅匹配文章文本内容),输出取或后的结果。
模糊搜索似乎很难搞,目前没有相关打算。
键入以搜索…
匹配算法:把输入按空格拆分,单独匹配每一段输入(不区分大小写,仅匹配文章文本内容),输出取或后的结果。
模糊搜索似乎很难搞,目前没有相关打算。
明知会迎来意难平的 Good End,但我们还有别的选择吗?
晚上走在四楼伸手不见伸手的走廊里,想起了去年今日心里所想:
我现在努力,是为了明年的今天,二楼的灯只为我一个人开。
努力自然是没有努力的,不然我去年就进队了。不过现在看来,虽然整栋楼只剩我一个常驻女角色,但进出的人太多了所以二楼的灯常亮。
也是因为这一点,早些时候把自己的刷新位置调整到了四楼。造孽啊!事实是只剩我一个人时,四楼根本不会开灯。
摸着黑走到第一个开关旁边,成功地没摸到。
往前趔趄几步,摸到了第二个开关,在寒风中哆嗦着打开,惊讶地发现因为怕冷,手伸得太晚了,恰好错过了第一个开关。
以上为事实记录,没什么隐喻义。撇捺中学什么时候才能在每层楼建两个厕所,这样我从三楼机房出发就不用决策半天了。
写点板子。
https://www.luogu.com.cn/problem/P5854
#include <bits/stdc++.h>
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
auto stime = std::chrono::steady_clock::now();
#endif
int n;
std::cin >> n;
std::vector<int> ls(n + 1), rs(n + 1);
std::vector<int> a(n + 1), l(n + 1), r(n + 1);
for (int i = 1; i <= n; ++i) {
std::cin >> a[i];
for (l[i] = i; l[i] != 1 && a[l[i] - 1] > a[i]; l[i] = l[l[i] - 1]);
if (l[i] != 1)
rs[l[i] - 1] = i;
}
for (int i = n; i; --i) {
for (r[i] = i; r[i] != n && a[r[i] + 1] > a[i]; r[i] = r[r[i] + 1]);
if (r[i] != n)
ls[r[i] + 1] = i;
}
auto res1 = 0ll, res2 = 0ll;
for (long long i = 1; i <= n; ++i)
res1 ^= i * (ls[i] + 1), res2 ^= i * (rs[i] + 1);
std::cout << res1 << ' ' << res2 << '\n';
#ifndef ONLINE_JUDGE
std::cerr << std::fixed << std::setprecision(6) << std::chrono::duration<double>(std::chrono::steady_clock::now() - stime).count() << "s\n";
#endif
return 0;
}冷。手太冷了。
Larrix:你把衣服扣上自然不冷了。
手心冷和没扣衣服有必然的联系吗?伪科学。
小时候很是苦恼:外婆的手总是很暖和,而我的手从来冰凉,在没有暖气的屋子里,几分钟就冻得生疼。
这一点随着年岁增长有愈演愈烈的迹象。关节好像结了冰,敲敲键盘能听到咔咔响。甚好,这样就能用薄膜键盘体验机械键盘的打击感了。
正所谓兴趣是最好的老师,高中和生物看了对眼,从倒一飞跃到正一。第一次仔细观察(作为生物的)自己的手心,才发现——手上的血管似乎埋得太浅了。乃至于,稍微用心看一眼,就可以看到分明而高饱和度的蓝紫色脉络,像向上渗透的树枝。
甚好,这样以后学生物可以多一门作弊技巧。
想起藤野先生的话,“你看,你将这条血管移了一点位置了。”但是先生,我可是直接对着手心微微凸起的血管摹印的啊。
然而实在浅得叫人揪心,好像稍加用力就会从这层薄薄的皮肤里迸出。好在我身体里最大的器官恪守职责,手掌从来没有四分五裂的趋势。实在是因为热二律难以抗衡,它也只好眼睁睁看着徐行的血液带来的一点点热量流了一地。
https://www.luogu.com.cn/problem/P3385
#include <bits/stdc++.h>
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
auto stime = std::chrono::steady_clock::now();
#endif
int T;
for (std::cin >> T; T--; ) {
int n, m;
std::cin >> n >> m;
std::vector<std::vector<std::pair<int, int> > > g(n + 1);
for (int x, y, w; m--; ) {
std::cin >> x >> y >> w;
g[x].emplace_back(y, w);
if (w >= 0)
g[y].emplace_back(x, w);
}
std::queue<int> q;
std::vector<int> tag(n + 1), inq(n + 1), dis(n + 1, 0x3f3f3f3f);
dis[1] = 0, q.push(1), inq[1] = 1;
for (; !q.empty(); ) {
int x = q.front();
q.pop(), inq[x] = 0;
if (++tag[x] == n) {
std::cout << "YES\n";
goto issol;
}
for (auto [i, w] : g[x])
if (dis[i] > dis[x] + w) {
dis[i] = dis[x] + w;
if (!inq[i])
q.push(i), inq[i] = 1;
}
}
std::cout << "NO\n";
issol: ;
}
#ifndef ONLINE_JUDGE
std::cerr << std::fixed << std::setprecision(6) << std::chrono::duration<double>(std::chrono::steady_clock::now() - stime).count() << "s\n";
#endif
return 0;
}图论板子就没几个会的。
想起之前在知乎上看到 WYXkk 说 Tarjan 是无需会的算法,联合省选 2023 转头就考了。喜提言出法随。
https://www.luogu.com.cn/problem/P3387
#include <bits/stdc++.h>
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
auto stime = std::chrono::steady_clock::now();
#endif
int n, m;
std::cin >> n >> m;
std::vector<int> a(n + 1);
for (int i = 1; i <= n; ++i)
std::cin >> a[i];
std::vector<std::vector<int> > g(n + 1);
for (int x, y; m--; ) {
std::cin >> x >> y;
g[x].push_back(y);
}
int cnt = 0;
std::vector<int> st;
std::vector<int> dfn(n + 1), low(n + 1), col(n + 1), s(n + 1);
std::function<void(int)> DFS = [&](int x) {
static int now = 0;
st.push_back(x);
dfn[x] = low[x] = ++now;
for (auto i : g[x])
if (!dfn[i]) {
DFS(i);
low[x] = std::min(low[x], low[i]);
}
else if (!col[i])
low[x] = std::min(low[x], dfn[i]);
if (low[x] == dfn[x]) {
++cnt;
for (int p = -1; p != x; ) {
p = st.back(), st.pop_back();
col[p] = cnt, s[cnt] += a[p];
}
}
return;
};
for (int i = 1; i <= n; ++i)
if (!dfn[i])
DFS(i);
std::vector<std::vector<int> > g1(cnt + 1);
std::vector<int> deg(cnt + 1), res(cnt + 1);
for (int i = 1; i <= n; ++i)
for (auto j : g[i])
if (col[i] != col[j])
g1[col[j]].push_back(col[i]), ++deg[col[i]];
std::queue<int> q;
for (int i = 1; i <= cnt; ++i)
if (!deg[i])
q.push(i);
for (; !q.empty(); ) {
int x = q.front();
q.pop();
res[x] += s[x];
for (auto i : g1[x]) {
res[i] = std::max(res[i], res[x]);
if (!--deg[i])
q.push(i);
}
}
std::cout << *std::max_element(res.begin() + 1, res.end()) << '\n';
#ifndef ONLINE_JUDGE
std::cerr << std::fixed << std::setprecision(6) << std::chrono::duration<double>(std::chrono::steady_clock::now() - stime).count() << "s\n";
#endif
return 0;
}真是奇妙!不去想自己有多冷,反而没那么冷了。寒冷其实是一种模因污染,我们需要使用对应的手段对抗祂。
古希腊哲学家卡文迪许曾经说过:“爱人的眼睛是澄澈的粉色。”我告诉他,这可能是因为你的爱人是一瓶碳酸钴。
那天我走在路上,与饮水机撞个满怀。我想我找到了我粉色眼睛的爱人——“你就是我的隐德来希吗?”我不禁问出口。
“不,我是被飞起来引得来吸猫的。”她答道。飞起来在冬日难得的阳光下喵啸且徐行,踩着优雅的猫步,径直走到女厕所里去了。
它比起猫,明明更像猞猁。我在心里抗议。但被她的粉色的眼睛注视着,倒叫我不好意思开口了。
可惜由于我撞上了(crash into)饮水机,她裂开成了两半。从未工作过的热水口发出悲鸣,她在三楼迷茫地踯躅了一阵,便静静地立在了一楼(Ground Floor)。随后,她就消失了。目睹着她的淡去(fade away),我想我又看见了某种柳莺。
“嘿,哥们,你会高次权方和不等式吗?”
“哦,亲爱的柳莺小姐,要我说的话,这想必是某种基本不等式吧。”
“哈哈!哥们,你真幽默!”
“不胜荣幸,小姐。比起这一点,更令我高兴的是您愿意与我交谈。”
黄腰柳莺的眉毛比黄眉柳莺的眉毛更黄,恰似我比我的龟儿子更像一个龟儿子。
https://www.luogu.com.cn/problem/P3388
#include <bits/stdc++.h>
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
auto stime = std::chrono::steady_clock::now();
#endif
int n, m;
std::cin >> n >> m;
std::vector<std::vector<std::pair<int, int> > > g(n + 1);
for (int x, y; m--; ) {
std::cin >> x >> y;
g[x].emplace_back(y, m), g[y].emplace_back(x, m);
}
int cnt = 0;
std::vector<int> dfn(n + 1), low(n + 1), tag(n + 1);
std::function<void(int, int)> DFS = [&](int x, int fa) {
static int now = 0;
dfn[x] = low[x] = ++now;
for (auto [i, id] : g[x])
if (!dfn[i]) {
DFS(i, id);
if (fa == -1)
++cnt;
low[x] = std::min(low[x], low[i]);
if (low[i] >= dfn[x])
tag[x] = 1;
}
else if (id != fa)
low[x] = std::min(low[x], dfn[i]);
return;
};
for (int i = 1; i <= n; ++i)
if (!dfn[i]) {
cnt = 0, DFS(i, -1);
tag[i] = (cnt >= 2);
}
std::vector<int> res;
for (int i = 1; i <= n; ++i)
if (tag[i])
res.push_back(i);
std::cout << res.size() << '\n';
for (auto i : res)
std::cout << i << ' ';
std::cout << '\n';
#ifndef ONLINE_JUDGE
std::cerr << std::fixed << std::setprecision(6) << std::chrono::duration<double>(std::chrono::steady_clock::now() - stime).count() << "s\n";
#endif
return 0;
}为什么有【模板】割点(割顶),却没有【模板】割边(桥)?
https://www.luogu.com.cn/problem/P3807
#include <bits/stdc++.h>
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
auto stime = std::chrono::steady_clock::now();
#endif
int T;
for (std::cin >> T; T--; ) {
int n, m, mod;
std::cin >> m >> n >> mod, n += m;
std::vector<long long> fac(mod), inv(mod);
fac[0] = inv[0] = 1ll;
for (int i = 1; i < mod; ++i)
fac[i] = fac[i - 1] * i % mod;
auto qkp = [&](long long x, int y) {
auto res = 1ll;
for (; y; (x *= x) %= mod, y >>= 1)
if (y & 1)
(res *= x) %= mod;
return res;
};
inv[mod - 1] = qkp(fac[mod - 1], mod - 2);
for (int i = mod - 2; i; --i)
inv[i] = inv[i + 1] * (i + 1) % mod;
std::function<long long(int, int)> C = [&](int n, int m) {
if (n < m)
return 0ll;
if (n < mod)
return fac[n] * inv[m] % mod * inv[n - m] % mod;
return C(n / mod, m / mod) * C(n % mod, m % mod) % mod;
};
std::cout << C(n, m) << '\n';
}
#ifndef ONLINE_JUDGE
std::cerr << std::fixed << std::setprecision(6) << std::chrono::duration<double>(std::chrono::steady_clock::now() - stime).count() << "s\n";
#endif
return 0;
}https://www.luogu.com.cn/problem/P1495
哎呀好难!不会!假装不会考,跳了先。
https://www.luogu.com.cn/problem/P2495
long long 没开完喜提 WA 3 发
#include <bits/stdc++.h>
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
auto stime = std::chrono::steady_clock::now();
#endif
int n;
std::cin >> n;
std::vector<std::vector<std::pair<int, int> > > g(n + 1);
for (int i = 1, x, y, w; i < n; ++i) {
std::cin >> x >> y >> w;
g[x].emplace_back(y, w), g[y].emplace_back(x, w);
}
std::vector<long long> s(n + 1);
std::vector<int> dfn(2 * n), dep(n + 1), L(n + 1), R(n + 1);
s[1] = 1e18;
std::function<void(int, int)> DFS = [&](int x, int fa) {
static int now = 0;
dfn[++now] = x, L[x] = now;
for (auto [i, w] : g[x])
if (i != fa) {
dep[i] = dep[x] + 1;
s[i] = std::min(s[x], (long long)w);
DFS(i, x);
dfn[++now] = x;
}
R[x] = now;
return;
};
DFS(1, -1);
std::vector<std::vector<int> > st(20, std::vector<int> (2 * n));
st[0] = dfn;
for (int j = 1; (1 << j) < 2 * n; ++j)
for (int i = 1; i + (1 << j) - 1 < 2 * n; ++i)
if (dep[st[j - 1][i]] < dep[st[j - 1][i + (1 << (j - 1))]])
st[j][i] = st[j - 1][i];
else
st[j][i] = st[j - 1][i + (1 << (j - 1))];
auto ask = [&](int l, int r) {
int k = std::__lg(r - l + 1);
return dep[st[k][l]] < dep[st[k][r - (1 << k) + 1]] ? st[k][l] : st[k][r - (1 << k) + 1];
};
auto askLCA = [&](int x, int y) {
return ask(std::min(L[x], L[y]), std::max(R[x], R[y]));
};
int m;
std::cin >> m;
std::vector<int> tag(n + 1);
std::vector<long long> f(n + 1, 1e18);
std::vector<std::vector<int> > g1(n + 1);
for (int k; m--; ) {
std::cin >> k;
std::vector<int> pos(k);
for (int i = 0; i < k; ++i)
std::cin >> pos[i], tag[pos[i]] = 1;
std::sort(pos.begin(), pos.end(), [&](int x, int y) { return L[x] < L[y]; });
for (int i = 1; i < k; ++i)
pos.push_back(askLCA(pos[i - 1], pos[i]));
std::sort(pos.begin(), pos.end(), [&](int x, int y) { return L[x] < L[y]; });
pos.erase(std::unique(pos.begin(), pos.end()), pos.end());
k = (int)pos.size();
std::vector<int> st, rt;
for (auto i : pos) {
for (; !st.empty() && R[st.back()] < L[i]; st.pop_back());
if (st.empty())
rt.push_back(i);
else
g1[st.back()].push_back(i);
st.push_back(i);
}
std::function<void(int)> DFS = [&](int x) {
if (tag[x]) {
f[x] = s[x];
return;
}
f[x] = 0;
for (auto i : g1[x])
DFS(i), f[x] += f[i];
f[x] = std::min(f[x], s[x]);
return;
};
auto res = 0ll;
for (auto i : rt)
DFS(i), res += f[i];
std::cout << res << '\n';
for (auto i : pos) {
f[i] = 1e18, tag[i] = 0;
std::vector<int>().swap(g1[i]);
}
}
#ifndef ONLINE_JUDGE
std::cerr << std::fixed << std::setprecision(6) << std::chrono::duration<double>(std::chrono::steady_clock::now() - stime).count() << "s\n";
#endif
return 0;
}https://www.luogu.com.cn/problem/P3384
我真有不会这东西的可能性吗?
https://www.luogu.com.cn/problem/P3806
我真有不会这东西的可能性吗?× 2
https://www.luogu.com.cn/problem/P3809
不行了,这个是真不会。双关键字桶排比有机推断还烧脑 😰
没写出来!再默写一遍 😡
写错了一个地方!再默写一遍 😡
写对了!再默写一遍 😡
写对了!再默写一遍 😡
写对了!和解了!
我不想再记线性求 height 了!直接二分加哈希也是一样的复杂度吧?
好丑…… 默写线性 height 吧 🙂
#include <bits/stdc++.h>
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
auto stime = std::chrono::steady_clock::now();
#endif
int n;
std::string s;
std::cin >> s, n = (int)s.length(), s = "#" + s;
std::vector<int> sa(n + 1), rk(2 * n + 1), h(n + 1);
{
int m = 128;
std::vector<int> c(std::max(n, m) + 1), id(n + 1), la(2 * n + 1);
std::copy(s.begin() + 1, s.end(), rk.begin() + 1);
for (int i = 1; i <= n; ++i)
++c[rk[i]];
std::partial_sum(c.begin() + 1, c.begin() + m + 1, c.begin() + 1);
for (int i = n; i; --i)
sa[c[rk[i]]--] = i;
for (int w = 1, p = -1; p != n; w <<= 1, m = p) {
int cnt = 0;
for (int i = n - w + 1; i <= n; ++i)
id[++cnt] = i;
for (int i = 1; i <= n; ++i)
if (sa[i] > w)
id[++cnt] = sa[i] - w;
std::fill(c.begin() + 1, c.begin() + m + 1, 0);
for (int i = 1; i <= n; ++i)
++c[rk[i]];
std::partial_sum(c.begin() + 1, c.begin() + m + 1, c.begin() + 1);
for (int i = n; i; --i)
sa[c[rk[id[i]]]--] = id[i];
std::copy(rk.begin() + 1, rk.end(), la.begin() + 1);
p = 0;
for (int i = 1; i <= n; ++i)
if (i != 1 && la[sa[i]] == la[sa[i - 1]] && la[sa[i] + w] == la[sa[i - 1] + w])
rk[sa[i]] = p;
else
rk[sa[i]] = ++p;
for (int i = 1, to = 0; i <= n; ++i) {
for (to = std::max(to - 1, 0); s[i + to] == s[sa[rk[i] - 1] + to]; ++to);
h[rk[i]] = to;
}
}
}
for (int i = 1; i <= n; ++i)
std::cout << sa[i] << ' ';
std::cout << '\n';
#ifndef ONLINE_JUDGE
std::cerr << std::fixed << std::setprecision(6) << std::chrono::duration<double>(std::chrono::steady_clock::now() - stime).count() << "s\n";
#endif
return 0;
}考虑到我对 SA 的熟悉程度,考了其实算不上太会,待会儿看看吧
https://www.luogu.com.cn/problem/P3919
我有不会主席树的可能性吗?还真有。打一遍吧。咋开小了。
#include <bits/stdc++.h>
const int maxn = 1e6 + 5, maxm = 3e7 + 5;
struct { int l, r, u; } t[maxm];
int a[maxn], tot;
void bld(int &p, int l, int r) {
p = ++tot;
if (l == r) {
t[p].u = a[l];
return;
}
int mid = (l + r) >> 1;
bld(t[p].l, l, mid), bld(t[p].r, mid + 1, r);
return;
}
void upd(int &p, int q, int l, int r, int x, int v) {
p = ++tot, t[p] = t[q];
if (l == r) {
t[p].u = v;
return;
}
int mid = (l + r) >> 1;
if (x <= mid)
upd(t[p].l, t[q].l, l, mid, x, v);
else
upd(t[p].r, t[q].r, mid + 1, r, x, v);
return;
}
int ask(int p, int l, int r, int x) {
if (l == r)
return t[p].u;
int mid = (l + r) >> 1;
if (x <= mid)
return ask(t[p].l, l, mid, x);
return ask(t[p].r, mid + 1, r, x);
}
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
auto stime = std::chrono::steady_clock::now();
#endif
int n, m;
std::cin >> n >> m;
std::vector<int> rt(m + 1);
for (int i = 1; i <= n; ++i)
std::cin >> a[i];
bld(rt[0], 1, n);
for (int i = 1, q, op; i <= m; ++i) {
std::cin >> q >> op;
if (op == 1) {
int x, v;
std::cin >> x >> v;
upd(rt[i], rt[q], 1, n, x, v);
}
else {
int x;
std::cin >> x;
std::cout << ask(rt[q], 1, n, x) << '\n';
rt[i] = ++tot, t[rt[i]] = t[rt[q]];
}
}
#ifndef ONLINE_JUDGE
std::cerr << std::fixed << std::setprecision(6) << std::chrono::duration<double>(std::chrono::steady_clock::now() - stime).count() << "s\n";
#endif
return 0;
}为啥需要主席树啊,直接 DAG 是不是就能做了。
#include <bits/stdc++.h>
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
auto stime = std::chrono::steady_clock::now();
#endif
int n, m;
std::cin >> n >> m;
struct node { int to, op, i, v; };
std::vector<std::vector<node> > g(m + 1);
std::vector<int> a(n + 1);
for (int i = 1; i <= n; ++i)
std::cin >> a[i];
int tot = 0;
for (int i = 1, q, op, x; i <= m; ++i) {
std::cin >> q >> op >> x;
if (op == 1) {
int v;
std::cin >> v;
g[q].push_back({ i, 1, x, v });
}
else
g[q].push_back({ i, 2, x, ++tot });
}
std::vector<int> res(tot + 1);
std::function<void(int)> DFS = [&](int x) {
int tmp = -1;
for (auto [to, op, i, v] : g[x]) {
if (op == 1)
tmp = a[i], a[i] = v;
else
res[v] = a[i];
DFS(to);
if (op == 1)
a[i] = tmp;
}
return;
};
DFS(0);
for (int i = 1; i <= tot; ++i)
std::cout << res[i] << '\n';
#ifndef ONLINE_JUDGE
std::cerr << std::fixed << std::setprecision(6) << std::chrono::duration<double>(std::chrono::steady_clock::now() - stime).count() << "s\n";
#endif
return 0;
}Quack:需要适当穿插一些想题。
https://www.luogu.com.cn/problem/P3810
我有不会 CDQ 的可能性吗?还真有。打一遍吧。
机房里有一个人学了 6 年 OI 但没拿过省一,是谁呢?