版本比较
波
正文
增加 194 行删除 1249 行
12345678910111213141516171812345672089221011121314151617181920212223242512 行未改动3839404142434445464748495051525354555657585960616263646566676869707172255 行未改动全部展开328329330331306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149233233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536622 行未改动38939039139215273933941529153015313953963973983994004014024034044051541406407408409410283 行未改动全部展开69469569669718336986997007018 行未改动71071171271318507147157167177181855719720721185818597227231861186272472572618647277281866729730731186973273373473518737367377387397407 行未改动748749750751188918901891189218931894189575275375475518971898189919001901756757758190519061907759760761762763191019111912764765766191476776819167691918191919201921770771772773774223 行未改动全部展开9989991000100121531002100310042155100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103:::success[模拟赛]- 初赛 - S - [2025](https://www.luogu.com.cn/contest/261748) - [2024](https://www.luogu.com.cn/contest/187650) - [2023](https://www.luogu.com.cn/contest/121700) - J - [2025](https://www.luogu.com.cn/contest/261747) - [2024](https://www.luogu.com.cn/contest/187649) - [2023](https://www.luogu.com.cn/contest/121699)- 复赛 - S - [2024](https://www.luogu.com.cn/contest/200849) - [2023](https://www.luogu.com.cn/contest/136700) - J - [2025](https://www.luogu.com.cn/contest/255793) - [2024](https://www.luogu.com.cn/contest/200686) - [2023](https://www.luogu.com.cn/contest/125612):::::success[trick]::::success[二项式定理 in 矩阵]$$ \sum_{j=0}^{n} \binom{n}{j} M^j = \sum_{j=0}^{n} \binom{n}{j} M^j \cdot I^{n-j} = (M + I)^n $$::::
::::success[决策覆盖]若状态 $A$ 能到达集合 $S$ 或状态 $B$,状态 $B$ 仅能到达集合 $S$,那么状态 $A$ 必胜。:::::::
:::::success[trick]::::success[操作抵消]对于先手,若无论如何操作后对方可以操作使得状态的某一部分完全相同(如奇偶性),此时先手必败。::::
::::success[$\times2+1$]对于构造,若希望答案计数为 $k$,此时有计数为 $1$ 的方案,并且能找出 $\times2$ 与 $+1$ 的操作方案,那么二进制拆开即可。::::
::::success[方案二选一]若两个方案加起来 $\leq 2k$,则其中有一个方案 $\leq k$。::::
::::success[回文括号序列]记 `(` 为 $1$,`)` 为 $0$。
记 $res_i$ 表示前 $i$ 个括号的和,有:12 行未改动```cppint solve(int x){return ((((x + (x & -x)) ^ x) >> 2) / (x & -x)) | (x + (x & -x));}```::::
::::success[区间dp转移]$$f_{i,l,r} = \sum f_{i-1, l', r'} ([l, r] \cap [l', r']\neq\varnothing$$
等价于:
$$pre_{i, x} = \sum_{l\leq r\leq x}f_{i, l, r}$$$$suf_{i, x} = \sum_{x\leq l\leq r}f_{i, l, r}$$$$f_{i, l, r} = pre_{i-1, m} - pre_{i-1, l-1} - suf_{i-1, r+1}$$
$pre,suf$ 的状态数少于 $f$,考虑抛弃 $f$。
$$\begin{aligned}pre_{i, x} &= \sum_{l\leq r\leq x}pre_{i-1, m} - \sum_{l\leq r\leq x}pre_{i-1, l-1} - \sum_{l\leq r\leq x}suf_{i-1, r+1} \\&=\frac{x(x+1)}{2}pre_{i-1,m}-\sum_{l \leq x}(x-l+1)pre_{i-1,l-1}-\sum_{r \leq x}r\times suf_{i-1, r+1}\end{aligned}$$
$$\begin{aligned} suf_{i, x} &= \sum_{x\leq l\leq r}pre_{i-1, m} - \sum_{x\leq l\leq r}pre_{i-1, l-1} - \sum_{x\leq l\leq r}suf_{i-1, r+1} \\&=\frac{(m-x+1)(m-x+2)}{2}pre_{i-1,m}-\sum_{x\leq l}(m-l+1)pre_{i-1,l-1}-\sum_{x\leq r}(r-x+1)suf_{i-1, r+1} \end{aligned}$$
考虑对称性或将 $pre, suf$ 并排放,可用矩阵乘法优化。:::::
:::::::success[插件]
255 行未改动全部展开
```:::
:::success[喵]```javascript// ==UserScript==// @name 喵// @namespace http://tampermonkey.net/// @version 1.3// @description 喵// @author 喵// @match *://*/*// @grant none// ==/UserScript==
(function() { 'use strict';
function processInput(target, isContentEditable) { let value = isContentEditable ? target.textContent : target.value; let cursorPos = isContentEditable ? getCaretPosition(target) : target.selectionStart;
if (cursorPos < 1 || value[cursorPos - 1] !== '。') return;
// 避免重复:前面已经是“喵。” if (cursorPos >= 2 && value[cursorPos - 2] === '喵') { return; }
const newValue = value.substring(0, cursorPos - 1) + '喵。' + value.substring(cursorPos);
if (isContentEditable) { const oldScrollTop = target.scrollTop; target.textContent = newValue; // 光标放在“喵。”之后 → cursorPos + 1 setCaretPosition(target, cursorPos + 1); target.scrollTop = oldScrollTop; } else { target.value = newValue; target.setSelectionRange(cursorPos + 1, cursorPos + 1); } }
function getCaretPosition(element) { const selection = window.getSelection(); if (selection.rangeCount === 0) return 0; const range = selection.getRangeAt(0).cloneRange(); range.selectNodeContents(element); range.setEnd(selection.getRangeAt(0).endContainer, selection.getRangeAt(0).endOffset); return range.toString().length; }
function setCaretPosition(element, pos) { // 先获取总文本长度,避免越界 const totalLength = element.textContent.length; if (pos > totalLength) pos = totalLength;
const selection = window.getSelection(); const range = document.createRange(); let charCount = 0; let found = false;
function walk(node) { if (found || node.nodeType !== Node.TEXT_NODE) return; const nodeLen = node.textContent.length; if (charCount + nodeLen >= pos) { const offset = pos - charCount; range.setStart(node, offset); range.collapse(true); found = true; } else { charCount += nodeLen; } }
// 使用 TreeWalker 更可靠地遍历文本节点 const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null, false); let node; while (!found && (node = walker.nextNode())) { walk(node); }
if (!found) { // 放在末尾 range.selectNodeContents(element); range.collapse(false); }
selection.removeAllRanges(); selection.addRange(range); }
document.addEventListener('input', function(e) { const t = e.target; const isEditable = t.isContentEditable; const isTextInput = (t.tagName === 'INPUT' && t.type === 'text') || t.tagName === 'TEXTAREA';
if (isEditable || isTextInput) { setTimeout(() => processInput(t, isEditable), 0); } }, true);
document.addEventListener('compositionend', function(e) { if (e.target.isContentEditable) { setTimeout(() => processInput(e.target, true), 0); } }, true);})();```:::
:::success[梦回考场]```javascript// ==UserScript==// @name 洛谷 - 梦回考场// @namespace http://tampermonkey.net/// @version 0.5// @description 洛谷题目页面改为NOI/NOIP/CSP经典PDF风格,享受沉浸(致郁)式刷题。// @author Jerrycyx (Luogu UID 545986)// @match https://www.luogu.com.cn/problem/*// @license MPL-2.0// @grant GM_addStyle// @require https://scriptcat.org/lib/513/2.1.0/ElementGetter.js#sha256=aQF7JFfhQ7Hi+weLrBlOsY24Z2ORjaxgZNoni7pAz5U=// @downloadURL https://update.greasyfork.dpdns.org/scripts/543195/%E6%B4%9B%E8%B0%B7%20-%20%E6%A2%A6%E5%9B%9E%E8%80%83%E5%9C%BA.user.js// @updateURL https://update.greasyfork.dpdns.org/scripts/543195/%E6%B4%9B%E8%B0%B7%20-%20%E6%A2%A6%E5%9B%9E%E8%80%83%E5%9C%BA.meta.js// ==/UserScript==
(function () { "use strict";
if (CheckUrl()) { console.log("[Luogu-RER] URL passed"); MainScript(); }
function CheckUrl() { const path = window.location.pathname; const validPrefixes = ["P", "B", "CF", "SP", "AT", "UVA", "T", "U"]; const regex = /^\/problem\/([^/]+)$/; const match = path.match(regex); if (!match) return false; if (!validPrefixes.some(prefix => match[1].startsWith(prefix))) return false; return true; }
async function MainScript() { console.log("[Luogu-RER] MainScript Running."); const mainElement = await elmGetter.get("#app > .main-container"); mainElement.classList.add("main-element"); mainElement.id = "Main-element"; const [oringinalProblemHeader, oringinalSidebar, problemElement] = await elmGetter.get([ ".theme-bg:nth-child(1) > .theme-fg > .columba-content-wrap.header-layout", "main > .columba-content-wrap > .sidebar-container > .side", "main > .columba-content-wrap > .sidebar-container > .main > .problem" ], mainElement); problemElement.classList.add("problem-element"); problemElement.id = "Problem-element";
(async function () { removeSome(1, "#app > nav"); removeSome(1, "#app > .top-bar"); removeSome(1, "#app > .page-loading"); removeSome(1, "#app > .nav-scrollbar");
GlobalStyles(); ProcessStrong(); ProcessA(); ProcessTable();
ProcessSampleBlocks() .then(() => removeAll(".io-sample > .io-sample-block button.lform-size-small", problemElement));
ProcessCodeBlocks() .then(() => { removeAll(".code-container > button.copy-button", problemElement); removeAll(".line-numbers-rows", problemElement); });
ProcessTitles() .then(ProcessImages);
BuildToolbar() .then(() => { removeSome(1, ".problem-block-actions", problemElement); oringinalSidebar.remove(); });
BuildStat() .then(BuildHeader) .then(() => removeSome(2, ".theme-bg", mainElement)); })();
async function GlobalStyles() { console.log("[Luogu-RER] GlobalStyles Running.");
elmGetter.each("#Problem-element p, #Problem-element ul, #Problem-element ol, #Problem-element .attachments", problemElement, e => { e.classList.add("custom-common-text"); }); GM_addStyle(` #Problem-element { --common-font-family: KaTeX_Main, SimSun, serif; --strong-font-family: KaTeX_Main, SimHei, sans-serif; } .custom-common-text { font-family: var(--common-font-family); font-weight: normal; } .custom-strong-text { font-family: var(--strong-font-family); font-weight: normal; } `);
GM_addStyle(` #Main-element { margin: 12px 0; width: auto; } #Main-element > main { background-color: unset; } @media (prefers-color-scheme: light) { body { background-color: #e6e6e6; } } @media (prefers-color-scheme: dark) { body { background-color: #333333; } } #Main-element > main > .columba-content-wrap { padding: 0px; } #Main-element > main > .columba-content-wrap > .sidebar-container { margin: unset; } #Problem-element { color: black; width: 100% max-width: 1191px; margin: 0 auto; padding: 77px 141px 156px 141px; border-radius: 0px; box-shadow: 0 1px 10px 0px #1a1a1a1a; }
#Problem-element p:not(li > p) { text-indent: 2em; } #Problem-element p, #Problem-element ul, #Problem-element ol, #Problem-element .attachments { font-size: 24px; line-height: 1.6; margin: unset; } #Problem-element ul, #Problem-element ol { margin-left: 1em; } #Problem-element :is(ul, ol) :is(ul, ol) { margin-left: unset; } #Problem-element :is(ul, ol) :is(ul, ol) li::marker { content: "– "; }
.katex:not(.katex-display .katex) { font-size: 1em; }
#Problem-element ::selection{ background-color: #99c1da; //TODO mix-blend-mode: multiply; color: inherit; }
#Problem-element :focus-visible { outline: 3px dashed black; } `); }
async function ProcessSampleBlocks() { console.log("[Luogu-RER] ProcessSampleBlocks Running.");
elmGetter.each("h2.lfe-h2", problemElement, h2 => { if (h2.textContent.trim() === "输入输出样例") { h2.remove(); } });
elmGetter.each(".io-sample > .io-sample-block b", problemElement, b => { const content = b.textContent.trim(); const regex = /^(输入|输出)\s*#(\d+)$/; const match = content.match(regex); if (match) { const type = match[1]; const num = match[2]; const h2 = document.createElement("h2"); h2.classList.add("lfe-h2"); h2.textContent = `样例 ${num} ${type}`; b.parentNode.parentNode.replaceChild(h2, b.parentNode);
} }); }
async function ProcessCodeBlocks() { console.log("[Luogu-RER] ProcessCodeBlocks Running.");
async function ProcessSingleCodeBlocks(e) { e.classList.add("code-block"); var lines = e.textContent.split("\n"); const fragment = document.createDocumentFragment(); lines.forEach((lineText, idx) => { const lineContainer = document.createElement("div"); lineContainer.classList.add("custom-code-line"); const lineNumber = document.createElement("span"); lineNumber.classList.add("custom-line-number"); lineNumber.textContent = idx + 1; const contentSpan = document.createElement("span"); contentSpan.classList.add("custom-code-content"); contentSpan.textContent = lineText === "" ? "\u200B" : lineText; lineContainer.appendChild(lineNumber); lineContainer.appendChild(contentSpan); fragment.appendChild(lineContainer); }); e.innerHTML = ""; e.appendChild(fragment); }
elmGetter.each(".io-sample-block pre", problemElement, ProcessSingleCodeBlocks); //elmGetter.each("pre > code[class^='language-'], pre > code[class*=' language-']", problemElement, ProcessSingleCodeBlocks);
GM_addStyle(` #Problem-element > .lfe-marked-wrap { overflow: visible; }
#Problem-element > .io-sample { margin: 0px; display: block; } #Problem-element > .io-sample > .io-sample-block { margin: 0px; }
#Problem-element pre, #Problem-element code, .custom-pre-line-number { font-family: Consolas !important; /* SB Luogu don't use that f**king "!important" */ background-color: unset; } #Problem-element pre, #Problem-element code { font-size: 24px; line-height: 1.5; } #Problem-element pre { margin: 27px -5px 62px 17px; } .code-block { position: relative; overflow: visible; }
#Problem-element .custom-line-number { position: absolute; text-align: right; right: 100%; font-size: 20px; color: #949494; padding-right: 14px; padding-top: 4px; }
#Problem-element code { border: none; } #Problem-element pre { border: solid 1px blue; border-radius: 0; padding: 5px; } `); }
async function ProcessTitles() { console.log("[Luogu-RER] ProcessTitles Running.");
elmGetter.each("h1, h2, h3, h4, h5, h6", problemElement, h => { h.classList.add("H123456", "custom-strong-text"); if (!h.classList.contains("custom-title")) { const text = h.textContent; if (text.length > 0) { if (text[0] !== "【") { h.insertBefore(document.createTextNode("【"), h.firstChild); } if (text[text.length - 1] !== "】") { h.appendChild(document.createTextNode("】")); } } } });
GM_addStyle(` .custom-title { text-align: center; } .H123456 { font-weight: normal; } #Problem-element .H123456:not(.custom-title) { text-indent: 1em; } #Problem-element h1 { font-size: 36px; margin: 37px 0px; border-bottom: unset; padding-bottom: unset; } #Problem-element h2 { margin-top: 43px; margin-bottom: 18px; font-size: 26px; border-bottom: unset; padding-bottom: unset; } #Problem-element > p.problem-block-actions:not(#problem-element :first-child) { margin-top: 43px; margin-bottom: 18px; } #Problem-element h3 { margin-top: 24px; margin-bottom: 7px; font-size: 25px; } #Problem-element h4, #Problem-element h5, #Problem-element h6 { margin-top: 10px; margin-bottom: 7px; font-size: 24px; } `); }
async function ProcessImages() { console.log("[Luogu-RER] ProcessImages Running.");
elmGetter.each("p, .H123456", problemElement, e => { function isValidChainImage(e) { if (e.tagName === 'IMG') return true; let current = e; while (current) { const childNodes = current.childNodes; if (childNodes.length !== 1 || childNodes[0].nodeType !== 1) { return false; } current = current.firstElementChild; if (current && current.tagName === 'IMG') { return true; } } } if (isValidChainImage(e)) e.classList.add("single-line-image"); });
GM_addStyle(` .single-line-image { text-indent: 0 !important; text-align: center; } `) }
async function ProcessStrong() { console.log("[Luogu-RER] ProcessStrong Running.");
elmGetter.each("strong", problemElement, strong => { strong.classList.add("custom-strong-text"); const fragment = document.createDocumentFragment(); const processNode = (node) => { if (node.nodeType === Node.TEXT_NODE) { const text = node.textContent; const segments = text.split(/([\u4e00-\u9fa5])/); segments.forEach(segment => { if (!segment) return;
if (/^[\u4e00-\u9fa5]$/.test(segment)) { const span = document.createElement("span"); span.classList.add("custom-hanzi-dot"); span.textContent = segment;
const svgNS = "http://www.w3.org/2000/svg"; const svg = document.createElementNS(svgNS, "svg"); svg.setAttribute("class", "custom-dot"); svg.setAttribute("viewBox", "0 0 10 10");
const circle = document.createElementNS(svgNS, "circle"); circle.setAttribute("cx", "5"); circle.setAttribute("cy", "5"); circle.setAttribute("r", "3"); circle.setAttribute("fill", "black");
svg.appendChild(circle); span.appendChild(svg); fragment.appendChild(span); } else { fragment.appendChild(document.createTextNode(segment)); } }); } else if (node.nodeType === Node.ELEMENT_NODE) { fragment.appendChild(node.cloneNode(true)); } }; strong.childNodes.forEach(node => processNode(node)); strong.innerHTML = ""; strong.appendChild(fragment); });
GM_addStyle(` .custom-hanzi-dot { position: relative; } .custom-hanzi-dot svg.custom-dot { height: 0.16em; position: absolute; left: 0.5em; bottom: -0.05em; transform: translateX(-50%); pointer-events: none; } `); }
async function ProcessA() { console.log("[Luogu-RER] ProcessA Running.");
elmGetter.each("a", problemElement, e => { e.classList.add("custom-strong-text"); });
GM_addStyle(` #Problem-element a { color: black; font-style: italic; transition: unset; } #Problem-element a:hover { filter: none; } `) }
async function ProcessTable() { console.log("[Luogu-RER] ProcessTable Running.");
elmGetter.each("table > thead > tr > th, table > tbody > tr > td", problemElement, e => { e.classList.add("custom-common-text"); });
GM_addStyle(` #Problem-element table { display: table; margin: 25px auto; width: fit-content; }
#Problem-element table > thead > tr { border-bottom: 3px solid black; } #Problem-element table > thead > tr > th, #Problem-element table > tbody > tr > td { font-size: 24px; border: 1px solid black; } #Problem-element table { border-top: 4px solid black; border-bottom: 4px solid black; border-left: 2px solid white; border-right: 2px solid white; } `) }
async function BuildToolbar() { GM_addStyle(` @media (prefers-color-scheme: light) { #Custom-toolbar { --toolbar-bg: #f7f7f7; --toolbar-border: #bebebe; --toolbar-text: #262626; --toolbar-button-on: #e5e5e5; --toolbar-button-on-bottom: #0072c9; --toolbar-button-hover: #eaeaea; --toolbar-button-active: #efefef; --toolbar-separator-color: #b6b6b6; --toolbar-shadow: 0px 4.8px 10.8px rgba(0,0,0,0.13), 0px 0px 4.7px rgba(0,0,0,0.11); } #Custom-toolbar-setting { --setting-menu-bg: #ffffff; --setting-item-hover: #ebebeb; --setting-menu-hr: #e0e0e0 } } @media (prefers-color-scheme: dark) { #Custom-toolbar { --toolbar-bg: #3b3b3b; --toolbar-border: #4f4f4f; --toolbar-text: #ffffff; --toolbar-button-on: #4d4d4d; --toolbar-button-on-bottom: #63ade5; --toolbar-button-hover: #484848; --toolbar-button-active: #424242; --toolbar-separator-color: #737373; --toolbar-shadow: rgba(0, 0, 0, 0.26) 0px 4.8px 10.8px, rgba(0, 0, 0, 0.22) 0px 0px 4.7px; } #Custom-toolbar-setting { --setting-menu-bg: #292929; --setting-item-hover: #313131; --setting-menu-hr: #545454; } } `)
console.log("[Luogu-RER] BuildToolbar Running.");
const toolbar = document.createElement("div"); toolbar.id = "Custom-toolbar"; toolbar.classList.add("custom-toolbar");
const toolbarLeft = document.createElement("div"); toolbarLeft.id = "Custom-toolbar-left"; toolbarLeft.classList.add("custom-toolbar-left");
const toolbarCenter = document.createElement("div"); toolbarCenter.id = "Custom-toolbar-center"; toolbarCenter.classList.add("custom-toolbar-center");
const toolbarRight = document.createElement("div"); toolbarRight.id = "Custom-toolbar-right"; toolbarRight.classList.add("custom-toolbar-right");
toolbar.append(toolbarLeft, toolbarCenter, toolbarRight); const documentApp = document.querySelector("#app"); documentApp.insertBefore(toolbar, documentApp.firstChild);
function RemoveAllVueDataAttributes(e) { Array.from(e.attributes).forEach(attr => { if (attr.name.startsWith('data-v-')) { e.removeAttribute(attr.name); } }); } function removeAllAttributes(e) { [...e.attributes].forEach(attr => e.removeAttribute(attr.name)); }
async function InitToolbarLeftLargeButton(selector, parent, id, stateUpdater) { const button = parent.querySelector(selector); removeAllAttributes(button); button.classList.add("custom-toolbar-button", "custom-toolbar-button-large"); button.id = id; toolbarLeft.appendChild(button); if (stateUpdater) stateUpdater(button); return button; }
const submitButton = await InitToolbarLeftLargeButton( "div > div > button[type='button']", oringinalProblemHeader, "Custom-toolbar-submit", btn => btn.classList.toggle( "custom-toolbar-button-on", window.location.hash === "#submit" ) ); new MutationObserver(() => submitButton.classList.toggle( "custom-toolbar-button-on", window.location.hash === "#submit" )).observe(document, { subtree: true, childList: true });
const leftSeparator1 = document.createElement("div"); leftSeparator1.classList.add("custom-toolbar-separator"); toolbarLeft.appendChild(leftSeparator1);
async function BuildModalButton(id, modalIndex) { const button = await InitToolbarLeftLargeButton( "div > div > button[type='button']", oringinalProblemHeader, id ); const modal = document.querySelectorAll("#app > div.modal")[modalIndex]; const updateState = () => button.classList.toggle( "custom-toolbar-button-on", !modal.classList.contains("hide") ); updateState(); new MutationObserver(updateState).observe(modal, { attributes: true, attributeFilter: ["class"] }); return button; } await BuildModalButton("Custom-toolbar-add-list", 0); await BuildModalButton("Custom-toolbar-copy-problem", 1);
const leftSeparator2 = document.createElement("div"); leftSeparator2.classList.add("custom-toolbar-separator"); toolbarLeft.appendChild(leftSeparator2);
problemElement.querySelectorAll(".problem-block-actions > *").forEach(actionButton => { const text = actionButton.textContent.trim(); if (text != "展开" && text != "进入 IDE 模式" && text != "显示翻译" && text != "隐藏翻译") { removeAllAttributes(actionButton); actionButton.className = "custom-toolbar-a"; toolbarLeft.appendChild(actionButton); } if (text == "显示翻译" || text == "隐藏翻译") {
} });
const rightActionMap = { "退出比赛模式": { id: "Custom-toolbar-a-exit" }, " 提交记录": { id: "Custom-toolbar-a-record" }, " 查看题解": { id: "Custom-toolbar-a-solution" }, " 题目反馈": { id: "Custom-toolbar-a-feedback" } }; oringinalSidebar.querySelectorAll("div a").forEach(e => { RemoveAllVueDataAttributes(e); e.classList.add("custom-toolbar-a"); const config = rightActionMap[e.textContent]; if (config) { e.id = config.id; toolbarRight.appendChild(e); } });
const rightSeparator1 = document.createElement("div"); rightSeparator1.classList.add("custom-toolbar-separator"); toolbarRight.appendChild(rightSeparator1);
const setting = document.createElement("div"); setting.id = "Custom-toolbar-setting"; setting.classList.add("custom-toolbar-setting"); toolbarRight.appendChild(setting);
const settingButton = document.createElement("button"); settingButton.id = "Custom-toolbar-setting-button"; settingButton.classList.add("custom-toolbar-setting-button", "custom-toolbar-button"); function CreateSettingSVG() { const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); svg.setAttribute("width", "20"); svg.setAttribute("height", "20"); svg.setAttribute("viewBox", "0 0 20 20"); const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); path.setAttribute("d", "M 1.91 7.38 A 8.5 8.5 0 0 1 3.7 4.3 a 0.5 0.5 0 0 1 0.54 -0.13 l 1.92 0.68 a 1 1 0 0 0 1.32 -0.76 l 0.36 -2 a 0.5 0.5 0 0 1 0.4 -0.4 a 8.53 8.53 0 0 1 3.55 0 c 0.2 0.04 0.35 0.2 0.38 0.4 l 0.37 2 a 1 1 0 0 0 1.32 0.76 l 1.92 -0.68 a 0.5 0.5 0 0 1 0.54 0.13 a 8.5 8.5 0 0 1 1.78 3.08 c 0.06 0.2 0 0.4 -0.15 0.54 l -1.56 1.32 a 1 1 0 0 0 0 1.52 l 1.56 1.32 a 0.5 0.5 0 0 1 0.15 0.54 a 8.5 8.5 0 0 1 -1.78 3.08 a 0.5 0.5 0 0 1 -0.54 0.13 l -1.92 -0.68 a 1 1 0 0 0 -1.32 0.76 l -0.37 2 a 0.5 0.5 0 0 1 -0.38 0.4 a 8.53 8.53 0 0 1 -3.56 0 a 0.5 0.5 0 0 1 -0.39 -0.4 l -0.36 -2 a 1 1 0 0 0 -1.32 -0.76 l -1.92 0.68 a 0.5 0.5 0 0 1 -0.54 -0.13 a 8.5 8.5 0 0 1 -1.78 -3.08 a 0.5 0.5 0 0 1 0.15 -0.54 l 1.56 -1.32 a 1 1 0 0 0 0 -1.52 L 2.06 7.92 a 0.5 0.5 0 0 1 -0.15 -0.54 Z m 1.06 0 l 1.3 1.1 a 2 2 0 0 1 0 3.04 l -1.3 1.1 c 0.3 0.79 0.71 1.51 1.25 2.16 l 1.6 -0.58 a 2 2 0 0 1 2.63 1.53 l 0.3 1.67 a 7.55 7.55 0 0 0 2.5 0 l 0.3 -1.67 a 2 2 0 0 1 2.64 -1.53 l 1.6 0.58 a 7.5 7.5 0 0 0 1.24 -2.16 l -1.3 -1.1 a 2 2 0 0 1 0 -3.04 l 1.3 -1.1 a 7.5 7.5 0 0 0 -1.25 -2.16 l -1.6 0.58 a 2 2 0 0 1 -2.63 -1.53 l -0.3 -1.67 a 7.55 7.55 0 0 0 -2.5 0 l -0.3 1.67 A 2 2 0 0 1 5.81 5.8 l -1.6 -0.58 a 7.5 7.5 0 0 0 -1.24 2.16 Z M 7.5 10 a 2.5 2.5 0 1 1 5 0 a 2.5 2.5 0 0 1 -5 0 Z m 1 0 a 1.5 1.5 0 1 0 3 0 a 1.5 1.5 0 0 0 -3 0 Z"); path.setAttribute("fill", getComputedStyle(toolbar).getPropertyValue("--toolbar-text")); svg.appendChild(path); return svg; } settingButton.appendChild(CreateSettingSVG()); setting.appendChild(settingButton);
const settingMenu = document.createElement("div"); settingMenu.id = "Custom-toolbar-setting-menu"; settingMenu.classList.add("custom-toolbar-setting-menu", "custom-toolbar-setting-menu-hidden"); setting.appendChild(settingMenu);
let globalClickListener = null; settingButton.addEventListener("click", function (e) { e.stopPropagation(); settingMenu.classList.remove("custom-toolbar-setting-menu-hidden"); if (globalClickListener) { document.removeEventListener("click", globalClickListener); } globalClickListener = function (event) { const isClickInsideMenu = settingMenu.contains(event.target); const isClickOnButton = settingButton.contains(event.target);
if (!isClickInsideMenu || isClickOnButton) { settingMenu.classList.add("custom-toolbar-setting-menu-hidden"); document.removeEventListener("click", globalClickListener); globalClickListener = null; } }; setTimeout(() => { document.addEventListener("click", globalClickListener); }, 0); });
function BuildSettingItemSwitch(text, onToggle, initialState = false) { const settingItem = document.createElement("button"); settingItem.classList.add("custom-toolbar-setting-item");
const checkbox = document.createElement("span"); checkbox.classList.add("custom-toolbar-setting-checkbox"); checkbox.innerHTML = '<svg style="width: 1.25em; height: 1.25em; vertical-align: middle; fill: currentColor; overflow: hidden;" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path d="M365.624235 692.484607 165.695786 492.556159 99.05297 559.198975 365.624235 825.77024 936.850128 254.54537 870.207311 187.902554Z" fill="#b3b3b3"></path></svg>';
const textSpan = document.createElement("span"); textSpan.classList.add("custom-toolbar-setting-text"); textSpan.textContent = text;
const content = document.createElement("div"); content.classList.add("custom-toolbar-setting-content"); content.appendChild(checkbox); content.appendChild(textSpan); settingItem.appendChild(content);
let enabled = initialState; checkbox.style.visibility = enabled ? "visible" : "hidden";
onToggle(enabled, text); settingItem.addEventListener("click", () => { enabled = !enabled; checkbox.style.visibility = enabled ? "visible" : "hidden"; onToggle(enabled, text); });
settingMenu.appendChild(settingItem);
return { getState: () => enabled, setState: (newState) => { enabled = newState; checkbox.style.visibility = enabled ? "visible" : "hidden"; onToggle(enabled, text); }, toggle: () => settingItem.click(), element: settingItem }; }
function SwitchStyle(enabled, styleId, enabledStyle, disabledStyle) { let styleElement = document.getElementById(styleId); if (!styleElement) { styleElement = document.createElement("style"); styleElement.id = styleId; document.head.appendChild(styleElement); } const cssRule = enabled ? enabledStyle : disabledStyle; styleElement.textContent = cssRule; }
BuildSettingItemSwitch("锁定工具栏", (enabled) => { SwitchStyle(enabled, "fix-toolbar-style", "#Custom-toolbar {\ position: sticky;\ top: 0;\ }", "#Custom-toolbar {\ position: fixed;\ top: 0;\ box-shadow: var(--toolbar-shadow)\ }");
let isNearTop = true, hideTimer = null;
if (enabled) { showToolbar(); if (hideTimer) { clearTimeout(hideTimer); hideTimer = null; } }
function showToolbar() { toolbar.style.top = "0"; if (hideTimer) { clearTimeout(hideTimer); hideTimer = null; } } function hideToolbar() { toolbar.style.top = "-41px"; }
function optimizedThrottle(func, limit) { let lastRan = 0; let ticking = false;
return function () { const context = this; const args = arguments; const now = Date.now();
if (now - lastRan >= limit) { if (!ticking) { requestAnimationFrame(function () { func.apply(context, args); lastRan = now; ticking = false; }); ticking = true; } } }; }
const handleMouseMove = optimizedThrottle(function (e) { if (enabled) return; const mouseY = e.clientY; const newState = mouseY <= 41;
if (newState !== isNearTop) { isNearTop = newState; if (isNearTop) { showToolbar(); } else { if (hideTimer) { clearTimeout(hideTimer); hideTimer = null; } hideTimer = setTimeout(hideToolbar, 2000); } } }, 100);
window.addEventListener('mousemove', handleMouseMove); }, true);
BuildSettingItemSwitch("样例复制时带行号", (enabled) => { SwitchStyle(enabled, "line-number-selection-style", "#Problem-element .custom-line-number { user-select: all; }", "#Problem-element .custom-line-number { user-select: none; }" ); }, false);
BuildSettingItemSwitch("显示时空限制", (enabled) => { SwitchStyle(enabled, "limit-show-style", "", ".custom-stat { display: none; }" ); }, true);
const settingHr1 = document.createElement("hr"); settingHr1.classList.add("custom-setting-hr"); settingMenu.appendChild(settingHr1);
const settingItemInfo = document.createElement("button"); settingItemInfo.classList.add("custom-toolbar-setting-item"); settingItemInfo.id = "Custom-setting-item-info"; settingItemInfo.textContent = "查看题目详细信息(暂不可用)"; settingMenu.appendChild(settingItemInfo);
GM_addStyle(` #Custom-toolbar { background-color: var(--toolbar-bg); border-bottom: 1px solid var(--toolbar-border);
z-index: 10; width: 100%; height: 41px; padding: 0px 4px; display: flex; justify-content: space-between; align-items: center; box-sizing: border-box;
transition: top 0.5s;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI'; } #Custom-toolbar-left, #Custom-toolbar-center, #Custom-toolbar-right { height: 100%; display: flex; align-items: center; }
#Custom-toolbar-left { justify-content: flex-start; margin-right: auto; } #Custom-toolbar-center { justify-content: center; margin-left: auto; margin-right: auto; } #Custom-toolbar-right { justify-content: flex-end; margin-left: auto; } #Custom-toolbar-setting-menu { position: absolute; right: 2px; width: max-content; }
.custom-toolbar-button:not(.custom-toolbar-button-large), .custom-toolbar-a { font-size: 15px; } .custom-toolbar-button-large { font-size: 16px; }
.custom-toolbar-button, .custom-toolbar-a { cursor: default; border: 2px solid transparent; border-radius: 2px;
padding: 0 8px; margin: 2px 0px; max-height: 100%;
display: flex; white-space: pre-wrap; justify-content: center; align-items: center;
color: var(--toolbar-text); background-color: var(--toolbar-bg); outline: none; transition: background-color 0.1s ease-in-out; } .custom-toolbar-button { height: 32px; } .custom-toolbar-a { height: 28px; } .custom-toolbar-a a { color: var(--toolbar-text); outline: none; }
.custom-toolbar-button-on { background-color: var(--toolbar-button-on); border-bottom-color: var(--toolbar-button-on-bottom); }
.custom-toolbar-button:hover, .custom-toolbar-a:hover { background-color: var(--toolbar-button-hover); filter: unset; } .custom-toolbar-button:active, .custom-toolbar-a:active { background-color: var(--toolbar-button-active); }
.custom-toolbar-separator { margin: 0 4px; width: 1px; height: 16px; background-color: var(--toolbar-separator-color); }
#app > .dropdown.shown { z-index: 12; }
#Custom-toolbar-setting-button { cursor: pointer; } #Custom-toolbar-setting-menu { display: flex; flex-direction: column;
background-color: var(--setting-menu-bg); padding: 5px 2px; border-radius: 10px; box-shadow: var(--toolbar-shadow); font-size: 15px;
transition: opacity 0.1s ease, visibility 0.1s ease; } .custom-toolbar-setting-menu-hidden { opacity: 0; visibility: hidden; } .custom-toolbar-setting-checkbox { margin-right: 0.5em; } .custom-toolbar-setting-item { width: auto; text-align: left;
padding: 5px 10px; margin: 0 4px; background-color: transparent; color: var(--toolbar-text); border: unset; border-radius: 4px; } .custom-toolbar-setting-item:hover { background-color: var(--setting-item-hover); } .custom-setting-hr { border: 1px var(--setting-menu-hr) solid; width: 100%; margin: 5px 0; } `); }
async function BuildStat() { const [timeLimit, memoryLimit] = (await elmGetter.get([ ".stat > .field:nth-child(3) > .stat-text.value", ".stat > .field:nth-child(4) > .stat-text.value" ], oringinalProblemHeader)).map(e => e.textContent.trim());
console.log("[Luogu-RER] BuildStat Running.");
const stat = document.createElement("div"); stat.classList.add("custom-stat", "custom-common-text");
const timeStat = document.createElement("div"); timeStat.classList.add("custom-time-stat"); timeStat.textContent = "时间限制:" + timeLimit;
const memoryStat = document.createElement("div"); memoryStat.classList.add("custom-memory-stat"); memoryStat.textContent = "空间限制:" + memoryLimit;
stat.append(timeStat, memoryStat); problemElement.insertBefore(stat, problemElement.firstChild);
GM_addStyle(` .custom-stat { font-size: 24px; display: flex; flex-wrap: wrap; justify-content: center; } .custom-time-stat, .custom-memory-stat { margin-left: 1em; margin-right: 1em; } `);
return stat; }
async function BuildHeader(stat) { console.log("[Luogu-RER] BuildHeader Running.");
const titleContent = (await elmGetter.get("h1.lfe-h1", oringinalProblemHeader)).textContent;
const title = document.createElement("h1"); title.classList.add("lfe-h1", "custom-title"); title.textContent = titleContent.substring(titleContent.indexOf(" ") + 1); problemElement.insertBefore(title, stat);
const customHeaderElement = document.createElement("header"); customHeaderElement.classList.add("custom-header", "custom-common-text"); problemElement.insertBefore(customHeaderElement, title);
const leftText = document.createElement("div"); leftText.classList.add("custom-header-left-text"); leftText.textContent = "洛谷 Luogu"; customHeaderElement.appendChild(leftText);
const rightText = document.createElement("div"); rightText.classList.add("custom-header-right-text"); rightText.textContent = titleContent; customHeaderElement.appendChild(rightText);
const hrElement = document.createElement("hr"); hrElement.classList.add("custom-header-hr"); customHeaderElement.appendChild(hrElement);
GM_addStyle(` .custom-header { font-size: 20px; display: flex; flex-wrap: wrap; margin: 0px 0px 48px 0px; } .custom-header-left-text, .custom-header-right-text { margin: 0px; } .custom-header-left-text { margin-right: auto; } .custom-header-hr { flex-basis: 100%; border: 1px solid #bfbfbf; margin: 0px; } `); } }
async function removeAll(selector, container = document) { elmGetter.each(selector, container, e => { e.remove(); }); } async function removeSome(number, selector, container = document) { for (let i = 1; i <= number; i++) { const e = await elmGetter.get(selector, container); e.remove(); } }})();```::::::::::
:::::::success[板子]::::::success[缺省源]```cpp#include <bits/stdc++.h>// #pragma GCC optimize(3,"Ofast","inline")#define int long longusing namespace std;namespace IO { const int LL=1<<20; char bbuf[LL],*pp1,*pp2,OOUT[LL],*pp3=OOUT; #define Gc() (pp1==pp2&&(pp2=(pp1=bbuf)+fread(bbuf,1,LL,stdin),pp1==pp2)?EOF:*pp1++) #define Pc(x) (pp3==OOUT+LL&&(fwrite(OOUT,1,LL,stdout),pp3=OOUT),*pp3++=(x)) struct F{~F(){fwrite(OOUT,1,pp3-OOUT,stdout);}}fff; template<typename T> inline void rd(T& x){x=0ll; char c=Gc(); bool xans=0; while(!isdigit(c))xans^=c=='-',c=Gc();while(isdigit(c))x=x*10+(c^48),c=Gc(); if(xans)x=-x;}inline void rd(char& c){do c=Gc();while(isspace(c));}inline void rd(string& s){s=""; char c; rd(c); do s+=c; while(!isspace(c=Gc())&&~c);}template<typename T,typename... A> inline void rd(T& x,A&... mat){rd(x),rd(mat...);}template<typename T> inline void wt(T x){if(x<0)Pc('-'),x=-x; static int s[45],t=0; do s[++t]=x%10; while(x/=10);while(t)Pc(s[t--]|48);}inline void wt(char c){Pc(c);}inline void wt(const char* s){while(*s)Pc(*s++);}inline void wt(string s){for(char c:s)Pc(c);}template<typename T,typename... A> inline void wt(T x,A... mat){wt(x),Pc(sizeof...(mat)?' ':'\n'),(wt(mat...),0);}} using namespace IO;#define fr(x) freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout);#define rep(i, l, r) for(int i = (l); i <= (r); ++i)#define urep(i, r, l) for(int i = (r); i >= (l); --i)#define ary array <int, 3>constexpr int inf = 0x3f3f3f3f3f3f3f3f, mod = 1000000007;#define _ 200005
signed main(){ return 0;}```::::::::::::success[数据结构]:::success[单向链表模板]```cppstruct Node 22 行未改动
:::success[并查集]
```cppstruct DSUnamespace DSU{ int fa[200005]; int siz[200005]; DSU(){for(int i = 1; i <= 200000; i++)fa[i] = i,siz[i] = 1;} int fa[_], siz[_]; inline void init(){for(int i = 1; i < _; i++)fa[i] = i,siz[i] = 1;} int find(int x){return fa[x] == x ? x : fa[x] = find(fa[x]);} void unite(int x, int y) { x = find(x), y = find(y); if(x == y)return; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; fa[y] = x; }}dsu;};```::: ::::success[平衡树]283 行未改动全部展开::::::::::success[矩阵]```cpp
struct Matrix{ int x, y; int a[sz][sz];8 行未改动 for (int k = 0; k <= T.y; ++k) { r = a[i][k]; for (int j = 0; j <= y; ++j) res.a[i][j] = (res.a[i][j] + T.a[k][j] * r) % mod; res.a[i][j] = (res.a[i][j] + (T.a[k][j] * r)); } return res; }
Matrix operator^(int val) const Matrix operator^(int x) const { Matrix res, bas; res.x = res.y = bas.x = bas.y = x; for (int i = 0; i <= x; ++i) for (int i = 0; i < sz; ++i) res.a[i][i] = 1; for (int i = 0; i <= x; ++i) for (int j = 0; j <= x; ++j) for (int i = 0; i < sz; ++i) for (int j = 0; j < sz; ++j) bas.a[i][j] = a[i][j]; while (val) while (x) { if (val & 1) if (x & 1) res = res * bas; bas = bas * bas; val >>= 1; x >>= 1; } return res; }}}mat, base;```::::::::::::::success[图论]7 行未改动```::::::success[dijkstra]```cpp//无负边权struct edge{int v, w;};struct node{ int u, dis; bool operator > (const node& a) const { return dis > a.dis;}}op;vector <ary> e[_];int dis[_], vis[_];priority_queue < ary, vector<ary>, greater<ary> >q;
int n, m;int dis[10005], vis[10005];vector<edge>e[10005];priority_queue<node, vector<node>, greater<node> >q;
void dijkstra() { memset(dis, 0x3f, sizeof(dis)); memset(vis, 0, sizeof(vis)); dis[1] = 0; q.push({1, 0}); memset(vis,0,sizeof(vis)); dis[s] = 0; q.push({0, s}); while(!q.empty()) { op = q.top();q.pop(); int u = op.u; if(vis[u])continue; int u = q.top()[1]; q.pop(); if(vis[u]) continue; vis[u] = 1; for(int i = 0; i < e[u].size(); i++) for(auto [w, v] : e[u]) { int v = e[u][i].v,w = e[u][i].w; if (dis[v] > dis[u] + w) { dis[v] = dis[u] + w; q.push({v, dis[v]}); } dis[v] = dis[u] + w, q.push({dis[v], v}); } }}```223 行未改动全部展开 }
:::::::::::success[快读]:::::success[数学]::::success[组合数学]```cppinline int read(){int x=0,f=1;char ch=getchar();while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}return x*f;}struct CNM{ int fact[_], infact[_], inv[_]; int qpow(int a, int b) { int res = 1; while (b > 0) { a %= mod; if (b & 1) res = res * a % mod; a = a * a; b >>= 1; } return res; } CNM() { inv[1] = fact[0] = infact[0] = fact[1] = infact[1] = 1; for (int i = 2; i < _; ++i) inv[i] = mod - (mod / i) * inv[mod % i] % mod, fact[i] = fact[i-1] * i % mod, infact[i] = infact[i-1] * inv[i] % mod; } int C(int n, int m) {return (n >= m && n >= 0) ? fact[n] * infact[n-m] % mod * infact[m] % mod : 0;}}C;```::::::::success[高斯消元]```cppnamespace gss{ double mat[_][_], xans[_]; const double eps = 1e-8; int solve(int n) { bool flg = false; rep(i, 1, n) { int mxi = 0; double maxv = 0; rep(j, (flg ? 1 : i), n) { if(j < i && fabs(mat[j][j] - 1) < eps) continue; if(fabs(mat[j][i]) > maxv) maxv = fabs(mat[j][i]), mxi = j; } if(maxv < eps) { flg = true; continue; } if(mxi != i) swap(mat[mxi], mat[i]); double inv = mat[i][i]; rep(j, i, n+1) mat[i][j] /= inv; rep(j, 1, n) { if(j == i) continue; double factor = mat[j][i]; rep(k, i, n+1) mat[j][k] -= mat[i][k] * factor; } } rep(i, 1, n) { bool az = true; rep(j, 1, n) if(fabs(mat[i][j]) > eps) { az = false; break; } if(az && fabs(mat[i][n+1]) > eps) return -1; } if(flg) return 0; rep(i, 1, n) xans[i] = mat[i][n+1]; return 1; }} ;```:::::::::
::::success[素数筛]```cppnamespace Sieve {std::bitset<_ / 2 + 1> isnt; std::vector<int> pri;void sieve(int n) {isnt.reset(); isnt[0] = 1; pri.clear();if (n >= 2) pri.emplace_back(2);for (int i = 1; i * 2 + 1 <= n; ++i) {if (!isnt[i]) {int p = i * 2 + 1;if (n / p >= p) for (int j = i * (i + 1) * 2; j * 2 + 1 <= n; j += p)isnt[j] = 1;pri.emplace_back(p);}}}inline bool check(int x) {if (x < 3) return x == 2;return (x & 1) && !isnt[x >> 1];}}using namespace Sieve;
```::::::::success[FastIO]```cpp// #define LOCALnamespace IO {#ifndef LOCAL const int L=1<<20; char buf[L],*p1,*p2,out[L],*p3=out; #define Gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,L,stdin),p1==p2)?EOF:*p1++) #define Pc(x) (p3==out+L&&(fwrite(out,1,L,stdout),p3=out),*p3++=(x)) struct F{~F(){fwrite(out,1,p3-out,stdout);}}f;#else #define Gc() getchar() #define Pc(x) putchar(x)#endif template<typename T> inline void rd(T& x){x=0; char c=Gc(); bool f=0; while(!isdigit(c))f^=c=='-',c=Gc();while(isdigit(c))x=x*10+(c^48),c=Gc(); if(f)x=-x;}inline void rd(char& c){do c=Gc();while(isspace(c));}inline void rd(string& s){s=""; char c; rd(c); do s+=c; while(!isspace(c=Gc())&&~c);}template<typename T,typename... A> inline void rd(T& x,A&... a){rd(x),rd(a...);}template<typename T> inline void wt(T x){if(x<0)Pc('-'),x=-x; static int s[45],t=0; do s[++t]=x%10; while(x/=10);while(t)Pc(s[t--]|48);}inline void wt(char c){Pc(c);}inline void wt(const char* s){while(*s)Pc(*s++);}inline void wt(string s){for(char c:s)Pc(c);}template<typename T,typename... A> inline void wt(T x,A... a){wt(x),Pc(sizeof...(a)?' ':'\n'),(wt(a...),0);}} using namespace IO;
```:::::::::::