正文
增加 194 行删除 1249 行
123456789101112131415161718192021222324252612 行未改动3940414243444546255 行未改动全部展开30230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150022 行未改动15231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545283 行未改动全部展开1829183018311832183318341835183618378 行未改动184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618777 行未改动18851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925223 行未改动全部展开2149215021512152215321542155215621572158:::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[回文括号序列]记 `(` 为 $1$,`)` 为 $0$。记 $res_i$ 表示前 $i$ 个括号的和,有:12 行未改动```cppint solve(int x){return ((((x + (x & -x)) ^ x) >> 2) / (x & -x)) | (x + (x & -x));}```::::::::::::::::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 + 1setCaretPosition(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; //TODOmix-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[数据结构]:::success[单向链表模板]```cppstruct Node22 行未改动:::success[并查集]```cppstruct DSU{int fa[200005];int siz[200005];DSU(){for(int i = 1; i <= 200000; 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[矩阵]```cppstruct 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;}return res;}Matrix operator^(int val) const{Matrix res, bas;res.x = res.y = bas.x = bas.y = x;for (int i = 0; i <= x; ++i)res.a[i][i] = 1;for (int i = 0; i <= x; ++i)for (int j = 0; j <= x; ++j)bas.a[i][j] = a[i][j];while (val){if (val & 1)res = res * bas;bas = bas * bas;val >>= 1;}return res;}}```::::::::::::::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;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});while(!q.empty()){op = q.top();q.pop();int u = op.u;if(vis[u])continue;vis[u] = 1;for(int i = 0; i < e[u].size(); i++){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]});}}}}```223 行未改动全部展开}:::::::::::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;}```:::::::::::1234567891011121314151617181920212223242512 行未改动3839404142434445464748495051525354555657585960616263646566676869707172255 行未改动全部展开32832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536622 行未改动389390391392393394395396397398399400401402403404405406407408409410283 行未改动全部展开6946956966976986997007018 行未改动7107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407 行未改动748749750751752753754755756757758759760761762763764765766767768769770771772773774223 行未改动全部展开99899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103:::::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[操作抵消]对于先手,若无论如何操作后对方可以操作使得状态的某一部分完全相同(如奇偶性),此时先手必败。::::::::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[板子]::::::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 _ 200005signed main(){return 0;}```::::::::::::success[数据结构]:::success[单向链表模板]```cppstruct Node22 行未改动:::success[并查集]```cppnamespace DSU{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;}};```:::::::success[平衡树]283 行未改动全部展开::::::::::success[矩阵]```cppstruct 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));}return res;}Matrix operator^(int x) const{Matrix res, bas;for (int i = 0; i < sz; ++i)res.a[i][i] = 1;for (int i = 0; i < sz; ++i)for (int j = 0; j < sz; ++j)bas.a[i][j] = a[i][j];while (x){if (x & 1)res = res * bas;bas = bas * bas;x >>= 1;}return res;}}mat, base;```::::::::::::::success[图论]7 行未改动```::::::success[dijkstra]```cppvector <ary> e[_];int dis[_], vis[_];priority_queue < ary, vector<ary>, greater<ary> >q;void dijkstra(){memset(dis, 0x3f, sizeof(dis));memset(vis,0,sizeof(vis));dis[s] = 0;q.push({0, s});while(!q.empty()){int u = q.top()[1]; q.pop();if(vis[u]) continue;vis[u] = 1;for(auto [w, v] : e[u]){if (dis[v] > dis[u] + w)dis[v] = dis[u] + w, q.push({dis[v], v});}}}```223 行未改动全部展开}::::::::::::success[数学]::::success[组合数学]```cppstruct 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 LOCALconst 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)#endiftemplate<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;```:::::::::::