Compare commits

..

2 Commits

Author SHA1 Message Date
c8e8f1f0cb Merge branch 'main' of https://git.zziyu.cn/Zengtudor/algorithm_2024 2024-10-12 19:30:59 +08:00
eac90c8b50 update 2024-10-12 19:29:37 +08:00
97 changed files with 2148166 additions and 2148159 deletions

12
.gitignore vendored
View File

@ -1,7 +1,7 @@
.*
build
!.gitignore
*.json
/cmake-build*
/build*
.*
build
!.gitignore
*.json
/cmake-build*
/build*
/test*.txt

View File

@ -1,27 +1,27 @@
cmake_minimum_required(VERSION 3.10)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_options(-Wall)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
message("Build type is [${CMAKE_BUILD_TYPE}]")
project(algorithm_2024)
include_directories(${CMAKE_CURRENT_LIST_DIR}/src/include)
file(GLOB_RECURSE SRC_LIST CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp)
foreach(SRC IN LISTS SRC_LIST)
get_filename_component(SRC_NAME_WE ${SRC} NAME_WE)
message("[${SRC}] will be build to [${SRC_NAME_WE}]")
add_executable(${SRC_NAME_WE} ${SRC})
endforeach()
cmake_minimum_required(VERSION 3.10)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_options(-Wall)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
message("Build type is [${CMAKE_BUILD_TYPE}]")
project(algorithm_2024)
include_directories(${CMAKE_CURRENT_LIST_DIR}/src/include)
file(GLOB_RECURSE SRC_LIST CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp)
foreach(SRC IN LISTS SRC_LIST)
get_filename_component(SRC_NAME_WE ${SRC} NAME_WE)
message("[${SRC}] will be build to [${SRC_NAME_WE}]")
add_executable(${SRC_NAME_WE} ${SRC})
endforeach()

464
LICENSE
View File

@ -1,232 +1,232 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for software and other kinds of works.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS
0. Definitions.
“This License” refers to version 3 of the GNU General Public License.
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
A “covered work” means either the unmodified Program or a work based on the Program.
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
1. Source Code.
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
7. Additional Terms.
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
11. Patents.
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
alogrithm_2024
Copyright (C) 2024 Zengtudor
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
alogrithm_2024 Copyright (C) 2024 Zengtudor
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/philosophy/why-not-lgpl.html>.
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for software and other kinds of works.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS
0. Definitions.
“This License” refers to version 3 of the GNU General Public License.
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
A “covered work” means either the unmodified Program or a work based on the Program.
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
1. Source Code.
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
7. Additional Terms.
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
11. Patents.
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
alogrithm_2024
Copyright (C) 2024 Zengtudor
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
alogrithm_2024 Copyright (C) 2024 Zengtudor
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -1,26 +1,26 @@
# algorithm_2024
algorithm_2024
## 错题本
### Luogu某题
#### 数组越界导致变量异常更改
### [OJ4980:拯救行动](http://noi.openjudge.cn/ch0205/4980/)
#### 未考虑无答案(特殊情况)时输出
#### 优先对联是从大到小排序重载运算符时需反向或者std::greater
```cpp
struct Status{
Point now;
ll step;
bool operator<(const Status &that)const noexcept{
return this->step > that.step;
}
};
std::priority_queue<Status> q;
# algorithm_2024
algorithm_2024
## 错题本
### Luogu某题
#### 数组越界导致变量异常更改
### [OJ4980:拯救行动](http://noi.openjudge.cn/ch0205/4980/)
#### 未考虑无答案(特殊情况)时输出
#### 优先对联是从大到小排序重载运算符时需反向或者std::greater
```cpp
struct Status{
Point now;
ll step;
bool operator<(const Status &that)const noexcept{
return this->step > that.step;
}
};
std::priority_queue<Status> q;
```

View File

@ -1,3 +1,3 @@
1
0
1
0
2

View File

@ -1,10 +1,10 @@
7 3
1 2
1 3
2 4
2 5
3 6
3 7
3 2 6 7
2 3 6
7 3
1 2
1 3
2 4
2 5
3 6
3 7
3 2 6 7
2 3 6
4 4 5 6 7

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +1,32 @@
2
1
2
2
2
2
1
2
1
2
2
1
2
2
2
2
2
1
2
2
2
1
2
2
2
2
0
2
2
2
2
2
2
1
2
2
2
2
1
2
1
2
2
1
2
2
2
2
2
1
2
2
2
1
2
2
2
2
0
2
2
2
2
2

View File

@ -1,332 +1,332 @@
300 32
12 230
46 12
12 126
290 1
16 98
115 290
226 17
17 229
268 185
290 82
40 285
171 151
40 1
300 124
132 268
1 81
40 240
268 255
89 268
257 290
118 158
151 289
268 254
134 290
169 256
131 295
40 55
1 151
124 136
144 1
108 17
151 3
40 166
124 59
174 151
188 12
268 168
231 124
256 5
50 48
145 268
235 213
177 290
268 148
17 137
292 268
14 17
40 258
212 30
131 10
124 219
12 206
151 104
158 1
124 19
30 223
51 151
151 178
48 83
266 17
290 287
72 40
87 290
23 124
1 246
276 268
1 124
17 67
221 268
29 158
71 151
12 155
283 48
151 260
17 232
268 293
151 196
243 290
20 17
1 48
252 268
256 194
98 101
256 147
239 131
54 213
131 49
40 159
151 291
247 131
158 164
61 151
157 17
107 151
268 133
12 156
56 124
17 98
124 199
290 7
98 2
86 268
191 17
227 1
131 182
97 30
151 135
47 124
150 131
284 256
131 99
151 275
290 201
131 129
266 209
17 256
170 40
268 294
117 1
297 151
290 140
163 1
124 80
17 208
12 162
17 22
60 124
149 268
195 1
44 290
207 12
213 90
290 17
66 290
272 131
113 290
151 250
1 30
40 259
238 290
253 98
288 124
161 1
48 13
175 48
142 290
264 131
172 290
131 122
58 17
213 17
234 40
69 124
277 213
70 124
245 268
100 151
222 290
262 1
186 1
179 268
74 30
211 131
290 153
299 268
187 151
256 184
57 131
131 190
48 263
1 193
290 112
213 278
17 154
110 48
1 200
39 98
244 30
27 158
282 290
151 225
48 8
268 1
202 30
17 12
21 151
17 237
1 121
94 124
281 151
125 268
98 204
6 98
160 48
48 35
1 298
213 279
106 30
167 290
40 248
11 290
173 256
85 151
93 17
17 189
43 290
17 123
151 224
1 251
141 131
218 12
119 158
76 98
198 290
256 114
290 130
17 36
273 12
88 256
213 146
40 15
98 210
120 1
241 40
91 1
131 216
124 25
268 152
151 127
242 256
109 40
228 131
79 268
236 124
143 290
9 290
203 290
1 233
183 124
31 151
265 256
192 290
290 176
269 256
65 40
274 17
131 261
151 138
139 1
290 52
286 1
124 105
30 296
75 12
131 95
180 17
131 78
205 1
41 124
1 267
26 268
98 116
181 213
151 24
124 165
220 290
30 96
40 271
214 213
53 131
256 103
268 73
84 268
32 131
290 37
131 28
280 290
63 1
12 34
215 268
102 48
40 128
12 217
256 249
62 1
42 17
266 111
290 33
270 17
124 68
18 12
17 92
64 17
213 38
290 197
77 98
268 45
131 290
151 4
4 217 68 241 63
2 137 39
3 176 159 26
7 298 14 300 45 73 257 254
5 68 1 271 116 164
6 60 231 135 165 118 146
2 197 239
15 35 216 189 14 228 222 248 184 125 191 25 50 119 167 179
2 247 239
3 234 196 44
10 196 52 166 236 244 129 235 49 29 87
2 153 295
2 230 294
31 141 165 140 208 50 189 167 153 13 84 268 52 203 287 197 133 38 180 191 127 92 95 275 69 148 106 160 285 71 145 183
3 137 195 228
2 106 164
3 21 168 70
3 233 220 282
20 42 8 231 272 15 188 207 247 284 148 77 206 241 216 200 17 201 265 103 43
7 94 130 61 29 182 74 30
2 100 46
3 177 113 205
4 35 222 268 252
5 255 221 293 132 97
77 196 275 190 193 230 226 242 80 280 243 63 119 189 241 84 111 19 244 100 113 90 265 69 105 186 184 104 76 233 299 65 199 71 145 97 259 101 134 225 42 43 221 240 274 284 256 131 253 125 138 272 56 300 121 23 222 158 47 168 142 91 207 62 147 58 246 278 262 118 197 127 10 238 26 79 34 223
2 179 99
2 242 256
28 117 215 282 219 251 178 97 169 128 174 277 187 36 105 139 138 206 132 86 232 141 77 84 16 212 118 14 136
9 157 217 54 102 280 166 225 191 182
2 44 47
4 42 166 53 128
12 115 209 150 15 90 61 63 17 223 207 25 120
300 32
12 230
46 12
12 126
290 1
16 98
115 290
226 17
17 229
268 185
290 82
40 285
171 151
40 1
300 124
132 268
1 81
40 240
268 255
89 268
257 290
118 158
151 289
268 254
134 290
169 256
131 295
40 55
1 151
124 136
144 1
108 17
151 3
40 166
124 59
174 151
188 12
268 168
231 124
256 5
50 48
145 268
235 213
177 290
268 148
17 137
292 268
14 17
40 258
212 30
131 10
124 219
12 206
151 104
158 1
124 19
30 223
51 151
151 178
48 83
266 17
290 287
72 40
87 290
23 124
1 246
276 268
1 124
17 67
221 268
29 158
71 151
12 155
283 48
151 260
17 232
268 293
151 196
243 290
20 17
1 48
252 268
256 194
98 101
256 147
239 131
54 213
131 49
40 159
151 291
247 131
158 164
61 151
157 17
107 151
268 133
12 156
56 124
17 98
124 199
290 7
98 2
86 268
191 17
227 1
131 182
97 30
151 135
47 124
150 131
284 256
131 99
151 275
290 201
131 129
266 209
17 256
170 40
268 294
117 1
297 151
290 140
163 1
124 80
17 208
12 162
17 22
60 124
149 268
195 1
44 290
207 12
213 90
290 17
66 290
272 131
113 290
151 250
1 30
40 259
238 290
253 98
288 124
161 1
48 13
175 48
142 290
264 131
172 290
131 122
58 17
213 17
234 40
69 124
277 213
70 124
245 268
100 151
222 290
262 1
186 1
179 268
74 30
211 131
290 153
299 268
187 151
256 184
57 131
131 190
48 263
1 193
290 112
213 278
17 154
110 48
1 200
39 98
244 30
27 158
282 290
151 225
48 8
268 1
202 30
17 12
21 151
17 237
1 121
94 124
281 151
125 268
98 204
6 98
160 48
48 35
1 298
213 279
106 30
167 290
40 248
11 290
173 256
85 151
93 17
17 189
43 290
17 123
151 224
1 251
141 131
218 12
119 158
76 98
198 290
256 114
290 130
17 36
273 12
88 256
213 146
40 15
98 210
120 1
241 40
91 1
131 216
124 25
268 152
151 127
242 256
109 40
228 131
79 268
236 124
143 290
9 290
203 290
1 233
183 124
31 151
265 256
192 290
290 176
269 256
65 40
274 17
131 261
151 138
139 1
290 52
286 1
124 105
30 296
75 12
131 95
180 17
131 78
205 1
41 124
1 267
26 268
98 116
181 213
151 24
124 165
220 290
30 96
40 271
214 213
53 131
256 103
268 73
84 268
32 131
290 37
131 28
280 290
63 1
12 34
215 268
102 48
40 128
12 217
256 249
62 1
42 17
266 111
290 33
270 17
124 68
18 12
17 92
64 17
213 38
290 197
77 98
268 45
131 290
151 4
4 217 68 241 63
2 137 39
3 176 159 26
7 298 14 300 45 73 257 254
5 68 1 271 116 164
6 60 231 135 165 118 146
2 197 239
15 35 216 189 14 228 222 248 184 125 191 25 50 119 167 179
2 247 239
3 234 196 44
10 196 52 166 236 244 129 235 49 29 87
2 153 295
2 230 294
31 141 165 140 208 50 189 167 153 13 84 268 52 203 287 197 133 38 180 191 127 92 95 275 69 148 106 160 285 71 145 183
3 137 195 228
2 106 164
3 21 168 70
3 233 220 282
20 42 8 231 272 15 188 207 247 284 148 77 206 241 216 200 17 201 265 103 43
7 94 130 61 29 182 74 30
2 100 46
3 177 113 205
4 35 222 268 252
5 255 221 293 132 97
77 196 275 190 193 230 226 242 80 280 243 63 119 189 241 84 111 19 244 100 113 90 265 69 105 186 184 104 76 233 299 65 199 71 145 97 259 101 134 225 42 43 221 240 274 284 256 131 253 125 138 272 56 300 121 23 222 158 47 168 142 91 207 62 147 58 246 278 262 118 197 127 10 238 26 79 34 223
2 179 99
2 242 256
28 117 215 282 219 251 178 97 169 128 174 277 187 36 105 139 138 206 132 86 232 141 77 84 16 212 118 14 136
9 157 217 54 102 280 166 225 191 182
2 44 47
4 42 166 53 128
12 115 209 150 15 90 61 63 17 223 207 25 120

View File

@ -1,158 +1,158 @@
2
2
2
2
3
3
3
1
3
2
3
2
3
2
3
3
3
3
2
2
2
2
3
3
3
1
2
3
1
3
3
2
3
3
3
3
1
2
3
1
3
3
2
2
3
3
2
2
3
2
3
3
2
2
2
3
3
2
2
2
2
2
3
3
2
3
3
2
3
2
3
3
1
3
2
3
2
3
3
2
3
2
2
3
2
2
3
2
3
2
3
3
3
2
3
3
2
2
2
3
2
3
2
3
2
3
3
3
3
2
2
2
1
3
2
3
3
2
3
2
3
2
3
3
3
2
2
3
2
3
3
2
2
3
3
2
2
3
2
3
3
2
3
1
2
3
2
3
2
1
2
3
3
2
3
2
3
3
2
2
2
2
3
3
3
1
3
2
3
2
3
2
3
3
3
3
2
2
2
2
3
3
3
1
2
3
1
3
3
2
3
3
3
3
1
2
3
1
3
3
2
2
3
3
2
2
3
2
3
3
2
2
2
3
3
2
2
2
2
2
3
3
2
3
3
2
3
2
3
3
1
3
2
3
2
3
3
2
3
2
2
3
2
2
3
2
3
2
3
3
3
2
3
3
2
2
2
3
2
3
2
3
2
3
3
3
3
2
2
2
1
3
2
3
3
2
3
2
3
2
3
3
3
2
2
3
2
3
3
2
2
3
3
2
2
3
2
3
3
2
3
1
2
3
2
3
2
1
2
3
3
2
3
2
3
3

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
2 2 2
2 2 2

View File

@ -1 +1 @@
458446679
458446679

View File

@ -1 +1 @@
1 326461 939834
1 326461 939834

View File

@ -1 +1 @@
19
19

View File

@ -1 +1 @@
4 2 2
4 2 2

View File

@ -1 +1 @@
195308839
195308839

View File

@ -1 +1 @@
2 3 28658230
2 3 28658230

View File

@ -1 +1 @@
773413093
773413093

View File

@ -1 +1 @@
606437 824052 577591
606437 824052 577591

View File

@ -1 +1 @@
389279880
389279880

View File

@ -1 +1 @@
986607978 603343652 29167602
986607978 603343652 29167602

View File

@ -1,90 +1,90 @@
/*
n行m列Ai取第i行最小值Bj取第j列最大值
*/
#include <algorithm>
#include <iostream>
#include <limits>
#include <set>
#include <vector>
using std::cin, std::cout;
using ull = unsigned long long;
using ui = unsigned int;
static constexpr size_t MAX_N {(size_t)1e3+5};
static constexpr ull MOD {998244353};
static size_t n,m,k;
ull mtx[MAX_N][MAX_N];
std::set<std::pair<size_t,ull>> s;
template<class T>
std::ostream&operator<<(std::ostream &os,const std::vector<T> &v)noexcept{
os<<"[";
for(size_t i{0};i<v.size()-1;i++){
os<<v[i]<<" ,";
}
cout<<v[v.size()-1]<<"]";
return os;
}
template<class T>
size_t hashVector1(const std::vector<T>& vec) noexcept{
size_t seed = 0;
for (size_t i = 0; i < vec.size(); ++i) {
// 结合元素的值和其索引来生成哈希
seed ^= std::hash<T>()((vec[i]+i)*(i << 2)) + 0x9e3779b9 - ((vec[i]*(i<<32))<<4) + ((vec[i]+i)<<2);
}
return seed;
}
template<class T>
size_t hashVector2(const std::vector<T>& vec) noexcept{
size_t seed = 0;
for (size_t i = 0; i < vec.size(); ++i) {
// 结合元素的值和其索引来生成哈希
seed ^= std::hash<T>()((vec[i]+i)*(i << 3)) + MOD<<(i%32) - ((vec[i]*(i<<16))<<3) + ((vec[i]+i)<<3);
}
return seed;
}
void dfs(size_t x, size_t y){
if(x>n){
// cout<<"x:"<<x<<" y:"<<y<<'\n';
std::vector<ull> v;
v.reserve(n+m);
for(size_t i=1;i<=n;i++){
ull ai {std::numeric_limits<decltype(ai)>::max()};
for(size_t j=1;j<=m;j++){
ai = std::min(ai,mtx[i][j]);
}
v.push_back(ai);
}
for(size_t j {1};j<=m;j++){
ull bj {std::numeric_limits<decltype(bj)>::min()};
for(size_t i{1};i<=n;i++){
bj = std::max(bj,mtx[i][j]);
}
v.push_back(bj);
}
// cout<<v<<"\n";
// cout<<hashVector1(v)<<','<<hashVector2(v)<<'\n';
s.insert({hashVector1(v),hashVector2(v)});
return;
}
for(ull i{1};i<=k;i++){
mtx[x][y]=i;
if(y+1>m){
dfs(x+1,1);
}else{
dfs(x,y+1);
}
}
}
int main(){
cin>>n>>m>>k;
dfs(1,1);
cout<<s.size()%MOD<<'\n';
/*
n行m列Ai取第i行最小值Bj取第j列最大值
*/
#include <algorithm>
#include <iostream>
#include <limits>
#include <set>
#include <vector>
using std::cin, std::cout;
using ull = unsigned long long;
using ui = unsigned int;
static constexpr size_t MAX_N {(size_t)1e3+5};
static constexpr ull MOD {998244353};
static size_t n,m,k;
ull mtx[MAX_N][MAX_N];
std::set<std::pair<size_t,ull>> s;
template<class T>
std::ostream&operator<<(std::ostream &os,const std::vector<T> &v)noexcept{
os<<"[";
for(size_t i{0};i<v.size()-1;i++){
os<<v[i]<<" ,";
}
cout<<v[v.size()-1]<<"]";
return os;
}
template<class T>
size_t hashVector1(const std::vector<T>& vec) noexcept{
size_t seed = 0;
for (size_t i = 0; i < vec.size(); ++i) {
// 结合元素的值和其索引来生成哈希
seed ^= std::hash<T>()((vec[i]+i)*(i << 2)) + 0x9e3779b9 - ((vec[i]*(i<<32))<<4) + ((vec[i]+i)<<2);
}
return seed;
}
template<class T>
size_t hashVector2(const std::vector<T>& vec) noexcept{
size_t seed = 0;
for (size_t i = 0; i < vec.size(); ++i) {
// 结合元素的值和其索引来生成哈希
seed ^= std::hash<T>()((vec[i]+i)*(i << 3)) + MOD<<(i%32) - ((vec[i]*(i<<16))<<3) + ((vec[i]+i)<<3);
}
return seed;
}
void dfs(size_t x, size_t y){
if(x>n){
// cout<<"x:"<<x<<" y:"<<y<<'\n';
std::vector<ull> v;
v.reserve(n+m);
for(size_t i=1;i<=n;i++){
ull ai {std::numeric_limits<decltype(ai)>::max()};
for(size_t j=1;j<=m;j++){
ai = std::min(ai,mtx[i][j]);
}
v.push_back(ai);
}
for(size_t j {1};j<=m;j++){
ull bj {std::numeric_limits<decltype(bj)>::min()};
for(size_t i{1};i<=n;i++){
bj = std::max(bj,mtx[i][j]);
}
v.push_back(bj);
}
// cout<<v<<"\n";
// cout<<hashVector1(v)<<','<<hashVector2(v)<<'\n';
s.insert({hashVector1(v),hashVector2(v)});
return;
}
for(ull i{1};i<=k;i++){
mtx[x][y]=i;
if(y+1>m){
dfs(x+1,1);
}else{
dfs(x,y+1);
}
}
}
int main(){
cin>>n>>m>>k;
dfs(1,1);
cout<<s.size()%MOD<<'\n';
}

View File

@ -1,8 +1,8 @@
YES
NO
YES
NO
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
YES

View File

@ -1,9 +1,9 @@
8
0 0 0
0 1 0
1 0 1
1 1 0
2 0 1
2 1 0
2 1 1
2 0 2
8
0 0 0
0 1 0
1 0 1
1 1 0
2 0 1
2 1 0
2 1 1
2 0 2

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
0
1
1
0
1
1
0

View File

@ -1,5 +1,5 @@
0
3
0
4
0
3
0
4
1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,179 +1,179 @@
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+5;
struct node
{
ll mx,sum,t,sv,add,tag,len;
};
node tr[maxn<<2];
int n,q;
ll d[maxn<<2];
inline void mdf(int id,int k,ll w)
{
if(k==0)
{
tr[id].mx+=w;
tr[id].t+=w*w*tr[id].len+tr[id].sv*w+tr[id].sum*w;
tr[id].sum+=w*tr[id].len;
tr[id].sv+=w*tr[id].len;
tr[id].add+=w;
}
if(k==1)
{
tr[id].mx=w,tr[id].t=w*w*tr[id].len,tr[id].sum=w*tr[id].len,tr[id].sv=w*tr[id].len;
tr[id].add=0,tr[id].tag=w;
}
}
inline void pushdown(int id)
{
if(tr[id].tag)
{
mdf(id<<1,1,tr[id].tag);
mdf(id<<1|1,1,tr[id].tag);
}
if(tr[id].add)
{
mdf(id<<1,0,tr[id].add);
mdf(id<<1|1,0,tr[id].add);
}
tr[id].tag=tr[id].add=0;
}
node calc(node nd,int id)
{
node ret=nd;
if(tr[id].len==1)
{
ret.mx=max(ret.mx,tr[id].mx);
ret.sum+=tr[id].sum;
ret.t+=tr[id].sum*ret.mx;
ret.sv+=ret.mx;
ret.len+=tr[id].len;
}
else
{
pushdown(id);
if(tr[id<<1].mx>=nd.mx)
{
ret=calc(nd,id<<1);
ret.mx=max(ret.mx,tr[id<<1|1].mx);
ret.sum+=tr[id<<1|1].sum;
ret.t+=tr[id].t-tr[id<<1].t;
ret.sv+=tr[id].sv-tr[id<<1].sv;
ret.len+=tr[id<<1|1].len;
}
else
{
nd.sum+=tr[id<<1].sum;
nd.t+=tr[id<<1].sum*nd.mx;
nd.sv+=tr[id<<1].len*nd.mx;
nd.len+=tr[id<<1].len;
ret=calc(nd,id<<1|1);
}
}
return ret;
}
inline void pushup(int id)
{
tr[id]=calc(tr[id<<1],id<<1|1);
tr[id].tag=tr[id].add=0;
}
void build(int id,int l,int r)
{
if(l==r)
{
tr[id]=(node){d[l],d[l],d[l]*d[l],d[l],0,0,1};
return;
}
int mid=(l+r)>>1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
pushup(id);
}
void update(int id,int l,int r,int x,int y,int k,ll w)
{
if(l>=x && r<=y)
{
mdf(id,k,w);
return;
}
int mid=(l+r)>>1;
pushdown(id);
if(x<=mid) update(id<<1,l,mid,x,y,k,w);
if(y>mid) update(id<<1|1,mid+1,r,x,y,k,w);
pushup(id);
}
int num[maxn],cnt,L[maxn],R[maxn];
void get_num(int id,int l,int r,int x,int y)
{
if(l>=x && r<=y)
{
cnt++;
num[cnt]=id,L[cnt]=l,R[cnt]=r;
return;
}
int mid=(l+r)>>1;
pushdown(id);
if(x<=mid) get_num(id<<1,l,mid,x,y);
if(y>mid) get_num(id<<1|1,mid+1,r,x,y);
}
int get_pos(int id,int l,int r,node nd,ll t)
{
if(l==r) return l;
int mid=(l+r)>>1;
pushdown(id);
node dt=calc(nd,id<<1);
if(dt.t<=t) return get_pos(id<<1|1,mid+1,r,dt,t);
else return get_pos(id<<1,l,mid,nd,t);
}
int main()
{
//system("fc training.out training6.ans /W");
//return 0;
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen("training6.in","r",stdin);
//freopen("training.out","w",stdout);
int fl;
node nd,dt;
char opt;
ll s,t,w;
cin>>n>>q;
for(int i=0;i<n;i++) cin>>d[i];
build(1,0,n-1);
while(q--)
{
cin>>opt>>s>>t;
if(opt=='P')
{
cin>>w;
if(s<=t) update(1,0,n-1,s,t,0,w);
else update(1,0,n-1,0,t,0,w),update(1,0,n-1,s,n-1,0,w);
}
if(opt=='R')
{
cin>>w;
if(s<=t) update(1,0,n-1,s,t,1,w);
else update(1,0,n-1,0,t,1,w),update(1,0,n-1,s,n-1,1,w);
}
if(opt=='Q')
{
fl=0,cnt=0,nd=(node){0,0,0,0,0,0,0};
get_num(1,0,n-1,s,n-1);
get_num(1,0,n-1,0,n-1);
for(int i=1;i<=cnt;i++)
{
dt=calc(nd,num[i]);
if(dt.t>t)
{
fl=1;
cout<<get_pos(num[i],L[i],R[i],nd,t)<<'\n';
break;
}
nd=dt;
}
if(fl==0) cout<<get_pos(1,0,n-1,nd,(t-nd.t)%(tr[1].sum*tr[1].mx)+nd.t)<<'\n';
}
}
return 0;
}
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+5;
struct node
{
ll mx,sum,t,sv,add,tag,len;
};
node tr[maxn<<2];
int n,q;
ll d[maxn<<2];
inline void mdf(int id,int k,ll w)
{
if(k==0)
{
tr[id].mx+=w;
tr[id].t+=w*w*tr[id].len+tr[id].sv*w+tr[id].sum*w;
tr[id].sum+=w*tr[id].len;
tr[id].sv+=w*tr[id].len;
tr[id].add+=w;
}
if(k==1)
{
tr[id].mx=w,tr[id].t=w*w*tr[id].len,tr[id].sum=w*tr[id].len,tr[id].sv=w*tr[id].len;
tr[id].add=0,tr[id].tag=w;
}
}
inline void pushdown(int id)
{
if(tr[id].tag)
{
mdf(id<<1,1,tr[id].tag);
mdf(id<<1|1,1,tr[id].tag);
}
if(tr[id].add)
{
mdf(id<<1,0,tr[id].add);
mdf(id<<1|1,0,tr[id].add);
}
tr[id].tag=tr[id].add=0;
}
node calc(node nd,int id)
{
node ret=nd;
if(tr[id].len==1)
{
ret.mx=max(ret.mx,tr[id].mx);
ret.sum+=tr[id].sum;
ret.t+=tr[id].sum*ret.mx;
ret.sv+=ret.mx;
ret.len+=tr[id].len;
}
else
{
pushdown(id);
if(tr[id<<1].mx>=nd.mx)
{
ret=calc(nd,id<<1);
ret.mx=max(ret.mx,tr[id<<1|1].mx);
ret.sum+=tr[id<<1|1].sum;
ret.t+=tr[id].t-tr[id<<1].t;
ret.sv+=tr[id].sv-tr[id<<1].sv;
ret.len+=tr[id<<1|1].len;
}
else
{
nd.sum+=tr[id<<1].sum;
nd.t+=tr[id<<1].sum*nd.mx;
nd.sv+=tr[id<<1].len*nd.mx;
nd.len+=tr[id<<1].len;
ret=calc(nd,id<<1|1);
}
}
return ret;
}
inline void pushup(int id)
{
tr[id]=calc(tr[id<<1],id<<1|1);
tr[id].tag=tr[id].add=0;
}
void build(int id,int l,int r)
{
if(l==r)
{
tr[id]=(node){d[l],d[l],d[l]*d[l],d[l],0,0,1};
return;
}
int mid=(l+r)>>1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
pushup(id);
}
void update(int id,int l,int r,int x,int y,int k,ll w)
{
if(l>=x && r<=y)
{
mdf(id,k,w);
return;
}
int mid=(l+r)>>1;
pushdown(id);
if(x<=mid) update(id<<1,l,mid,x,y,k,w);
if(y>mid) update(id<<1|1,mid+1,r,x,y,k,w);
pushup(id);
}
int num[maxn],cnt,L[maxn],R[maxn];
void get_num(int id,int l,int r,int x,int y)
{
if(l>=x && r<=y)
{
cnt++;
num[cnt]=id,L[cnt]=l,R[cnt]=r;
return;
}
int mid=(l+r)>>1;
pushdown(id);
if(x<=mid) get_num(id<<1,l,mid,x,y);
if(y>mid) get_num(id<<1|1,mid+1,r,x,y);
}
int get_pos(int id,int l,int r,node nd,ll t)
{
if(l==r) return l;
int mid=(l+r)>>1;
pushdown(id);
node dt=calc(nd,id<<1);
if(dt.t<=t) return get_pos(id<<1|1,mid+1,r,dt,t);
else return get_pos(id<<1,l,mid,nd,t);
}
int main()
{
//system("fc training.out training6.ans /W");
//return 0;
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen("training6.in","r",stdin);
//freopen("training.out","w",stdout);
int fl;
node nd,dt;
char opt;
ll s,t,w;
cin>>n>>q;
for(int i=0;i<n;i++) cin>>d[i];
build(1,0,n-1);
while(q--)
{
cin>>opt>>s>>t;
if(opt=='P')
{
cin>>w;
if(s<=t) update(1,0,n-1,s,t,0,w);
else update(1,0,n-1,0,t,0,w),update(1,0,n-1,s,n-1,0,w);
}
if(opt=='R')
{
cin>>w;
if(s<=t) update(1,0,n-1,s,t,1,w);
else update(1,0,n-1,0,t,1,w),update(1,0,n-1,s,n-1,1,w);
}
if(opt=='Q')
{
fl=0,cnt=0,nd=(node){0,0,0,0,0,0,0};
get_num(1,0,n-1,s,n-1);
get_num(1,0,n-1,0,n-1);
for(int i=1;i<=cnt;i++)
{
dt=calc(nd,num[i]);
if(dt.t>t)
{
fl=1;
cout<<get_pos(num[i],L[i],R[i],nd,t)<<'\n';
break;
}
nd=dt;
}
if(fl==0) cout<<get_pos(1,0,n-1,nd,(t-nd.t)%(tr[1].sum*tr[1].mx)+nd.t)<<'\n';
}
}
return 0;
}

View File

@ -1,202 +1,202 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200001;
int n,q;
int a[N];
struct node{
int mx;
ll sm,smx,tt;
int tg1,tg2;
}t[N*4];
#define ls (p<<1)
#define rs (p<<1|1)
#define mid (l+r>>1)
void build(int p,int l,int r){
for(int i=l;i<=r;i++){
t[p].mx=max(t[p].mx,a[i]);
t[p].sm+=a[i];
t[p].smx+=t[p].mx;
t[p].tt+=1ll*t[p].mx*a[i];
}
if(l==r)return;
build(ls,l,mid);
build(rs,mid+1,r);
}
void pushdown(int p,int l,int r){
int tg;
if(t[p].tg1){
tg=t[p].tg1;
t[p].tg1=0;
t[ls].mx=t[rs].mx=tg;
t[ls].sm=1ll*(mid-l+1)*tg,t[rs].sm=1ll*(r-mid)*tg;
t[ls].smx=t[ls].sm,t[rs].smx=t[rs].sm;
t[ls].tt=t[ls].sm*tg,t[rs].tt=t[rs].sm*tg;
t[ls].tg1=t[rs].tg1=tg;
t[ls].tg2=t[rs].tg2=0;
}
if(t[p].tg2){
tg=t[p].tg2;
t[p].tg2=0;
t[ls].mx+=tg,t[rs].mx+=tg;
t[ls].tt+=tg*(1ll*tg*(mid-l+1)+t[ls].sm+t[ls].smx),t[rs].tt+=tg*(1ll*tg*(r-mid)+t[rs].sm+t[rs].smx);
t[ls].sm+=1ll*(mid-l+1)*tg,t[rs].sm+=1ll*(r-mid)*tg;
t[ls].smx+=1ll*(mid-l+1)*tg,t[rs].smx+=1ll*(r-mid)*tg;
t[ls].tg2+=tg,t[rs].tg2+=tg;
}
}
int qmx;
ll qsmx,qtt;
void query(int p,int l,int r){
if(l==r){
if(qmx>t[p].mx)qsmx+=qmx,qtt+=qmx*t[p].sm;
else qsmx+=t[p].mx,qtt+=t[p].tt,qmx=t[p].mx;
return;
}
pushdown(p,l,r);
if(qmx>t[ls].mx){
qsmx+=1ll*qmx*(mid-l+1);
qtt+=qmx*t[ls].sm;
query(rs,mid+1,r);
}
else{
qsmx+=t[p].smx-t[ls].smx;
qtt+=t[p].tt-t[ls].tt;
query(ls,l,mid);
qmx=t[p].mx;
}
}
void update(int p,int l,int r){
t[p].mx=max(t[ls].mx,t[rs].mx);
t[p].sm=t[ls].sm+t[rs].sm;
qmx=t[ls].mx;
qsmx=t[ls].smx;
qtt=t[ls].tt;
query(rs,mid+1,r);
t[p].smx=qsmx;
t[p].tt=qtt;
}
void modify1(int p,int l,int r,int x,int y,int d){
if(x<=l&&r<=y){
t[p].mx=d;
t[p].sm=1ll*(r-l+1)*d;
t[p].smx=t[p].sm;
t[p].tt=t[p].sm*d;
t[p].tg1=d;
t[p].tg2=0;
return;
}
pushdown(p,l,r);
if(x<=mid)modify1(ls,l,mid,x,y,d);
if(mid<y)modify1(rs,mid+1,r,x,y,d);
update(p,l,r);
}
void modify2(int p,int l,int r,int x,int y,int d){
if(x<=l&&r<=y){
t[p].mx+=d;
t[p].tt+=d*(1ll*d*(r-l+1)+t[p].sm+t[p].smx);
t[p].sm+=1ll*(r-l+1)*d;
t[p].smx+=1ll*(r-l+1)*d;
t[p].tg2+=d;
return;
}
pushdown(p,l,r);
if(x<=mid)modify2(ls,l,mid,x,y,d);
if(mid<y)modify2(rs,mid+1,r,x,y,d);
update(p,l,r);
}
struct seg{
int p,l,r;
}b[100];
int m;
void getseg(int p,int l,int r,int x,int y){
if(x<=l&&r<=y){
b[++m]=(seg){p,l,r};
return;
}
pushdown(p,l,r);
if(x<=mid)getseg(ls,l,mid,x,y);
if(mid<y)getseg(rs,mid+1,r,x,y);
}
int gettt(int p,int l,int r,ll tm){
if(l==r){
query(p,l,r);
if(qtt>tm)return l-1;
return l;
}
pushdown(p,l,r);
int mx=qmx;
ll tt=qtt;
query(ls,l,mid);
if(qtt>tm){
qmx=mx,qtt=tt;
return gettt(ls,l,mid,tm);
}
return gettt(rs,mid+1,r,tm);
}
int getsm(int p,int l,int r,ll tm){
if(l==r){
if(t[p].sm>tm)return l-1;
return l;
}
pushdown(p,l,r);
if(t[ls].sm>tm)return getsm(ls,l,mid,tm);
return getsm(rs,mid+1,r,tm-t[ls].sm);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>q;
for(int i=0;i<n;i++)cin>>a[i];
build(1,0,n-1);
while(q--){
char op[2];
cin>>op;
if(op[0]=='R'){
int l,r,d;
cin>>l>>r>>d;
if(l<=r)modify1(1,0,n-1,l,r,d);
else modify1(1,0,n-1,l,n-1,d),modify1(1,0,n-1,0,r,d);
}
if(op[0]=='P'){
int l,r,d;
cin>>l>>r>>d;
if(l<=r)modify2(1,0,n-1,l,r,d);
else modify2(1,0,n-1,l,n-1,d),modify2(1,0,n-1,0,r,d);
}
if(op[0]=='Q'){
int s;
ll tm;
cin>>s>>tm;
m=0;
getseg(1,0,n-1,s,n-1);
if(s)getseg(1,0,n-1,0,s-1);
bool flag=0;
int mx=0;
ll tt=0;
for(int i=1;i<=m;i++){
qmx=mx,qtt=tt;
query(b[i].p,b[i].l,b[i].r);
if(qtt>tm){
qmx=mx,qtt=tt;
cout<<(gettt(b[i].p,b[i].l,b[i].r,tm)+1)%n<<'\n';
flag=1;
break;
}
mx=qmx,tt=qtt;
}
if(flag)continue;
tm-=qtt;
tm/=t[1].mx;
tm%=t[1].sm;
for(int i=1;i<=m;i++){
if(t[b[i].p].sm>tm){
cout<<(getsm(b[i].p,b[i].l,b[i].r,tm)+1)%n<<'\n';
break;
}
tm-=t[b[i].p].sm;
}
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200001;
int n,q;
int a[N];
struct node{
int mx;
ll sm,smx,tt;
int tg1,tg2;
}t[N*4];
#define ls (p<<1)
#define rs (p<<1|1)
#define mid (l+r>>1)
void build(int p,int l,int r){
for(int i=l;i<=r;i++){
t[p].mx=max(t[p].mx,a[i]);
t[p].sm+=a[i];
t[p].smx+=t[p].mx;
t[p].tt+=1ll*t[p].mx*a[i];
}
if(l==r)return;
build(ls,l,mid);
build(rs,mid+1,r);
}
void pushdown(int p,int l,int r){
int tg;
if(t[p].tg1){
tg=t[p].tg1;
t[p].tg1=0;
t[ls].mx=t[rs].mx=tg;
t[ls].sm=1ll*(mid-l+1)*tg,t[rs].sm=1ll*(r-mid)*tg;
t[ls].smx=t[ls].sm,t[rs].smx=t[rs].sm;
t[ls].tt=t[ls].sm*tg,t[rs].tt=t[rs].sm*tg;
t[ls].tg1=t[rs].tg1=tg;
t[ls].tg2=t[rs].tg2=0;
}
if(t[p].tg2){
tg=t[p].tg2;
t[p].tg2=0;
t[ls].mx+=tg,t[rs].mx+=tg;
t[ls].tt+=tg*(1ll*tg*(mid-l+1)+t[ls].sm+t[ls].smx),t[rs].tt+=tg*(1ll*tg*(r-mid)+t[rs].sm+t[rs].smx);
t[ls].sm+=1ll*(mid-l+1)*tg,t[rs].sm+=1ll*(r-mid)*tg;
t[ls].smx+=1ll*(mid-l+1)*tg,t[rs].smx+=1ll*(r-mid)*tg;
t[ls].tg2+=tg,t[rs].tg2+=tg;
}
}
int qmx;
ll qsmx,qtt;
void query(int p,int l,int r){
if(l==r){
if(qmx>t[p].mx)qsmx+=qmx,qtt+=qmx*t[p].sm;
else qsmx+=t[p].mx,qtt+=t[p].tt,qmx=t[p].mx;
return;
}
pushdown(p,l,r);
if(qmx>t[ls].mx){
qsmx+=1ll*qmx*(mid-l+1);
qtt+=qmx*t[ls].sm;
query(rs,mid+1,r);
}
else{
qsmx+=t[p].smx-t[ls].smx;
qtt+=t[p].tt-t[ls].tt;
query(ls,l,mid);
qmx=t[p].mx;
}
}
void update(int p,int l,int r){
t[p].mx=max(t[ls].mx,t[rs].mx);
t[p].sm=t[ls].sm+t[rs].sm;
qmx=t[ls].mx;
qsmx=t[ls].smx;
qtt=t[ls].tt;
query(rs,mid+1,r);
t[p].smx=qsmx;
t[p].tt=qtt;
}
void modify1(int p,int l,int r,int x,int y,int d){
if(x<=l&&r<=y){
t[p].mx=d;
t[p].sm=1ll*(r-l+1)*d;
t[p].smx=t[p].sm;
t[p].tt=t[p].sm*d;
t[p].tg1=d;
t[p].tg2=0;
return;
}
pushdown(p,l,r);
if(x<=mid)modify1(ls,l,mid,x,y,d);
if(mid<y)modify1(rs,mid+1,r,x,y,d);
update(p,l,r);
}
void modify2(int p,int l,int r,int x,int y,int d){
if(x<=l&&r<=y){
t[p].mx+=d;
t[p].tt+=d*(1ll*d*(r-l+1)+t[p].sm+t[p].smx);
t[p].sm+=1ll*(r-l+1)*d;
t[p].smx+=1ll*(r-l+1)*d;
t[p].tg2+=d;
return;
}
pushdown(p,l,r);
if(x<=mid)modify2(ls,l,mid,x,y,d);
if(mid<y)modify2(rs,mid+1,r,x,y,d);
update(p,l,r);
}
struct seg{
int p,l,r;
}b[100];
int m;
void getseg(int p,int l,int r,int x,int y){
if(x<=l&&r<=y){
b[++m]=(seg){p,l,r};
return;
}
pushdown(p,l,r);
if(x<=mid)getseg(ls,l,mid,x,y);
if(mid<y)getseg(rs,mid+1,r,x,y);
}
int gettt(int p,int l,int r,ll tm){
if(l==r){
query(p,l,r);
if(qtt>tm)return l-1;
return l;
}
pushdown(p,l,r);
int mx=qmx;
ll tt=qtt;
query(ls,l,mid);
if(qtt>tm){
qmx=mx,qtt=tt;
return gettt(ls,l,mid,tm);
}
return gettt(rs,mid+1,r,tm);
}
int getsm(int p,int l,int r,ll tm){
if(l==r){
if(t[p].sm>tm)return l-1;
return l;
}
pushdown(p,l,r);
if(t[ls].sm>tm)return getsm(ls,l,mid,tm);
return getsm(rs,mid+1,r,tm-t[ls].sm);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>q;
for(int i=0;i<n;i++)cin>>a[i];
build(1,0,n-1);
while(q--){
char op[2];
cin>>op;
if(op[0]=='R'){
int l,r,d;
cin>>l>>r>>d;
if(l<=r)modify1(1,0,n-1,l,r,d);
else modify1(1,0,n-1,l,n-1,d),modify1(1,0,n-1,0,r,d);
}
if(op[0]=='P'){
int l,r,d;
cin>>l>>r>>d;
if(l<=r)modify2(1,0,n-1,l,r,d);
else modify2(1,0,n-1,l,n-1,d),modify2(1,0,n-1,0,r,d);
}
if(op[0]=='Q'){
int s;
ll tm;
cin>>s>>tm;
m=0;
getseg(1,0,n-1,s,n-1);
if(s)getseg(1,0,n-1,0,s-1);
bool flag=0;
int mx=0;
ll tt=0;
for(int i=1;i<=m;i++){
qmx=mx,qtt=tt;
query(b[i].p,b[i].l,b[i].r);
if(qtt>tm){
qmx=mx,qtt=tt;
cout<<(gettt(b[i].p,b[i].l,b[i].r,tm)+1)%n<<'\n';
flag=1;
break;
}
mx=qmx,tt=qtt;
}
if(flag)continue;
tm-=qtt;
tm/=t[1].mx;
tm%=t[1].sm;
for(int i=1;i<=m;i++){
if(t[b[i].p].sm>tm){
cout<<(getsm(b[i].p,b[i].l,b[i].r,tm)+1)%n<<'\n';
break;
}
tm-=t[b[i].p].sm;
}
}
}
return 0;
}

View File

@ -1,166 +1,166 @@
#include <bits/stdc++.h>
using namespace std;
#define M 200005
typedef long long LL;
int A[M],n,q;
struct YD{
struct TNode{
int l,r,mark,mx,ad;
LL ans,sum,mx_s;
int len(){
return r-l+1;
}
void Reset(int ty,int v){
if(ty==1){
if(mark!=-1)mark+=v;
else ad+=v;
mx+=v;
ans+=1ll*v*v*len()+sum*v;
ans+=mx_s*v;
sum+=1ll*len()*v;
mx_s+=1ll*len()*v;
}else{
ad=0;
mark=mx=v;
mx_s=sum=1ll*len()*v;
ans=1ll*v*v*len();
}
}
}tree[M<<2];
#define fa tree[p]
#define lson tree[p<<1]
#define rson tree[p<<1|1]
void Down(int p){
if(fa.ad!=0)lson.Reset(1,fa.ad),rson.Reset(1,fa.ad),fa.ad=0;
if(fa.mark!=-1)lson.Reset(2,fa.mark),rson.Reset(2,fa.mark),fa.mark=-1;
}
LL get_mx_s(int p,int mx){
LL ret=0;
while(fa.l^fa.r){
Down(p);
if(lson.mx<=mx)ret+=1LL*mx*lson.len(),p=p<<1|1;
else ret+=fa.mx_s-lson.mx_s,p<<=1;
}
return ret+max(mx,fa.mx);
}
LL get_ans(int p,int mx){
LL ret=0;
while(fa.l^fa.r){
Down(p);
if(lson.mx<=mx)ret+=lson.sum*mx,p=p<<1|1;
else ret+=fa.ans-lson.ans,p<<=1;
}
return ret+1LL*fa.mx*max(fa.mx,mx);
}
void Up(int p){
fa.mx=max(lson.mx,rson.mx);
fa.sum=lson.sum+rson.sum;
fa.ans=lson.ans+get_ans(p<<1|1,lson.mx);
fa.mx_s=lson.mx_s+get_mx_s(p<<1|1,lson.mx);
}
int pos[M];
void build(int l,int r,int p=1){
fa.l=l,fa.r=r;
fa.mark=-1;
fa.ad=0;
if(l==r){
pos[l]=p;
fa.mx=A[l];
fa.ans=1ll*A[l]*A[l];
fa.sum=A[l];
fa.mx_s=A[l];
return;
}
int mid=l+r>>1;
build(l,mid,p<<1);
build(mid+1,r,p<<1|1);
Up(p);
}
void Update(int l,int r,int ty,int v,int p=1){
if(l==fa.l&&r==fa.r)return void(fa.Reset(ty,v));
Down(p);
int mid=fa.l+fa.r>>1;
if(r<=mid)Update(l,r,ty,v,p<<1);
else if(l>mid)Update(l,r,ty,v,p<<1|1);
else Update(l,mid,ty,v,p<<1),Update(mid+1,r,ty,v,p<<1|1);
Up(p);
}
int stk[M],top;
void Pb(int x){
for(int i=pos[x]>>1;i;i>>=1)stk[++top]=i;
while(top)Down(stk[top--]);
}
LL sum,tmp;
int mx;
int Ask_r(int x,LL t){
Pb(x);
int p=pos[x];
if(1LL*fa.mx*max(mx,fa.mx)>=t)return x-1;
int ret=x;
sum=1LL*max(mx,fa.mx)*fa.mx;
mx=max(mx,fa.mx);
while(p!=1){
if(p&1)p>>=1;
else{
p>>=1;
if(sum+(tmp=get_ans(p<<1|1,mx)) < t){
ret=rson.r,mx=max(mx,rson.mx),sum+=tmp;
}
else {
Down(p);
p=p<<1|1;
while(fa.l^fa.r){
Down(p);
if(sum+(tmp=get_ans(p<<1,mx)) < t)ret=lson.r,mx=max(mx,lson.mx),sum+=tmp,p=p<<1|1;
else p<<=1;
}
if(sum+(tmp=1LL*fa.mx*max(fa.mx,mx)) < t)ret=fa.l,mx=max(mx,lson.mx),sum+=tmp;
return ret;
}
}
}
return ret;
}
int Query(int x,LL t){
mx=sum=0;
int r=Ask_r(x,t);
if(r<n-1)return r+1;
else{
t-=sum;
sum=0;
r = Ask_r(0,t);
if(r<n-1)return r+1;
t-=sum;
sum=0;
LL tt = tree[1].sum * mx;
LL k = t/tt-(t%tt==0);
t-=tt*k;
return Ask_r(0,t)+1;
}
}
#undef fa
#undef lson
#undef rson
}Seg;
int main(){
scanf("%d%d",&n,&q);
for(int i=0;i<n;i++)scanf("%d",&A[i]);
Seg.build(0,n-1);
for(int i=1;i<=q;i++){
LL l,r,v;
char op[3];
scanf("%s%lld%lld",op,&l,&r);
if(op[0]=='Q'){
printf("%d\n",Seg.Query(l,r+1));
}else {
scanf("%lld",&v);
if(l<=r)Seg.Update(l,r,op[0]=='P'?1:2,v);
else {
Seg.Update(l,n-1,op[0]=='P'?1:2,v);
Seg.Update(0, r ,op[0]=='P'?1:2,v);
}
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define M 200005
typedef long long LL;
int A[M],n,q;
struct YD{
struct TNode{
int l,r,mark,mx,ad;
LL ans,sum,mx_s;
int len(){
return r-l+1;
}
void Reset(int ty,int v){
if(ty==1){
if(mark!=-1)mark+=v;
else ad+=v;
mx+=v;
ans+=1ll*v*v*len()+sum*v;
ans+=mx_s*v;
sum+=1ll*len()*v;
mx_s+=1ll*len()*v;
}else{
ad=0;
mark=mx=v;
mx_s=sum=1ll*len()*v;
ans=1ll*v*v*len();
}
}
}tree[M<<2];
#define fa tree[p]
#define lson tree[p<<1]
#define rson tree[p<<1|1]
void Down(int p){
if(fa.ad!=0)lson.Reset(1,fa.ad),rson.Reset(1,fa.ad),fa.ad=0;
if(fa.mark!=-1)lson.Reset(2,fa.mark),rson.Reset(2,fa.mark),fa.mark=-1;
}
LL get_mx_s(int p,int mx){
LL ret=0;
while(fa.l^fa.r){
Down(p);
if(lson.mx<=mx)ret+=1LL*mx*lson.len(),p=p<<1|1;
else ret+=fa.mx_s-lson.mx_s,p<<=1;
}
return ret+max(mx,fa.mx);
}
LL get_ans(int p,int mx){
LL ret=0;
while(fa.l^fa.r){
Down(p);
if(lson.mx<=mx)ret+=lson.sum*mx,p=p<<1|1;
else ret+=fa.ans-lson.ans,p<<=1;
}
return ret+1LL*fa.mx*max(fa.mx,mx);
}
void Up(int p){
fa.mx=max(lson.mx,rson.mx);
fa.sum=lson.sum+rson.sum;
fa.ans=lson.ans+get_ans(p<<1|1,lson.mx);
fa.mx_s=lson.mx_s+get_mx_s(p<<1|1,lson.mx);
}
int pos[M];
void build(int l,int r,int p=1){
fa.l=l,fa.r=r;
fa.mark=-1;
fa.ad=0;
if(l==r){
pos[l]=p;
fa.mx=A[l];
fa.ans=1ll*A[l]*A[l];
fa.sum=A[l];
fa.mx_s=A[l];
return;
}
int mid=l+r>>1;
build(l,mid,p<<1);
build(mid+1,r,p<<1|1);
Up(p);
}
void Update(int l,int r,int ty,int v,int p=1){
if(l==fa.l&&r==fa.r)return void(fa.Reset(ty,v));
Down(p);
int mid=fa.l+fa.r>>1;
if(r<=mid)Update(l,r,ty,v,p<<1);
else if(l>mid)Update(l,r,ty,v,p<<1|1);
else Update(l,mid,ty,v,p<<1),Update(mid+1,r,ty,v,p<<1|1);
Up(p);
}
int stk[M],top;
void Pb(int x){
for(int i=pos[x]>>1;i;i>>=1)stk[++top]=i;
while(top)Down(stk[top--]);
}
LL sum,tmp;
int mx;
int Ask_r(int x,LL t){
Pb(x);
int p=pos[x];
if(1LL*fa.mx*max(mx,fa.mx)>=t)return x-1;
int ret=x;
sum=1LL*max(mx,fa.mx)*fa.mx;
mx=max(mx,fa.mx);
while(p!=1){
if(p&1)p>>=1;
else{
p>>=1;
if(sum+(tmp=get_ans(p<<1|1,mx)) < t){
ret=rson.r,mx=max(mx,rson.mx),sum+=tmp;
}
else {
Down(p);
p=p<<1|1;
while(fa.l^fa.r){
Down(p);
if(sum+(tmp=get_ans(p<<1,mx)) < t)ret=lson.r,mx=max(mx,lson.mx),sum+=tmp,p=p<<1|1;
else p<<=1;
}
if(sum+(tmp=1LL*fa.mx*max(fa.mx,mx)) < t)ret=fa.l,mx=max(mx,lson.mx),sum+=tmp;
return ret;
}
}
}
return ret;
}
int Query(int x,LL t){
mx=sum=0;
int r=Ask_r(x,t);
if(r<n-1)return r+1;
else{
t-=sum;
sum=0;
r = Ask_r(0,t);
if(r<n-1)return r+1;
t-=sum;
sum=0;
LL tt = tree[1].sum * mx;
LL k = t/tt-(t%tt==0);
t-=tt*k;
return Ask_r(0,t)+1;
}
}
#undef fa
#undef lson
#undef rson
}Seg;
int main(){
scanf("%d%d",&n,&q);
for(int i=0;i<n;i++)scanf("%d",&A[i]);
Seg.build(0,n-1);
for(int i=1;i<=q;i++){
LL l,r,v;
char op[3];
scanf("%s%lld%lld",op,&l,&r);
if(op[0]=='Q'){
printf("%d\n",Seg.Query(l,r+1));
}else {
scanf("%lld",&v);
if(l<=r)Seg.Update(l,r,op[0]=='P'?1:2,v);
else {
Seg.Update(l,n-1,op[0]=='P'?1:2,v);
Seg.Update(0, r ,op[0]=='P'?1:2,v);
}
}
}
return 0;
}

View File

@ -1,36 +1,36 @@
#include <iostream>
#include <ranges>
using std::cin,std::cout;
constexpr const auto range = std::ranges::views::iota;
struct Point{
int x,y;
};
const int MAX_N = 1e4+5;
int n;
Point dir;
Point arr[MAX_N][2];
int main(){
std::iostream::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
cin>>n;
for(const int i:range(0,n)){
for(const int j:range(0,2)){
cin>>arr[i][j].x>>arr[i][j].y;
}
}
cin>>dir.x>>dir.y;
for(int i=n-1;i>=0;i--){
if(arr[i][0].x<=dir.x && dir.x <= arr[i][0].x+arr[i][1].x
&& arr[i][0].y<=dir.y && dir.y <= arr[i][0].y+arr[i][1].y){
std::cout<<i+1<<"\n";
return 0;
}
}
std::cout<<-1<<"\n";
#include <iostream>
#include <ranges>
using std::cin,std::cout;
constexpr const auto range = std::ranges::views::iota;
struct Point{
int x,y;
};
const int MAX_N = 1e4+5;
int n;
Point dir;
Point arr[MAX_N][2];
int main(){
std::iostream::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
cin>>n;
for(const int i:range(0,n)){
for(const int j:range(0,2)){
cin>>arr[i][j].x>>arr[i][j].y;
}
}
cin>>dir.x>>dir.y;
for(int i=n-1;i>=0;i--){
if(arr[i][0].x<=dir.x && dir.x <= arr[i][0].x+arr[i][1].x
&& arr[i][0].y<=dir.y && dir.y <= arr[i][0].y+arr[i][1].y){
std::cout<<i+1<<"\n";
return 0;
}
}
std::cout<<-1<<"\n";
}

View File

@ -1,32 +1,32 @@
#include <algorithm>
#include <iostream>
using std::cin, std::cout, std::iostream, std::max, std::for_each_n;
constexpr size_t MAX_N {(size_t)5e5+5};
int arr[MAX_N], len[MAX_N], ans1, ans2{1}, n, last_max;
int main(){
iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);
while(cin>>arr[n++]);
for(int i=0;i<n;i++){
for(int j=i-1;j>=0;j--){ //j<i
if(arr[j]>=arr[i] && len[i]<len[j]+1){
len[i] = len[j] + 1;
}
}
}
for_each_n(len,n,[](decltype(*len) e){
ans1 = std::max(ans1,e);
});
for(int i=1;i<n;i++){
if(arr[i]>arr[i-1]){
ans2++;
}
}
cout<<ans1<<'\n'<<ans2<<'\n';
}
#include <algorithm>
#include <iostream>
using std::cin, std::cout, std::iostream, std::max, std::for_each_n;
constexpr size_t MAX_N {(size_t)5e5+5};
int arr[MAX_N], len[MAX_N], ans1, ans2{1}, n, last_max;
int main(){
iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);
while(cin>>arr[n++]);
for(int i=0;i<n;i++){
for(int j=i-1;j>=0;j--){ //j<i
if(arr[j]>=arr[i] && len[i]<len[j]+1){
len[i] = len[j] + 1;
}
}
}
for_each_n(len,n,[](decltype(*len) e){
ans1 = std::max(ans1,e);
});
for(int i=1;i<n;i++){
if(arr[i]>arr[i-1]){
ans2++;
}
}
cout<<ans1<<'\n'<<ans2<<'\n';
}
// 40 PT

View File

@ -1,32 +1,32 @@
#include <ios>
#include<iostream>
int n;
int a[(int)1e4+5];
int main(){
std::ios::sync_with_stdio(false),std::cin.tie(nullptr),std::cout.tie(nullptr);
std::cin>>n;
int sum=0;
for(int i=1;i<=n;i++){
std::cin>>a[i];
sum+=a[i];
}
int avg = sum/n;
int ans = 0;
for(int i=1;i<n;i++){
ans++;
if(a[i]>avg){
a[i+1]+=a[i]-avg;
}else if(a[i]<avg){
a[i+1]-=avg-a[i];
}else{
ans--;
}
}
std::cout<<ans<<"\n";
#include <ios>
#include<iostream>
int n;
int a[(int)1e4+5];
int main(){
std::ios::sync_with_stdio(false),std::cin.tie(nullptr),std::cout.tie(nullptr);
std::cin>>n;
int sum=0;
for(int i=1;i<=n;i++){
std::cin>>a[i];
sum+=a[i];
}
int avg = sum/n;
int ans = 0;
for(int i=1;i<n;i++){
ans++;
if(a[i]>avg){
a[i+1]+=a[i]-avg;
}else if(a[i]<avg){
a[i+1]-=avg-a[i];
}else{
ans--;
}
}
std::cout<<ans<<"\n";
}

View File

@ -1,70 +1,70 @@
#include <ios>
#include<iostream>
#include <queue>
#include <vector>
const int MAX_N = (int)1e2+5;
int n;
int a[MAX_N];
int sum;
int avg;
int ans;
struct Gift{
int next,num;
};
std::vector<Gift> to[MAX_N];
int inDegree[MAX_N];
std::queue<int> q;
int main(){
std::ios::sync_with_stdio(false),std::cin.tie(nullptr),std::cout.tie(nullptr);
std::cin>>n;
for(int i=1;i<=n;i++){
std::cin>>a[i];
sum+=a[i];
}
avg = sum/n;
ans = 0;
for(int i=1;i<n;i++){
ans++;
if(a[i]>avg){
int num = a[i]-avg;
to[i].push_back({.next=i+1,.num=num});
inDegree[i+1]++;
a[i+1]+=num;
}else if(a[i]<avg){
int num = avg-a[i];
to[i+1].push_back({.next=i,.num=num});
inDegree[i]++;
a[i+1]-=num;
}else{
ans--;
}
}
for(int i=1;i<=n;i++){
if(inDegree[i]==0){
q.push(i);
}
}
while(q.empty()==false){
int top = q.front();
q.pop();
for(Gift i:to[top]){
inDegree[i.next]--;
std::cout<<top<<" give "<<i.next<<" "<<i.num<<" points\n";
if(inDegree[i.next]==0){
q.push(i.next);
}
}
}
// std::cout<<ans<<"\n";
#include <ios>
#include<iostream>
#include <queue>
#include <vector>
const int MAX_N = (int)1e2+5;
int n;
int a[MAX_N];
int sum;
int avg;
int ans;
struct Gift{
int next,num;
};
std::vector<Gift> to[MAX_N];
int inDegree[MAX_N];
std::queue<int> q;
int main(){
std::ios::sync_with_stdio(false),std::cin.tie(nullptr),std::cout.tie(nullptr);
std::cin>>n;
for(int i=1;i<=n;i++){
std::cin>>a[i];
sum+=a[i];
}
avg = sum/n;
ans = 0;
for(int i=1;i<n;i++){
ans++;
if(a[i]>avg){
int num = a[i]-avg;
to[i].push_back({.next=i+1,.num=num});
inDegree[i+1]++;
a[i+1]+=num;
}else if(a[i]<avg){
int num = avg-a[i];
to[i+1].push_back({.next=i,.num=num});
inDegree[i]++;
a[i+1]-=num;
}else{
ans--;
}
}
for(int i=1;i<=n;i++){
if(inDegree[i]==0){
q.push(i);
}
}
while(q.empty()==false){
int top = q.front();
q.pop();
for(Gift i:to[top]){
inDegree[i.next]--;
std::cout<<top<<" give "<<i.next<<" "<<i.num<<" points\n";
if(inDegree[i.next]==0){
q.push(i.next);
}
}
}
// std::cout<<ans<<"\n";
}

View File

@ -1,35 +1,35 @@
#include <iostream>
#include <algorithm>
using std::cin,std::cout,std::max,std::iostream;
constexpr size_t MAX_N {100+5};
int n, arr[MAX_N], go_up[MAX_N], go_down[MAX_N], ans;
int main(){
iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
go_up[i]=1,go_down[i]=1;
}
for(int i=0;i<n;i++){//j < i
for(int j=i-1;j>=0;j--){
if(arr[j]<arr[i] && go_up[i]<go_up[j]+1){
go_up[i] = go_up[j]+1;
}
}
}
for(int i=n-1;i>=0;i--){//i < j
for(int j=i+1;j<n;j++){
if(arr[j]<arr[i] && go_down[i]<go_down[j]+1){
go_down[i] = go_down[j] + 1;
}
}
}
for(int i=0;i<n;i++){
ans = max(ans,go_down[i]+go_up[i]-1);
}
cout<<n-ans<<'\n';
#include <iostream>
#include <algorithm>
using std::cin,std::cout,std::max,std::iostream;
constexpr size_t MAX_N {100+5};
int n, arr[MAX_N], go_up[MAX_N], go_down[MAX_N], ans;
int main(){
iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
go_up[i]=1,go_down[i]=1;
}
for(int i=0;i<n;i++){//j < i
for(int j=i-1;j>=0;j--){
if(arr[j]<arr[i] && go_up[i]<go_up[j]+1){
go_up[i] = go_up[j]+1;
}
}
}
for(int i=n-1;i>=0;i--){//i < j
for(int j=i+1;j<n;j++){
if(arr[j]<arr[i] && go_down[i]<go_down[j]+1){
go_down[i] = go_down[j] + 1;
}
}
}
for(int i=0;i<n;i++){
ans = max(ans,go_down[i]+go_up[i]-1);
}
cout<<n-ans<<'\n';
}

View File

@ -1,31 +1,31 @@
#include<iostream>
using std::cin,std::cout,std::iostream;
const int MAX_COLOR = 50+5;
int price,color,n,k,p,last_coffee_shop,last_hotel[MAX_COLOR],left_hotel_num[MAX_COLOR],cnt_hotel_num[MAX_COLOR],ans;
int main(){
iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>k>>p;
for(int i=1;i<=n;i++){
cin>>color>>price;
if(price<=p){
last_coffee_shop = i;
}
if(last_hotel[color] <= last_coffee_shop){
left_hotel_num[color] = cnt_hotel_num[color];
}
last_hotel[color]=i;
ans+=left_hotel_num[color];
cnt_hotel_num[color]++;
}
cout<<ans<<"\n";
#include<iostream>
using std::cin,std::cout,std::iostream;
const int MAX_COLOR = 50+5;
int price,color,n,k,p,last_coffee_shop,last_hotel[MAX_COLOR],left_hotel_num[MAX_COLOR],cnt_hotel_num[MAX_COLOR],ans;
int main(){
iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>k>>p;
for(int i=1;i<=n;i++){
cin>>color>>price;
if(price<=p){
last_coffee_shop = i;
}
if(last_hotel[color] <= last_coffee_shop){
left_hotel_num[color] = cnt_hotel_num[color];
}
last_hotel[color]=i;
ans+=left_hotel_num[color];
cnt_hotel_num[color]++;
}
cout<<ans<<"\n";
}

View File

@ -1,65 +1,72 @@
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using ll = long long;
using std::endl;
static auto &is = std::cin;
static auto &os = std::cout;
static const ll max_n = 1e4+5;
static ll n, m, a, b;
static std::vector<ll> next[max_n];
static bool vis[max_n];
static std::queue<ll> q;
static int colors[max_n];
static ll color_sum[3];
void set_color(const ll n,const int color)noexcept{
colors[n]=color;
color_sum[color]++;
}
void flush_exit()noexcept{
os<<endl;
_Exit(0);
}
void bfs(){
for(ll i{1};i<=n;i++){
if(vis[i])continue;
q.push(i);
set_color(i, 1);
while(!q.empty()){
const auto front = q.front();
q.pop();
for(const auto i:next[front]){
if(vis[i]){
if(colors[i]==colors[front]){
os<<"Impossible";
flush_exit();
}
continue;
}
set_color(i,(colors[front]&1)+1);
vis[i]=true;
q.push(i);
}
}
}
}
int main(){
is>>n>>m;
for(ll i{0};i<m;i++){
is>>a>>b;
next[a].push_back(b);
next[b].push_back(a);
}
bfs();
os<<std::min(color_sum[1],color_sum[2]);
flush_exit();
//#define NDEBUG
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define NV(v)#v<<" : "<<(v)
#ifdef NDEBUG
#define DEBUG(code)
#else
#define DEBUG(code){code}
#endif
using ll = long long;
using std::endl;
static auto &is = std::cin;
static auto &os = std::cout;
static const ll max_n = 1e4+5;
static ll n, m, a, b;
static std::vector<ll> next[max_n];
static bool vis[max_n];
static std::queue<ll> q;
static int colors[max_n];
static ll color_sum[3];
void set_color(const ll n,const int color)noexcept{
colors[n]=color;
color_sum[color]++;
}
void flush_exit()noexcept{
os<<endl;
_Exit(0);
}
void bfs(){
for(ll i{1};i<=n;i++){
if(vis[i])continue;
q.push(i);
set_color(i, 1);
while(!q.empty()){
const auto front = q.front();
q.pop();
for(const auto i:next[front]){
if(vis[i]){
if(colors[i]==colors[front]){
os<<"Impossible";
flush_exit();
}
continue;
}
set_color(i,(colors[front]&1)+1);
vis[i]=true;
q.push(i);
}
}
}
}
int main(){
is>>n>>m;
for(ll i{0};i<m;i++){
is>>a>>b;
next[a].push_back(b);
next[b].push_back(a);
}
bfs();
os<<std::min(color_sum[1],color_sum[2]);
flush_exit();
}

View File

@ -1,103 +1,103 @@
#define NDEBUG
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#define NV(v)#v<<" : "<<(v)
#ifdef NDEBUG
#define DEBUG(code)
#else
#define DEBUG(code){code}
#endif
using ull = unsigned long long;
const size_t max_n = 150+5;
struct Point{
ull x,y;
};
ull n;
Point points[max_n];
std::string s;
double mtx_len[max_n][max_n];
double max_len[max_n];
const double double_max = std::numeric_limits<double>::max(), double_min = std::numeric_limits<double>::min();
double min_ans {double_max}, default_ans{0};
double len(const Point &p1, const Point &p2){
return std::sqrt(
std::pow((double)p1.x-(double)p2.x, (double)2)+
std::pow((double)p1.y-(double)p2.y,(double)2)
);
}
int main(){
// std::cout<<INF<<'\n';
std::cin>>n;
for(ull i = 1;i<=n;i++){
std::cin>>points[i].x>>points[i].y;
}
for(ull i=1;i<=n;i++){
std::cin>>s;
for(ull j=1;j<=n;j++){
if(i==j){
continue;
}
if(s[j-1]=='1'){
mtx_len[i][j] = len(points[i],points[j]);
}else{
mtx_len[i][j] = double_max;
}
}
}
for(ull k=1;k<=n;k++){
for(ull i=1;i<=n;i++){
for(ull j=1;j<=n;j++){
double new_len;
if(mtx_len[i][k]!=double_max && mtx_len[k][j]!=double_max){
new_len = mtx_len[i][k]+mtx_len[k][j];
}else{
continue;
}
if(new_len<mtx_len[i][j]){
mtx_len[i][j] = new_len;
}
}
}
}
for(ull i=1;i<=n;i++){
max_len[i]=double_max;
for(ull j=1;j<=n;j++){
if(mtx_len[i][j]==double_max)continue;
max_len[i] = std::max(mtx_len[i][j],(max_len[i]==double_max?double_min:max_len[i]));
default_ans = std::max(default_ans,max_len[i]);
}
}
DEBUG(
std::cout<<NV(min_ans)<<"\n---start\n";
)
for(ull i=1;i<=n;i++){
for(ull j=i+1;j<=n;j++){
if(mtx_len[i][j]==double_max){
DEBUG(
std::cout<<NV(i)<<'\n'<<NV(j)<<'\n'<<NV(max_len[i])<<'\n'<<NV(max_len[j])<<'\n'
<<NV(len(points[i], points[j]))<<'\n'<<NV(max_len[i]+ len(points[i], points[j]) + max_len[j])<<'\n';
)
min_ans = std::min(max_len[i]+ len(points[i], points[j]) +max_len[j],min_ans);
DEBUG(
std::cout<<NV(min_ans)<<'\n';
std::cout<<"---\n";
)
}
}
}
std::cout<<std::fixed<<std::setprecision(6)<<(min_ans==double_max?default_ans:std::max(default_ans, min_ans))<<'\n';
#define NDEBUG
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#define NV(v)#v<<" : "<<(v)
#ifdef NDEBUG
#define DEBUG(code)
#else
#define DEBUG(code){code}
#endif
using ull = unsigned long long;
const size_t max_n = 150+5;
struct Point{
ull x,y;
};
ull n;
Point points[max_n];
std::string s;
double mtx_len[max_n][max_n];
double max_len[max_n];
const double double_max = std::numeric_limits<double>::max(), double_min = std::numeric_limits<double>::min();
double min_ans {double_max}, default_ans{0};
double len(const Point &p1, const Point &p2){
return std::sqrt(
std::pow((double)p1.x-(double)p2.x, (double)2)+
std::pow((double)p1.y-(double)p2.y,(double)2)
);
}
int main(){
// std::cout<<INF<<'\n';
std::cin>>n;
for(ull i = 1;i<=n;i++){
std::cin>>points[i].x>>points[i].y;
}
for(ull i=1;i<=n;i++){
std::cin>>s;
for(ull j=1;j<=n;j++){
if(i==j){
continue;
}
if(s[j-1]=='1'){
mtx_len[i][j] = len(points[i],points[j]);
}else{
mtx_len[i][j] = double_max;
}
}
}
for(ull k=1;k<=n;k++){
for(ull i=1;i<=n;i++){
for(ull j=1;j<=n;j++){
double new_len;
if(mtx_len[i][k]!=double_max && mtx_len[k][j]!=double_max){
new_len = mtx_len[i][k]+mtx_len[k][j];
}else{
continue;
}
if(new_len<mtx_len[i][j]){
mtx_len[i][j] = new_len;
}
}
}
}
for(ull i=1;i<=n;i++){
max_len[i]=double_max;
for(ull j=1;j<=n;j++){
if(mtx_len[i][j]==double_max)continue;
max_len[i] = std::max(mtx_len[i][j],(max_len[i]==double_max?double_min:max_len[i]));
default_ans = std::max(default_ans,max_len[i]);
}
}
DEBUG(
std::cout<<NV(min_ans)<<"\n---start\n";
)
for(ull i=1;i<=n;i++){
for(ull j=i+1;j<=n;j++){
if(mtx_len[i][j]==double_max){
DEBUG(
std::cout<<NV(i)<<'\n'<<NV(j)<<'\n'<<NV(max_len[i])<<'\n'<<NV(max_len[j])<<'\n'
<<NV(len(points[i], points[j]))<<'\n'<<NV(max_len[i]+ len(points[i], points[j]) + max_len[j])<<'\n';
)
min_ans = std::min(max_len[i]+ len(points[i], points[j]) +max_len[j],min_ans);
DEBUG(
std::cout<<NV(min_ans)<<'\n';
std::cout<<"---\n";
)
}
}
}
std::cout<<std::fixed<<std::setprecision(6)<<(min_ans==double_max?default_ans:std::max(default_ans, min_ans))<<'\n';
}

View File

@ -1,28 +1,28 @@
#include <iostream>
#define NV(v)#v<<" : "<<(v)
using ull = unsigned long long;
static ull n, m, k, x;
static auto &is = std::cin;
static auto &os = std::cout;
template<class T>
T fast_pow(T b,T e, const T &k){
T ret{1};
b%=k;
while(e>0){
if(e&1){
ret = (ret * b)%k;
}
e>>=1;
b = (b*b) %k;
}
return ret;
}
int main(){
// os<<NV(fast_pow(3,3, 1000))<<'\n';
is>>n>>m>>k>>x;
os<<((x+m*((ull)(fast_pow(10ull,k,n))%n))%n)<<'\n';
#include <iostream>
#define NV(v)#v<<" : "<<(v)
using ull = unsigned long long;
static ull n, m, k, x;
static auto &is = std::cin;
static auto &os = std::cout;
template<class T>
T fast_pow(T b,T e, const T &k){
T ret{1};
b%=k;
while(e>0){
if(e&1){
ret = (ret * b)%k;
}
e>>=1;
b = (b*b) %k;
}
return ret;
}
int main(){
// os<<NV(fast_pow(3,3, 1000))<<'\n';
is>>n>>m>>k>>x;
os<<((x+m*((ull)(fast_pow(10ull,k,n))%n))%n)<<'\n';
}

View File

@ -1,44 +1,44 @@
#include <iostream>
#include <type_traits>
using ull = unsigned long long;
template<class T>
class ReadNumber{
char c;
T w,n;
public:
ReadNumber& operator>>(T &t){
c=(char)0,w=1,n=0;
while(!isdigit(c)){
if constexpr (std::is_signed_v<T>){
if(c=='-')w=-1;
}
c=getchar();
}
while(isdigit(c)){
n=n*10+(c-'0');
c=getchar();
}
t = n*w;
return *this;
}
};
static ReadNumber<ull> readull;
// static auto &is = std::cin;
static auto &is = readull;
static auto &os = std::cout;
static ull a, b, ans, n;
int main(){
is>>n;
for(size_t i{0};i<n;i++){
is>>b;
if(a<b){
ans+=b-a;
}
a=b;
}
os<<ans<<'\n';
#include <iostream>
#include <type_traits>
using ull = unsigned long long;
template<class T>
class ReadNumber{
char c;
T w,n;
public:
ReadNumber& operator>>(T &t){
c=(char)0,w=1,n=0;
while(!isdigit(c)){
if constexpr (std::is_signed_v<T>){
if(c=='-')w=-1;
}
c=getchar();
}
while(isdigit(c)){
n=n*10+(c-'0');
c=getchar();
}
t = n*w;
return *this;
}
};
static ReadNumber<ull> readull;
// static auto &is = std::cin;
static auto &is = readull;
static auto &os = std::cout;
static ull a, b, ans, n;
int main(){
is>>n;
for(size_t i{0};i<n;i++){
is>>b;
if(a<b){
ans+=b-a;
}
a=b;
}
os<<ans<<'\n';
}

View File

@ -1,51 +1,51 @@
#include <iostream>
#include <istream>
#include <ranges>
using std::cin,std::cout;
static constexpr const auto range = std::ranges::views::iota;
const int MAX_N = 39+5;
int n;
int map[MAX_N][MAX_N];
int x,y,now{1};
int main(){
std::iostream::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
std::cin>>n;
x=1,y=n/2+1;
map[x][y]=now++;
/*
1. $(K-1)$ $K$ $(K-1)$
2. $(K-1)$ $K$ $(K-1)$
3. $(K-1)$ $K$ $(K-1)$
4. $(K-1)$ $(K-1)$ $K$ $(K-1)$ $K$ $(K-1)$
*/
while(now<=n*n){
if(x==1 && y!=n){
x=n,y++;
}else if(y==n && x!=1){
y=1,x--;
}else if(x==1 && y==n){
x++;
}else if(x!=1 && y!=n){
if(map[x-1][y+1]==0){
x--;
y++;
}else{
x++;
}
}
map[x][y]=now++;
}
for(int i:range(1,n+1)){
for(int j:range(1,n+1)){
std::cout<<map[i][j]<<" ";
}
std::cout<<"\n";
}
#include <iostream>
#include <istream>
#include <ranges>
using std::cin,std::cout;
static constexpr const auto range = std::ranges::views::iota;
const int MAX_N = 39+5;
int n;
int map[MAX_N][MAX_N];
int x,y,now{1};
int main(){
std::iostream::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
std::cin>>n;
x=1,y=n/2+1;
map[x][y]=now++;
/*
1. $(K-1)$ $K$ $(K-1)$
2. $(K-1)$ $K$ $(K-1)$
3. $(K-1)$ $K$ $(K-1)$
4. $(K-1)$ $(K-1)$ $K$ $(K-1)$ $K$ $(K-1)$
*/
while(now<=n*n){
if(x==1 && y!=n){
x=n,y++;
}else if(y==n && x!=1){
y=1,x--;
}else if(x==1 && y==n){
x++;
}else if(x!=1 && y!=n){
if(map[x-1][y+1]==0){
x--;
y++;
}else{
x++;
}
}
map[x][y]=now++;
}
for(int i:range(1,n+1)){
for(int j:range(1,n+1)){
std::cout<<map[i][j]<<" ";
}
std::cout<<"\n";
}
}

View File

@ -1,54 +1,54 @@
#include <algorithm>
#include <iostream>
#include <istream>
#include <queue>
#include <limits>
using std::cin,std::cout;
const int MAX_N {(int)2e5+5};
int n;
int next[MAX_N];
int in_degree[MAX_N];
bool vis[MAX_N];
std::queue<int> q;
int ans {std::numeric_limits<int>::max()};
int main(){
std::iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0);
std::cin>>n;
for(int i=1;i<=n;i++){
cin>>next[i];
in_degree[next[i]]++;
}
const auto push_vis = [](int n){
q.push(n);
vis[n]=true;
};
for(int i=1;i<=n;i++){
if(in_degree[i]<=0){
push_vis(i);
}
}
while(q.empty()==false){
int front = q.front();
q.pop();
if(--in_degree[next[front]]<=0){
push_vis(next[front]);
}
}
for(int i=1;i<=n;i++){
if(vis[i])continue;
int loop_size {0};
int start {i};
int now {start};
do{
vis[now]=true;
now=next[now];
loop_size++;
}while(now!=start);
ans=std::min(ans,loop_size);
}
std::cout<<ans<<"\n";
#include <algorithm>
#include <iostream>
#include <istream>
#include <queue>
#include <limits>
using std::cin,std::cout;
const int MAX_N {(int)2e5+5};
int n;
int next[MAX_N];
int in_degree[MAX_N];
bool vis[MAX_N];
std::queue<int> q;
int ans {std::numeric_limits<int>::max()};
int main(){
std::iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0);
std::cin>>n;
for(int i=1;i<=n;i++){
cin>>next[i];
in_degree[next[i]]++;
}
const auto push_vis = [](int n){
q.push(n);
vis[n]=true;
};
for(int i=1;i<=n;i++){
if(in_degree[i]<=0){
push_vis(i);
}
}
while(q.empty()==false){
int front = q.front();
q.pop();
if(--in_degree[next[front]]<=0){
push_vis(next[front]);
}
}
for(int i=1;i<=n;i++){
if(vis[i])continue;
int loop_size {0};
int start {i};
int now {start};
do{
vis[now]=true;
now=next[now];
loop_size++;
}while(now!=start);
ans=std::min(ans,loop_size);
}
std::cout<<ans<<"\n";
}

View File

@ -1,61 +1,61 @@
#include <iostream>
#include <istream>
#include <ranges>
#include <queue>
#include <limits>
#include <algorithm>
using std::cin,std::cout;
constexpr const auto range = std::ranges::views::iota;
const int MAX_N = 2e5+5;
int n;
int next[MAX_N];
int in_degree[MAX_N];
std::queue<int> q;
bool vis[MAX_N];
int ans {std::numeric_limits<int>::max()};
int main(){
std::iostream::sync_with_stdio(false),cin.tie(nullptr),cout.tie(0);
cin>>n;
for(const int i:range(1,n+1)){
cin>>next[i];
in_degree[next[i]]++;
}
const auto push_vis = [](const int n){
q.push(n);
vis[n]=true;
};
for(const int i:range(1,n+1)){
if(in_degree[i]==0){
push_vis(i);
}
}
while(q.empty()==false){
int front = q.front();
q.pop();
in_degree[next[front]]--;
if(in_degree[next[front]]==0){
push_vis(next[front]);
}
}
for(int i:range(1,n+1)){
if(vis[i])continue;
const int start {i};
int now {start};
int ring_size {0};
do{
vis[now]=true;
ring_size++;
now = next[now];
}while(now!=start);
ans = std::min(ans,ring_size);
}
cout<<ans<<"\n";
#include <iostream>
#include <istream>
#include <ranges>
#include <queue>
#include <limits>
#include <algorithm>
using std::cin,std::cout;
constexpr const auto range = std::ranges::views::iota;
const int MAX_N = 2e5+5;
int n;
int next[MAX_N];
int in_degree[MAX_N];
std::queue<int> q;
bool vis[MAX_N];
int ans {std::numeric_limits<int>::max()};
int main(){
std::iostream::sync_with_stdio(false),cin.tie(nullptr),cout.tie(0);
cin>>n;
for(const int i:range(1,n+1)){
cin>>next[i];
in_degree[next[i]]++;
}
const auto push_vis = [](const int n){
q.push(n);
vis[n]=true;
};
for(const int i:range(1,n+1)){
if(in_degree[i]==0){
push_vis(i);
}
}
while(q.empty()==false){
int front = q.front();
q.pop();
in_degree[next[front]]--;
if(in_degree[next[front]]==0){
push_vis(next[front]);
}
}
for(int i:range(1,n+1)){
if(vis[i])continue;
const int start {i};
int now {start};
int ring_size {0};
do{
vis[now]=true;
ring_size++;
now = next[now];
}while(now!=start);
ans = std::min(ans,ring_size);
}
cout<<ans<<"\n";
}

View File

@ -1,59 +1,59 @@
#include <iostream>
#include <algorithm>
using std::cin,std::cout,std::sort,std::max;
constexpr int MAX_N {(int)2e5+5};
struct City{
int a,b;
bool operator<(const City &that)const noexcept{
return this->a<that.a;
}
} city[MAX_N];
int n, len[MAX_N],ans;
template<class T>
class ReadNumber{
char c;
T w,n;
public:
ReadNumber& operator>>(T &num)noexcept{
c=(char)0,w=1,n=0;
while(!isdigit(c)){
// if constexpr(!std::is_same_v<ull, T>){
// if(c=='-')w=-1;
// }
c = getchar();
}
while(isdigit(c)){
n = n*10 + (c-'0');
c = getchar();
}
num = w*n;
return *this;
}
};
ReadNumber<int> readint;
#define cin readint
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>city[i].a>>city[i].b;
len[i]=1;
}
sort(city,city+n);
for(int i=0;i<n;i++){
for(int j=i-1;j>=0;j--){
if(city[j].b<city[i].b && len[i]<len[j]+1){
len[i]=len[j]+1;
}
}
}
for(int i=0;i<n;i++){
// cout<<"i:"<<i<<" "<<"len:"<<len[i]<<'\n';
ans = max(ans,len[i]);
}
cout<<ans<<'\n';
#include <iostream>
#include <algorithm>
using std::cin,std::cout,std::sort,std::max;
constexpr int MAX_N {(int)2e5+5};
struct City{
int a,b;
bool operator<(const City &that)const noexcept{
return this->a<that.a;
}
} city[MAX_N];
int n, len[MAX_N],ans;
template<class T>
class ReadNumber{
char c;
T w,n;
public:
ReadNumber& operator>>(T &num)noexcept{
c=(char)0,w=1,n=0;
while(!isdigit(c)){
// if constexpr(!std::is_same_v<ull, T>){
// if(c=='-')w=-1;
// }
c = getchar();
}
while(isdigit(c)){
n = n*10 + (c-'0');
c = getchar();
}
num = w*n;
return *this;
}
};
ReadNumber<int> readint;
#define cin readint
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>city[i].a>>city[i].b;
len[i]=1;
}
sort(city,city+n);
for(int i=0;i<n;i++){
for(int j=i-1;j>=0;j--){
if(city[j].b<city[i].b && len[i]<len[j]+1){
len[i]=len[j]+1;
}
}
}
for(int i=0;i<n;i++){
// cout<<"i:"<<i<<" "<<"len:"<<len[i]<<'\n';
ans = max(ans,len[i]);
}
cout<<ans<<'\n';
}

View File

@ -1,47 +1,47 @@
#include <iostream>
#include <algorithm>
#include <map>
using ull = unsigned long long;
#define NV(v)#v<<" : "<<(v)
static ull t, k, n, m, ans;
static std::map<ull,ull> fact_map;
static std::map<std::pair<ull,ull>,ull> C_map;
static ull fact(const ull n)noexcept{
if(n==0)return 1;
const auto it = fact_map.find(n);
if(it != fact_map.end())return (*it).second;
ull ret {1};
for(ull i{2};i<=n;i++){
ret*=i;
}
fact_map.insert({n,ret});
return ret;
}
static ull C(const ull n, const ull m)noexcept{
const auto it = C_map.find({n,m});
if(it!=C_map.end())return (*it).second;
const ull ret = (fact(n))/(fact(m)*fact(n-m));
C_map.insert({{n,m},ret});
return ret;
}
int main(){
// std::cout<<NV(fact(0))<<'\n'<<NV(fact(3))<<'\n';
std::iostream::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
std::cin>>t>>k;
for(ull i {0};i<t;i++){
std::cin>>n>>m;
ans = 0;
for(ull i {0};i<=n;i++){
for(ull j{0};j<=std::min(i,m);j++){
if(C(i,j)%k==0)ans++;
}
}
std::cout<<ans<<'\n';
}
#include <iostream>
#include <algorithm>
#include <map>
using ull = unsigned long long;
#define NV(v)#v<<" : "<<(v)
static ull t, k, n, m, ans;
static std::map<ull,ull> fact_map;
static std::map<std::pair<ull,ull>,ull> C_map;
static ull fact(const ull n)noexcept{
if(n==0)return 1;
const auto it = fact_map.find(n);
if(it != fact_map.end())return (*it).second;
ull ret {1};
for(ull i{2};i<=n;i++){
ret*=i;
}
fact_map.insert({n,ret});
return ret;
}
static ull C(const ull n, const ull m)noexcept{
const auto it = C_map.find({n,m});
if(it!=C_map.end())return (*it).second;
const ull ret = (fact(n))/(fact(m)*fact(n-m));
C_map.insert({{n,m},ret});
return ret;
}
int main(){
// std::cout<<NV(fact(0))<<'\n'<<NV(fact(3))<<'\n';
std::iostream::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
std::cin>>t>>k;
for(ull i {0};i<t;i++){
std::cin>>n>>m;
ans = 0;
for(ull i {0};i<=n;i++){
for(ull j{0};j<=std::min(i,m);j++){
if(C(i,j)%k==0)ans++;
}
}
std::cout<<ans<<'\n';
}
}

View File

@ -1,136 +1,136 @@
// #define NDEBUG //切换release和debug版本
#include <cctype>
#include <iostream>
#include <algorithm>
#include <type_traits>
#include <sstream>
using ull = unsigned long long;
template<class T,size_t size>
struct Array{
constexpr Array(){};
constexpr Array(const std::initializer_list<T> list){
std::copy(list.begin(),list.end(),arr);
}
#ifdef NDEBUG
#define NDB_NOEXCEPT noexcept
#define NDB_CONSTEXPR constexpr
#else
#define NDB_NOEXCEPT
#define NDB_CONSTEXPR
#endif
NDB_CONSTEXPR T& operator[](const size_t n)NDB_NOEXCEPT{
// static_assert(noexcept(Array::operator[](0)), "isn't noexcept");
#ifndef NDEBUG
if(n>=size){
std::ostringstream err_oss;
err_oss<<"\n[array_size]: "<<size<<"\n[Your index]: "<<n<<'\n';
throw std::runtime_error(err_oss.str());
}
#endif
return arr[n];
}
struct Iterator{
constexpr Iterator(const size_t n,T *const p)noexcept:now{n},p{p}{}
bool operator!=(const Iterator &that)const noexcept{
return this->now!=that.now;
}
NDB_CONSTEXPR T& operator*()const NDB_NOEXCEPT{
#ifndef NDEBUG
if(now>=size){
std::ostringstream err_oss;
err_oss<<"[array_size]: "<<size<<" [Your index]: "<<now<<'\n';
throw std::runtime_error(err_oss.str());
}
#endif
return p[now];
}
constexpr Iterator& operator++()noexcept{
now++;
return *this;
}
constexpr Iterator& operator--()noexcept{
now--;
return *this;
}
constexpr Iterator operator--(int)noexcept{
auto old = *this;
now--;
return old;
}
private:
size_t now;
T *const p;
};
constexpr Iterator begin()noexcept{
return Iterator(0,arr);
}
constexpr Iterator end()noexcept{
return Iterator(size,arr);
}
private:
T arr[size];
};
static const size_t max_n {(size_t)2e3+5};
ull k, t, n, m;
Array<Array<ull,max_n>,max_n> c,prefix;
static void init(){
c[0][0] = c[1][0] = c[1][1] = 1;
for(ull i {2};i<max_n;i++){
c[i][0]=1;
for(ull j{1};j<=i;j++){
c[i][j] = (c[i-1][j-1] + c[i-1][j])%k;
}
}
for(ull i = 2;i<max_n;i++){ //注意这里越界了这是个bug示例
for(ull j{1};j<=i;j++){
prefix[i][j] = prefix[i-1][j]+prefix[i][j-1]-prefix[i-1][j-1] + (c[i][j]==0?1:0);
}
prefix[i][i+1] = prefix[i][i];
}
}
#define NV(v)#v<<" : "<<(v)
template<class T>
struct ReadNumber{
ReadNumber& operator>>(T &num){
c=0,w=1,n=0;
while(!isdigit(c)){
if constexpr (!std::is_unsigned_v<T>){
if(c=='-')w=-1;
}
c=getchar();
}
while(isdigit(c)){
n=n*10+(c-'0');
c=getchar();
}
num = w*n;
return *this;
}
private:
char c;
T w,n;
};
ReadNumber<ull> readull;
int main(){
readull>>t>>k;
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
init();
for(ull i {0};i<t;i++){
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
readull>>n>>m;
// std::cout<<"test\n";
m = std::min(m,n);
std::cout<<(prefix[n][m])<<'\n';
}
// #define NDEBUG //切换release和debug版本
#include <cctype>
#include <iostream>
#include <algorithm>
#include <type_traits>
#include <sstream>
using ull = unsigned long long;
template<class T,size_t size>
struct Array{
constexpr Array(){};
constexpr Array(const std::initializer_list<T> list){
std::copy(list.begin(),list.end(),arr);
}
#ifdef NDEBUG
#define NDB_NOEXCEPT noexcept
#define NDB_CONSTEXPR constexpr
#else
#define NDB_NOEXCEPT
#define NDB_CONSTEXPR
#endif
NDB_CONSTEXPR T& operator[](const size_t n)NDB_NOEXCEPT{
// static_assert(noexcept(Array::operator[](0)), "isn't noexcept");
#ifndef NDEBUG
if(n>=size){
std::ostringstream err_oss;
err_oss<<"\n[array_size]: "<<size<<"\n[Your index]: "<<n<<'\n';
throw std::runtime_error(err_oss.str());
}
#endif
return arr[n];
}
struct Iterator{
constexpr Iterator(const size_t n,T *const p)noexcept:now{n},p{p}{}
bool operator!=(const Iterator &that)const noexcept{
return this->now!=that.now;
}
NDB_CONSTEXPR T& operator*()const NDB_NOEXCEPT{
#ifndef NDEBUG
if(now>=size){
std::ostringstream err_oss;
err_oss<<"[array_size]: "<<size<<" [Your index]: "<<now<<'\n';
throw std::runtime_error(err_oss.str());
}
#endif
return p[now];
}
constexpr Iterator& operator++()noexcept{
now++;
return *this;
}
constexpr Iterator& operator--()noexcept{
now--;
return *this;
}
constexpr Iterator operator--(int)noexcept{
auto old = *this;
now--;
return old;
}
private:
size_t now;
T *const p;
};
constexpr Iterator begin()noexcept{
return Iterator(0,arr);
}
constexpr Iterator end()noexcept{
return Iterator(size,arr);
}
private:
T arr[size];
};
static const size_t max_n {(size_t)2e3+5};
ull k, t, n, m;
Array<Array<ull,max_n>,max_n> c,prefix;
static void init(){
c[0][0] = c[1][0] = c[1][1] = 1;
for(ull i {2};i<max_n;i++){
c[i][0]=1;
for(ull j{1};j<=i;j++){
c[i][j] = (c[i-1][j-1] + c[i-1][j])%k;
}
}
for(ull i = 2;i<max_n;i++){ //注意这里越界了这是个bug示例
for(ull j{1};j<=i;j++){
prefix[i][j] = prefix[i-1][j]+prefix[i][j-1]-prefix[i-1][j-1] + (c[i][j]==0?1:0);
}
prefix[i][i+1] = prefix[i][i];
}
}
#define NV(v)#v<<" : "<<(v)
template<class T>
struct ReadNumber{
ReadNumber& operator>>(T &num){
c=0,w=1,n=0;
while(!isdigit(c)){
if constexpr (!std::is_unsigned_v<T>){
if(c=='-')w=-1;
}
c=getchar();
}
while(isdigit(c)){
n=n*10+(c-'0');
c=getchar();
}
num = w*n;
return *this;
}
private:
char c;
T w,n;
};
ReadNumber<ull> readull;
int main(){
readull>>t>>k;
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
init();
for(ull i {0};i<t;i++){
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
readull>>n>>m;
// std::cout<<"test\n";
m = std::min(m,n);
std::cout<<(prefix[n][m])<<'\n';
}
}

View File

@ -1,88 +1,88 @@
#define NDEBUG
#include <cctype>
#include <iostream>
#include <algorithm>
#include <type_traits>
#define NV(v)#v<<" : "<<(v)
#ifdef NDEBUG
#define DEBUG(code)
#else
#define DEBUG(code){code}
#endif
using ull = unsigned long long;
static const size_t max_n {(size_t)2e3+5};
// static const size_t max_n {(size_t)10};
static ull k, c[max_n][max_n], prefix[max_n][max_n], t, n, m;
static void init(){
c[0][0] = c[1][0] = c[1][1] = 1;
for(ull i {2};i<max_n;i++){
c[i][0]=1;
for(ull j{1};j<=i;j++){
c[i][j] = (c[i-1][j-1] + c[i-1][j])%k;
}
}
DEBUG(
for(ull i{0};i<max_n;i++){
for(ull j{0};j<=i;j++){
std::cout<<c[i][j]<<' ';
}
std::cout<<'\n';
}
std::cout<<"===========\n";
)
for(ull i = 2;i<max_n-1;i++){ //注意这里是max_n-1
for(ull j{1};j<=i;j++){
prefix[i][j] = prefix[i-1][j]+prefix[i][j-1]-prefix[i-1][j-1] + (c[i][j]==0?1:0);
}
prefix[i][i+1] = prefix[i][i];
}
DEBUG(
for(ull i{0};i<max_n;i++){
for(ull j{0};j<=i;j++){
std::cout<<prefix[i][j]<<' ';
}
std::cout<<'\n';
}
)
}
template<class T>
struct ReadNumber{
ReadNumber& operator>>(T &num){
c=0,w=1,n=0;
while(!isdigit(c)){
if constexpr (!std::is_unsigned_v<T>){
if(c=='-')w=-1;
}
c=getchar();
}
while(isdigit(c)){
n=n*10+(c-'0');
c=getchar();
}
num = w*n;
return *this;
}
private:
char c;
T w,n;
};
ReadNumber<ull> readull;
int main(){
readull>>t>>k;
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
init();
for(ull i {0};i<t;i++){
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
readull>>n>>m;
// std::cout<<"test\n";
m = std::min(m,n);
std::cout<<(prefix[n][m])<<'\n';
}
#define NDEBUG
#include <cctype>
#include <iostream>
#include <algorithm>
#include <type_traits>
#define NV(v)#v<<" : "<<(v)
#ifdef NDEBUG
#define DEBUG(code)
#else
#define DEBUG(code){code}
#endif
using ull = unsigned long long;
static const size_t max_n {(size_t)2e3+5};
// static const size_t max_n {(size_t)10};
static ull k, c[max_n][max_n], prefix[max_n][max_n], t, n, m;
static void init(){
c[0][0] = c[1][0] = c[1][1] = 1;
for(ull i {2};i<max_n;i++){
c[i][0]=1;
for(ull j{1};j<=i;j++){
c[i][j] = (c[i-1][j-1] + c[i-1][j])%k;
}
}
DEBUG(
for(ull i{0};i<max_n;i++){
for(ull j{0};j<=i;j++){
std::cout<<c[i][j]<<' ';
}
std::cout<<'\n';
}
std::cout<<"===========\n";
)
for(ull i = 2;i<max_n-1;i++){ //注意这里是max_n-1
for(ull j{1};j<=i;j++){
prefix[i][j] = prefix[i-1][j]+prefix[i][j-1]-prefix[i-1][j-1] + (c[i][j]==0?1:0);
}
prefix[i][i+1] = prefix[i][i];
}
DEBUG(
for(ull i{0};i<max_n;i++){
for(ull j{0};j<=i;j++){
std::cout<<prefix[i][j]<<' ';
}
std::cout<<'\n';
}
)
}
template<class T>
struct ReadNumber{
ReadNumber& operator>>(T &num){
c=0,w=1,n=0;
while(!isdigit(c)){
if constexpr (!std::is_unsigned_v<T>){
if(c=='-')w=-1;
}
c=getchar();
}
while(isdigit(c)){
n=n*10+(c-'0');
c=getchar();
}
num = w*n;
return *this;
}
private:
char c;
T w,n;
};
ReadNumber<ull> readull;
int main(){
readull>>t>>k;
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
init();
for(ull i {0};i<t;i++){
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
readull>>n>>m;
// std::cout<<"test\n";
m = std::min(m,n);
std::cout<<(prefix[n][m])<<'\n';
}
}

View File

@ -1,71 +1,71 @@
#include <iostream>
#include <ranges>
#include <queue>
#include <stdio.h>
using std::cout,std::iostream;
static const constexpr auto range {std::ranges::views::iota};
static const constexpr int MOD {80112002}, MAX_TYPES {(int)5e3+5} /*, MAX_REL_SHIPS {(int)5e5+5}*/;
static int types, rel_ships, a, b, in_degree[MAX_TYPES], out_degree[MAX_TYPES], link_nums[MAX_TYPES], ans;
static std::queue<int> q;
static std::vector<int> next[MAX_TYPES];
class ReadInt{
char c;
int w,n;
public:
ReadInt &operator>>(int &num){
c=0,w=1,n=0;
while(!isdigit(c)){
if(c=='-')w=-1;
c = (char)getchar();
}
while(isdigit(c)){
n=n*10+(c-'0');
c = (char)getchar();
}
num = n*w;
return *this;
}
};
static ReadInt readint;
#define cin readint
int main(){
cin>>types>>rel_ships;
for([[maybe_unused]] const int _:range(1,rel_ships+1)){
cin>>a>>b;
next[a].push_back(b);
in_degree[b]++;
out_degree[a]++;
}
for(const int i:range(1, types+1)){
if(in_degree[i]==0){
q.push(i);
link_nums[i] = 1;
}
}
while(!q.empty()){
auto front {q.front()};
q.pop();
for(auto i:next[front]){
link_nums[i] = (link_nums[i] + link_nums[front])%MOD;
if(--in_degree[i]==0){
q.push(i);
}
}
}
for(auto i:range(1,types+1)){
if(out_degree[i]==0){
ans = (ans + link_nums[i]) % MOD;
}
}
cout<<ans<<"\n";
#include <iostream>
#include <ranges>
#include <queue>
#include <stdio.h>
using std::cout,std::iostream;
static const constexpr auto range {std::ranges::views::iota};
static const constexpr int MOD {80112002}, MAX_TYPES {(int)5e3+5} /*, MAX_REL_SHIPS {(int)5e5+5}*/;
static int types, rel_ships, a, b, in_degree[MAX_TYPES], out_degree[MAX_TYPES], link_nums[MAX_TYPES], ans;
static std::queue<int> q;
static std::vector<int> next[MAX_TYPES];
class ReadInt{
char c;
int w,n;
public:
ReadInt &operator>>(int &num){
c=0,w=1,n=0;
while(!isdigit(c)){
if(c=='-')w=-1;
c = (char)getchar();
}
while(isdigit(c)){
n=n*10+(c-'0');
c = (char)getchar();
}
num = n*w;
return *this;
}
};
static ReadInt readint;
#define cin readint
int main(){
cin>>types>>rel_ships;
for([[maybe_unused]] const int _:range(1,rel_ships+1)){
cin>>a>>b;
next[a].push_back(b);
in_degree[b]++;
out_degree[a]++;
}
for(const int i:range(1, types+1)){
if(in_degree[i]==0){
q.push(i);
link_nums[i] = 1;
}
}
while(!q.empty()){
auto front {q.front()};
q.pop();
for(auto i:next[front]){
link_nums[i] = (link_nums[i] + link_nums[front])%MOD;
if(--in_degree[i]==0){
q.push(i);
}
}
}
for(auto i:range(1,types+1)){
if(out_degree[i]==0){
ans = (ans + link_nums[i]) % MOD;
}
}
cout<<ans<<"\n";
}

View File

@ -1,5 +1,5 @@
#include<iostream>
int main(){
#include<iostream>
int main(){
}

View File

@ -1,65 +1,65 @@
#include <iostream>
#include <bitset>
#include <type_traits>
using ull = unsigned long long;
using std::cout,std::iostream,std::bitset;
template<class T>
class ReadNumber{
char c;
T w,n;
public:
ReadNumber& operator>>(T &num)noexcept{
c=(char)0,w=1,n=0;
while(!isdigit(c)){
if constexpr(!std::is_same_v<ull, T>){
if(c=='-')w=-1;
}
c = getchar();
}
while(isdigit(c)){
n = n*10 + (c-'0');
c = getchar();
}
num = w*n;
return *this;
}
};
ull n, m, c, k, num, input, p, ans {1}, _;
bitset<64+5> bt;
ReadNumber<ull> readull;
#define cin readull
template<class T>
constexpr T safe_left_shift(const T t,const size_t n)noexcept{
constexpr auto sizeof_t = sizeof(t)*8;
return (n>=sizeof_t?0:t<<n);
}
int main(){
cin>>n>>m>>c>>k;
if(n==0 && m==0 && k==64){ //特判
cout<<"18446744073709551616\n";
return 0;
}
for(ull i=0;i<n;i++){
cin>>input;
num |= input; //所有编号占用的'1'的位置,把他并在一起
}
for(ull i=0;i<m;i++){
cin>>p>>_;
if(!((num>>p)&1) && !bt[p]){ //已有的n个编号里面没有出现过的规则并且还未标记,bt用来去重
k--;
bt[p]=true;
}
}
// for(int i=0;i<k;i++)ans*=2; //此时ans=所有(未排除n个已用规则),可以用的二进制位的组合
ans = safe_left_shift(1ull, k); // 避开未定义行为
cout<<ans-n<<'\n';//注意这里要去重,基本排列组合原理
#include <iostream>
#include <bitset>
#include <type_traits>
using ull = unsigned long long;
using std::cout,std::iostream,std::bitset;
template<class T>
class ReadNumber{
char c;
T w,n;
public:
ReadNumber& operator>>(T &num)noexcept{
c=(char)0,w=1,n=0;
while(!isdigit(c)){
if constexpr(!std::is_same_v<ull, T>){
if(c=='-')w=-1;
}
c = getchar();
}
while(isdigit(c)){
n = n*10 + (c-'0');
c = getchar();
}
num = w*n;
return *this;
}
};
ull n, m, c, k, num, input, p, ans {1}, _;
bitset<64+5> bt;
ReadNumber<ull> readull;
#define cin readull
template<class T>
constexpr T safe_left_shift(const T t,const size_t n)noexcept{
constexpr auto sizeof_t = sizeof(t)*8;
return (n>=sizeof_t?0:t<<n);
}
int main(){
cin>>n>>m>>c>>k;
if(n==0 && m==0 && k==64){ //特判
cout<<"18446744073709551616\n";
return 0;
}
for(ull i=0;i<n;i++){
cin>>input;
num |= input; //所有编号占用的'1'的位置,把他并在一起
}
for(ull i=0;i<m;i++){
cin>>p>>_;
if(!((num>>p)&1) && !bt[p]){ //已有的n个编号里面没有出现过的规则并且还未标记,bt用来去重
k--;
bt[p]=true;
}
}
// for(int i=0;i<k;i++)ans*=2; //此时ans=所有(未排除n个已用规则),可以用的二进制位的组合
ans = safe_left_shift(1ull, k); // 避开未定义行为
cout<<ans-n<<'\n';//注意这里要去重,基本排列组合原理
}

View File

@ -1,44 +1,44 @@
#include <iostream>
#include <exception>
#include <algorithm>
using ull = unsigned long long;
auto &is = std::cin;
auto &os = std::cout;
ull n, a, b, depth;
/*
cal(a,b)
1)a==b return 0;
2)a>b && a is odd return cal(a+1,b)+1;
3)a>b && a is even return cal(a/2,b)+1;
4)a>b/2 && a<b return b-a;
5)a<b/2 && b is odd return cal(a,b/2)+1;
6)a<b/2 && b is even return cal(a,b-1)+1;
*/
ull cal(const ull a,const ull b)noexcept{
if(a==b){
return 0;
}else if(a>b){
if(a&1)return cal(a+1,b)+1;
else return cal(a/2,b)+1;
}else if(a>b/2){
const auto ans = b-a;
if(b&1)return std::min(ans,cal(a,b-1)+1);
else return std::min(ans,cal(a,b/2)+1);
}else if(a<=b/2){
if(b&1)return cal(a,b-1)+1;
else return cal(a,b/2)+1;
}
throw std::runtime_error("cannot calculate");
}
int main(){
is>>n;
for(ull i {0};i<n;i++){
is>>a>>b;
os<<cal(a,b)<<'\n';
}
#include <iostream>
#include <exception>
#include <algorithm>
using ull = unsigned long long;
auto &is = std::cin;
auto &os = std::cout;
ull n, a, b, depth;
/*
cal(a,b)
1)a==b return 0;
2)a>b && a is odd return cal(a+1,b)+1;
3)a>b && a is even return cal(a/2,b)+1;
4)a>b/2 && a<b return b-a;
5)a<b/2 && b is odd return cal(a,b/2)+1;
6)a<b/2 && b is even return cal(a,b-1)+1;
*/
ull cal(const ull a,const ull b)noexcept{
if(a==b){
return 0;
}else if(a>b){
if(a&1)return cal(a+1,b)+1;
else return cal(a/2,b)+1;
}else if(a>b/2){
const auto ans = b-a;
if(b&1)return std::min(ans,cal(a,b-1)+1);
else return std::min(ans,cal(a,b/2)+1);
}else if(a<=b/2){
if(b&1)return cal(a,b-1)+1;
else return cal(a,b/2)+1;
}
throw std::runtime_error("cannot calculate");
}
int main(){
is>>n;
for(ull i {0};i<n;i++){
is>>a>>b;
os<<cal(a,b)<<'\n';
}
}

View File

@ -1,25 +1,25 @@
#include <iostream>
#include <ranges>
using std::cin, std::cout, std::string;
using ull = unsigned long long;
constexpr auto range = std::ranges::views::iota;
constexpr size_t MAX_N{(size_t)3e5 + 5}, MOD{998244353};
string s;
ull stk[MAX_N], left_num[MAX_N], dp[MAX_N], ans;
size_t stk_size;
int main() {
cin >> s;
for (const size_t i : range((size_t)0, s.size())) {
if (s[i] == '(') {
stk[stk_size++] = i + 1;
} else if (stk_size > 0) {
left_num[i] = stk[--stk_size];
dp[i] = (dp[left_num[i] - 2] + left_num[i]) % MOD;
ans = (ans + dp[i] * (s.size() - i)) % MOD;
}
}
cout << ans << '\n';
#include <iostream>
#include <ranges>
using std::cin, std::cout, std::string;
using ull = unsigned long long;
constexpr auto range = std::ranges::views::iota;
constexpr size_t MAX_N{(size_t)3e5 + 5}, MOD{998244353};
string s;
ull stk[MAX_N], left_num[MAX_N], dp[MAX_N], ans;
size_t stk_size;
int main() {
cin >> s;
for (const size_t i : range((size_t)0, s.size())) {
if (s[i] == '(') {
stk[stk_size++] = i + 1;
} else if (stk_size > 0) {
left_num[i] = stk[--stk_size];
dp[i] = (dp[left_num[i] - 2] + left_num[i]) % MOD;
ans = (ans + dp[i] * (s.size() - i)) % MOD;
}
}
cout << ans << '\n';
}

View File

@ -1,77 +1,77 @@
# 括号序列问题1
## 题目描述
给一个长度为 $n$ 的括号串 $s$,其中连续的一段 $s[l...r]$ 称为 $s$ 的子串。
合法串的定义如下:
1. `()` 是合法括号串。
2. 如果 `A` 是合法括号串,则 `(A)` 是合法括号串。
3. 如果 `A``B` 是合法括号串,则 `AB` 是合法括号串。
对于串 $t$,其所有子串中合法串的数量记为 $f(t)$
求 $s$ 串所有子串的 $f$ 值之和,即 $\sum_{l\le r}f(s[l...r])$,模 998244353。
## 输入格式
一个字符串 $s$
## 输出格式
输出一个整数代表答案
## 样例 #1
### 样例输入 #1
```
())
```
### 样例输出 #1
```
2
```
## 样例 #2
### 样例输入 #2
```
(()()
```
### 样例输出 #2
```
12
```
## 样例 #3
### 样例输入 #3
```
)(()())()
```
### 样例输出 #3
```
66
```
## 提示
设 $n$ 为输入串长度:
子任务120分$1\le n\le 100$
子任务220分$1\le n\le 700$
子任务320分$1\le n\le 5000$
# 括号序列问题1
## 题目描述
给一个长度为 $n$ 的括号串 $s$,其中连续的一段 $s[l...r]$ 称为 $s$ 的子串。
合法串的定义如下:
1. `()` 是合法括号串。
2. 如果 `A` 是合法括号串,则 `(A)` 是合法括号串。
3. 如果 `A``B` 是合法括号串,则 `AB` 是合法括号串。
对于串 $t$,其所有子串中合法串的数量记为 $f(t)$
求 $s$ 串所有子串的 $f$ 值之和,即 $\sum_{l\le r}f(s[l...r])$,模 998244353。
## 输入格式
一个字符串 $s$
## 输出格式
输出一个整数代表答案
## 样例 #1
### 样例输入 #1
```
())
```
### 样例输出 #1
```
2
```
## 样例 #2
### 样例输入 #2
```
(()()
```
### 样例输出 #2
```
12
```
## 样例 #3
### 样例输入 #3
```
)(()())()
```
### 样例输出 #3
```
66
```
## 提示
设 $n$ 为输入串长度:
子任务120分$1\le n\le 100$
子任务220分$1\le n\le 700$
子任务320分$1\le n\le 5000$
子任务440分$1\le n\le 300000$

View File

@ -1,45 +1,45 @@
#include <iostream>
#include <string>
#include <stack>
#include <array>
using std::cin, std::cout, std::string, std::stack, std::array;
constexpr size_t MOD {998244353}, MAX_N {(size_t)3e5+5};
string s;
stack<size_t> st;
unsigned int prefix[MAX_N], ans, sum, left_num;
constexpr size_t char_size {1<<(sizeof(char)*8)};
constexpr array<int,char_size> install_array(){
array<int,char_size> ret{};
ret[40]=1;
return ret;
}
constexpr array<int,char_size> map = install_array();
int main(){
cin>>s;
for(size_t i {0};i<s.size();i++){
for(size_t j {i+1};j<=s.size();j++){
for(size_t k{i};k<j;k++){
for(size_t l{k+1};l<=j;l++){
left_num = 0;
for(size_t m{k};m<l;m++){
left_num+=map[s[m]];
if(s[m]==')'){
if(left_num<=0){
goto failed;
}
left_num--;
}
}
if(left_num==0){
ans=(ans+1)%MOD;
}
failed:;
}
}
}
}
cout<<ans<<'\n';
#include <iostream>
#include <string>
#include <stack>
#include <array>
using std::cin, std::cout, std::string, std::stack, std::array;
constexpr size_t MOD {998244353}, MAX_N {(size_t)3e5+5};
string s;
stack<size_t> st;
unsigned int prefix[MAX_N], ans, sum, left_num;
constexpr size_t char_size {1<<(sizeof(char)*8)};
constexpr array<int,char_size> install_array(){
array<int,char_size> ret{};
ret[40]=1;
return ret;
}
constexpr array<int,char_size> map = install_array();
int main(){
cin>>s;
for(size_t i {0};i<s.size();i++){
for(size_t j {i+1};j<=s.size();j++){
for(size_t k{i};k<j;k++){
for(size_t l{k+1};l<=j;l++){
left_num = 0;
for(size_t m{k};m<l;m++){
left_num+=map[s[m]];
if(s[m]==')'){
if(left_num<=0){
goto failed;
}
left_num--;
}
}
if(left_num==0){
ans=(ans+1)%MOD;
}
failed:;
}
}
}
}
cout<<ans<<'\n';
}

View File

@ -1,104 +1,104 @@
#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <stdexcept>
#include <string>
#include <sstream>
using std::cin, std::cout, std::string;
typedef unsigned long long ull;
template<class T,size_t size>
struct Array{
constexpr Array(){};
constexpr Array(const std::initializer_list<T> list){
std::copy(list.begin(),list.end(),arr);
}
#ifdef NDEBUG
#define NDB_NOEXCEPT noexcept
#define NDB_CONSTEXPR constexpr
#else
#define NDB_NOEXCEPT
#define NDB_CONSTEXPR
#endif
NDB_CONSTEXPR T& operator[](const size_t n)NDB_NOEXCEPT{
#ifndef NDEBUG
if(n>=size){
std::ostringstream err_oss;
err_oss<<"\n[array_size]: "<<size<<"\n[Your index]: "<<n<<'\n';
throw std::runtime_error(err_oss.str());
}
#endif
return arr[n];
}
struct Iterator{
constexpr Iterator(const size_t n,T *const p)noexcept:now{n},p{p}{}
bool operator!=(const Iterator &that)const noexcept{
return this->now!=that.now;
}
NDB_CONSTEXPR T& operator*()const NDB_NOEXCEPT{
#ifndef NDEBUG
if(now>=size){
std::ostringstream err_oss;
err_oss<<"[array_size]: "<<size<<" [Your index]: "<<now<<'\n';
throw std::runtime_error(err_oss.str());
}
#endif
return p[now];
}
constexpr Iterator& operator++()noexcept{
now++;
return *this;
}
constexpr Iterator& operator--()noexcept{
now--;
return *this;
}
constexpr Iterator operator--(int)noexcept{
auto old = *this;
now--;
return old;
}
private:
size_t now;
T *const p;
};
constexpr Iterator begin()noexcept{
return Iterator(0,arr);
}
constexpr Iterator end()noexcept{
return Iterator(size,arr);
}
private:
T arr[size];
};
template<class T,class ...Args>
constexpr static Array<T,sizeof...(Args)> make_array(Args&&...args){
Array<T,sizeof...(Args)> arr;
size_t index {0};
((arr[index++]=args),...);
return arr;
}
static const size_t MOD {998244353}, MAX_N {300000+5};
static string s;
static size_t unused_left_num, ans;
static Array<size_t,MAX_N> left_dp, last_left;
static Array<ull,MAX_N> stk;
int main(){
cin>>s;
for(size_t i {1};i<=s.size();i++){
if(s[i-1]=='('){
stk[unused_left_num++]=i;
}else if(unused_left_num>0){
last_left[i] = stk[--unused_left_num];
left_dp[i] = (left_dp[last_left[i]-1] + last_left[i]) % MOD;
ans = (ans + left_dp[i] * (s.size() - i+1)) % MOD ;
}
}
cout<<ans<<'\n';
#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <stdexcept>
#include <string>
#include <sstream>
using std::cin, std::cout, std::string;
typedef unsigned long long ull;
template<class T,size_t size>
struct Array{
constexpr Array(){};
constexpr Array(const std::initializer_list<T> list){
std::copy(list.begin(),list.end(),arr);
}
#ifdef NDEBUG
#define NDB_NOEXCEPT noexcept
#define NDB_CONSTEXPR constexpr
#else
#define NDB_NOEXCEPT
#define NDB_CONSTEXPR
#endif
NDB_CONSTEXPR T& operator[](const size_t n)NDB_NOEXCEPT{
#ifndef NDEBUG
if(n>=size){
std::ostringstream err_oss;
err_oss<<"\n[array_size]: "<<size<<"\n[Your index]: "<<n<<'\n';
throw std::runtime_error(err_oss.str());
}
#endif
return arr[n];
}
struct Iterator{
constexpr Iterator(const size_t n,T *const p)noexcept:now{n},p{p}{}
bool operator!=(const Iterator &that)const noexcept{
return this->now!=that.now;
}
NDB_CONSTEXPR T& operator*()const NDB_NOEXCEPT{
#ifndef NDEBUG
if(now>=size){
std::ostringstream err_oss;
err_oss<<"[array_size]: "<<size<<" [Your index]: "<<now<<'\n';
throw std::runtime_error(err_oss.str());
}
#endif
return p[now];
}
constexpr Iterator& operator++()noexcept{
now++;
return *this;
}
constexpr Iterator& operator--()noexcept{
now--;
return *this;
}
constexpr Iterator operator--(int)noexcept{
auto old = *this;
now--;
return old;
}
private:
size_t now;
T *const p;
};
constexpr Iterator begin()noexcept{
return Iterator(0,arr);
}
constexpr Iterator end()noexcept{
return Iterator(size,arr);
}
private:
T arr[size];
};
template<class T,class ...Args>
constexpr static Array<T,sizeof...(Args)> make_array(Args&&...args){
Array<T,sizeof...(Args)> arr;
size_t index {0};
((arr[index++]=args),...);
return arr;
}
static const size_t MOD {998244353}, MAX_N {300000+5};
static string s;
static size_t unused_left_num, ans;
static Array<size_t,MAX_N> left_dp, last_left;
static Array<ull,MAX_N> stk;
int main(){
cin>>s;
for(size_t i {1};i<=s.size();i++){
if(s[i-1]=='('){
stk[unused_left_num++]=i;
}else if(unused_left_num>0){
last_left[i] = stk[--unused_left_num];
left_dp[i] = (left_dp[last_left[i]-1] + last_left[i]) % MOD;
ans = (ans + left_dp[i] * (s.size() - i+1)) % MOD ;
}
}
cout<<ans<<'\n';
}

View File

@ -1,24 +1,24 @@
#include <iostream>
#include <string>
using std::cin, std::cout, std::string;
using ull = unsigned long long;
constexpr size_t MAX_N {(size_t)3e5+5}, MOD {998244353};
string s;
ull left_ok[MAX_N], stk[MAX_N], stk_size, left_index[MAX_N], ans;
int main(){
cin>>s;
for(size_t i {1};i<=s.size();i++){
if(s[i-1]=='('){
stk[stk_size++] = i;
}else if(stk_size>0){
left_index[i] = stk[--stk_size];
left_ok[i] = (left_ok[left_index[i]-1] + left_index[i]) % MOD;
ans = ( ans + left_ok[i] * (s.size() - i + 1)) % MOD;
}
}
cout<<ans<<'\n';
#include <iostream>
#include <string>
using std::cin, std::cout, std::string;
using ull = unsigned long long;
constexpr size_t MAX_N {(size_t)3e5+5}, MOD {998244353};
string s;
ull left_ok[MAX_N], stk[MAX_N], stk_size, left_index[MAX_N], ans;
int main(){
cin>>s;
for(size_t i {1};i<=s.size();i++){
if(s[i-1]=='('){
stk[stk_size++] = i;
}else if(stk_size>0){
left_index[i] = stk[--stk_size];
left_ok[i] = (left_ok[left_index[i]-1] + left_index[i]) % MOD;
ans = ( ans + left_ok[i] * (s.size() - i + 1)) % MOD;
}
}
cout<<ans<<'\n';
}

View File

@ -1,59 +1,59 @@
#include <iostream>
#include <string>
#include <ranges>
#include <vector>
using std::cin, std::cout, std::string, std::vector, std::iostream;
constexpr auto range = std::ranges::views::iota;
size_t n;
string s;
int a_num, b_num;
char max_char, min_char;
struct Ope{
const size_t start,end;
const char c;
};
vector<Ope> v;
void print()noexcept{
cout<<v.size()<<'\n';
for(auto &i:v){
cout<<i.start+1<<' '<<i.end+1<<' '<<i.c<<'\n';
}
}
int main(){
iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin>>n;
cin>>s;
for(const int i:range((size_t)0,n)){
if(s[i]=='A') {
a_num++;
}else if(s[i]=='B'){
b_num++;
}
}
if(a_num>=b_num){
max_char = 'A';
min_char = 'B';
}else{
max_char = 'B';
min_char = 'A';
}
v.push_back({0,(size_t)n-1,max_char});
for(size_t i=0;i<n;i++){
if(s[i]==min_char){
size_t end {i};
for(size_t j=i+1;j<n;j++){
if(s[j]!=min_char)break;
end=j;
}
v.push_back({i,end,min_char});
i=end+1;
}
}
print();
#include <iostream>
#include <string>
#include <ranges>
#include <vector>
using std::cin, std::cout, std::string, std::vector, std::iostream;
constexpr auto range = std::ranges::views::iota;
size_t n;
string s;
int a_num, b_num;
char max_char, min_char;
struct Ope{
const size_t start,end;
const char c;
};
vector<Ope> v;
void print()noexcept{
cout<<v.size()<<'\n';
for(auto &i:v){
cout<<i.start+1<<' '<<i.end+1<<' '<<i.c<<'\n';
}
}
int main(){
iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin>>n;
cin>>s;
for(const int i:range((size_t)0,n)){
if(s[i]=='A') {
a_num++;
}else if(s[i]=='B'){
b_num++;
}
}
if(a_num>=b_num){
max_char = 'A';
min_char = 'B';
}else{
max_char = 'B';
min_char = 'A';
}
v.push_back({0,(size_t)n-1,max_char});
for(size_t i=0;i<n;i++){
if(s[i]==min_char){
size_t end {i};
for(size_t j=i+1;j<n;j++){
if(s[j]!=min_char)break;
end=j;
}
v.push_back({i,end,min_char});
i=end+1;
}
}
print();
}

View File

@ -1,2 +1,2 @@
1
1
1 4 A

View File

@ -1,2 +1,2 @@
4
4
AAAA

View File

@ -1,5 +1,5 @@
4
1 6 B
3 5 C
4 4 A
4
1 6 B
3 5 C
4 4 A
1 1 A

View File

@ -1,2 +1,2 @@
6
6
ABCACB

View File

@ -1,27 +1,27 @@
26
1 50 B
49 49 A
47 47 A
45 45 A
43 43 A
41 41 A
39 39 A
37 37 A
35 35 A
33 33 A
31 31 A
29 29 A
27 27 A
25 25 A
23 23 A
21 21 A
19 19 A
17 17 A
15 15 A
13 13 A
11 11 A
9 9 A
7 7 A
5 5 A
3 3 A
26
1 50 B
49 49 A
47 47 A
45 45 A
43 43 A
41 41 A
39 39 A
37 37 A
35 35 A
33 33 A
31 31 A
29 29 A
27 27 A
25 25 A
23 23 A
21 21 A
19 19 A
17 17 A
15 15 A
13 13 A
11 11 A
9 9 A
7 7 A
5 5 A
3 3 A
1 1 A

View File

@ -1,2 +1,2 @@
50
50
ABABABABABABABABABABABABABABABABABABABABABABABABAB

View File

@ -1,356 +1,356 @@
355
1 692 B
691 691 E
14 689 D
688 688 G
686 687 F
685 685 A
399 682 G
400 681 A
404 680 C
679 679 D
405 678 F
677 677 G
406 676 B
675 675 C
672 672 C
407 671 E
670 670 D
668 668 F
415 666 D
416 665 G
418 664 B
420 663 A
423 661 D
660 660 C
424 659 E
425 658 F
657 657 G
446 654 A
447 653 C
464 652 E
651 651 F
528 648 D
619 647 F
635 646 A
637 645 D
638 644 C
639 643 A
640 642 F
641 641 D
636 636 E
625 634 B
633 633 D
627 632 G
629 631 A
623 623 B
620 620 E
577 617 C
581 616 F
582 615 G
585 614 B
592 613 D
612 612 A
596 611 C
597 610 E
598 609 D
600 608 A
605 607 G
606 606 E
604 604 B
603 603 C
602 602 F
594 594 E
593 593 C
591 591 A
587 590 E
589 589 G
584 584 A
578 579 A
575 575 A
531 573 G
535 571 E
570 570 D
537 568 B
563 567 C
564 566 A
547 560 G
550 559 C
558 558 D
556 557 A
554 554 E
551 553 D
552 552 B
549 549 E
545 545 F
543 543 G
539 542 A
541 541 F
540 540 C
536 536 F
529 529 F
526 526 B
466 524 A
494 522 G
495 521 E
520 520 B
498 518 B
512 517 D
516 516 F
515 515 E
513 513 C
511 511 G
509 509 F
499 507 F
503 506 D
505 505 C
504 504 B
502 502 G
497 497 C
468 491 B
472 490 F
488 488 A
479 487 D
480 486 G
482 485 B
483 483 C
481 481 E
474 477 C
476 476 G
473 473 G
471 471 C
469 470 G
467 467 D
465 465 F
462 462 B
450 460 B
458 458 D
452 456 G
454 454 F
453 453 C
448 448 G
426 444 C
439 441 D
434 437 G
436 436 A
435 435 F
427 432 A
431 431 E
428 430 B
429 429 C
421 421 F
419 419 E
414 414 A
409 412 F
411 411 C
410 410 A
403 403 E
401 401 C
398 398 F
18 396 C
26 394 E
27 393 G
371 392 B
391 391 C
389 389 D
388 388 A
386 386 F
383 385 E
384 384 A
381 381 F
372 379 F
378 378 D
377 377 A
375 375 G
374 374 A
49 370 C
59 369 D
60 367 B
65 365 C
67 364 A
363 363 B
361 361 G
72 360 B
82 359 E
96 358 A
97 356 D
355 355 F
350 354 G
353 353 E
351 352 C
342 347 C
344 346 F
343 343 E
101 341 F
340 340 A
338 338 A
325 336 E
335 335 C
334 334 A
331 331 G
330 330 B
326 329 C
103 322 A
104 321 C
318 320 G
319 319 D
105 317 D
316 316 A
106 313 E
107 312 G
311 311 D
310 310 B
111 308 F
302 307 D
303 306 E
305 305 A
304 304 B
112 301 B
113 299 E
295 298 C
297 297 A
296 296 B
293 293 D
289 291 C
290 290 G
114 287 A
264 286 D
266 285 G
268 284 E
280 283 D
282 282 B
281 281 F
270 278 C
271 277 A
276 276 G
275 275 B
272 274 F
273 273 D
265 265 C
115 262 B
116 261 E
260 260 C
122 258 A
256 256 G
127 254 G
253 253 C
252 252 D
132 250 B
133 249 C
248 248 D
245 247 A
246 246 E
134 243 D
145 241 B
160 240 E
208 239 F
236 238 A
237 237 B
233 235 C
234 234 E
223 231 A
229 229 B
226 228 E
227 227 G
224 224 B
210 220 A
219 219 E
212 218 G
217 217 B
213 216 C
215 215 F
211 211 D
163 206 F
164 205 D
203 204 E
189 201 E
198 200 B
199 199 D
190 196 A
195 195 G
191 194 B
193 193 C
192 192 E
185 187 B
186 186 F
170 183 E
171 182 A
179 181 F
180 180 B
173 177 G
175 176 F
174 174 E
172 172 C
168 169 C
165 167 B
161 161 D
158 158 A
146 157 C
150 156 D
151 155 A
154 154 F
152 152 G
148 148 E
147 147 G
143 143 A
142 142 E
135 140 F
139 139 C
137 137 A
136 136 B
128 131 F
130 130 E
129 129 A
125 125 C
120 120 C
119 119 D
118 118 F
117 117 A
108 110 D
102 102 B
98 98 E
85 95 G
86 94 B
93 93 C
88 91 E
90 90 A
89 89 C
87 87 F
83 83 G
77 79 F
78 78 A
74 76 C
68 70 D
69 69 F
63 63 G
61 61 F
50 58 E
51 57 G
55 56 F
52 54 C
53 53 B
33 47 F
37 46 B
45 45 C
43 43 G
41 41 E
38 40 A
39 39 C
36 36 D
34 34 B
28 31 D
29 29 E
24 24 F
19 22 B
21 21 F
20 20 A
15 15 A
12 12 F
11 11 E
9 9 G
6 8 C
7 7 E
5 5 F
4 4 A
2 2 D
1 1 A
355
1 692 B
691 691 E
14 689 D
688 688 G
686 687 F
685 685 A
399 682 G
400 681 A
404 680 C
679 679 D
405 678 F
677 677 G
406 676 B
675 675 C
672 672 C
407 671 E
670 670 D
668 668 F
415 666 D
416 665 G
418 664 B
420 663 A
423 661 D
660 660 C
424 659 E
425 658 F
657 657 G
446 654 A
447 653 C
464 652 E
651 651 F
528 648 D
619 647 F
635 646 A
637 645 D
638 644 C
639 643 A
640 642 F
641 641 D
636 636 E
625 634 B
633 633 D
627 632 G
629 631 A
623 623 B
620 620 E
577 617 C
581 616 F
582 615 G
585 614 B
592 613 D
612 612 A
596 611 C
597 610 E
598 609 D
600 608 A
605 607 G
606 606 E
604 604 B
603 603 C
602 602 F
594 594 E
593 593 C
591 591 A
587 590 E
589 589 G
584 584 A
578 579 A
575 575 A
531 573 G
535 571 E
570 570 D
537 568 B
563 567 C
564 566 A
547 560 G
550 559 C
558 558 D
556 557 A
554 554 E
551 553 D
552 552 B
549 549 E
545 545 F
543 543 G
539 542 A
541 541 F
540 540 C
536 536 F
529 529 F
526 526 B
466 524 A
494 522 G
495 521 E
520 520 B
498 518 B
512 517 D
516 516 F
515 515 E
513 513 C
511 511 G
509 509 F
499 507 F
503 506 D
505 505 C
504 504 B
502 502 G
497 497 C
468 491 B
472 490 F
488 488 A
479 487 D
480 486 G
482 485 B
483 483 C
481 481 E
474 477 C
476 476 G
473 473 G
471 471 C
469 470 G
467 467 D
465 465 F
462 462 B
450 460 B
458 458 D
452 456 G
454 454 F
453 453 C
448 448 G
426 444 C
439 441 D
434 437 G
436 436 A
435 435 F
427 432 A
431 431 E
428 430 B
429 429 C
421 421 F
419 419 E
414 414 A
409 412 F
411 411 C
410 410 A
403 403 E
401 401 C
398 398 F
18 396 C
26 394 E
27 393 G
371 392 B
391 391 C
389 389 D
388 388 A
386 386 F
383 385 E
384 384 A
381 381 F
372 379 F
378 378 D
377 377 A
375 375 G
374 374 A
49 370 C
59 369 D
60 367 B
65 365 C
67 364 A
363 363 B
361 361 G
72 360 B
82 359 E
96 358 A
97 356 D
355 355 F
350 354 G
353 353 E
351 352 C
342 347 C
344 346 F
343 343 E
101 341 F
340 340 A
338 338 A
325 336 E
335 335 C
334 334 A
331 331 G
330 330 B
326 329 C
103 322 A
104 321 C
318 320 G
319 319 D
105 317 D
316 316 A
106 313 E
107 312 G
311 311 D
310 310 B
111 308 F
302 307 D
303 306 E
305 305 A
304 304 B
112 301 B
113 299 E
295 298 C
297 297 A
296 296 B
293 293 D
289 291 C
290 290 G
114 287 A
264 286 D
266 285 G
268 284 E
280 283 D
282 282 B
281 281 F
270 278 C
271 277 A
276 276 G
275 275 B
272 274 F
273 273 D
265 265 C
115 262 B
116 261 E
260 260 C
122 258 A
256 256 G
127 254 G
253 253 C
252 252 D
132 250 B
133 249 C
248 248 D
245 247 A
246 246 E
134 243 D
145 241 B
160 240 E
208 239 F
236 238 A
237 237 B
233 235 C
234 234 E
223 231 A
229 229 B
226 228 E
227 227 G
224 224 B
210 220 A
219 219 E
212 218 G
217 217 B
213 216 C
215 215 F
211 211 D
163 206 F
164 205 D
203 204 E
189 201 E
198 200 B
199 199 D
190 196 A
195 195 G
191 194 B
193 193 C
192 192 E
185 187 B
186 186 F
170 183 E
171 182 A
179 181 F
180 180 B
173 177 G
175 176 F
174 174 E
172 172 C
168 169 C
165 167 B
161 161 D
158 158 A
146 157 C
150 156 D
151 155 A
154 154 F
152 152 G
148 148 E
147 147 G
143 143 A
142 142 E
135 140 F
139 139 C
137 137 A
136 136 B
128 131 F
130 130 E
129 129 A
125 125 C
120 120 C
119 119 D
118 118 F
117 117 A
108 110 D
102 102 B
98 98 E
85 95 G
86 94 B
93 93 C
88 91 E
90 90 A
89 89 C
87 87 F
83 83 G
77 79 F
78 78 A
74 76 C
68 70 D
69 69 F
63 63 G
61 61 F
50 58 E
51 57 G
55 56 F
52 54 C
53 53 B
33 47 F
37 46 B
45 45 C
43 43 G
41 41 E
38 40 A
39 39 C
36 36 D
34 34 B
28 31 D
29 29 E
24 24 F
19 22 B
21 21 F
20 20 A
15 15 A
12 12 F
11 11 E
9 9 G
6 8 C
7 7 E
5 5 F
4 4 A
2 2 D
1 1 A

View File

@ -1,2 +1,2 @@
692
692
ADBAFCECGBEFBDADDCBAFBCFCEGDEDDGFBFDBACAEBGBCBFGCEGCBCFFGEDBFBGBCCADFDABBCCCFAFBBEGEGBFECAEBCBGADEDDFBACDEGDDDFBEABEAFDCEAAACAGFAEFBCDFBAFCFDEADBCGECDAGAFADCABEDEFDBBBCCEACGEFFGAFBFAEDBFBDEABECBGAEBDBEDEEDFEFFADGCCFCBGEAFFABAEGEBAAFCECABAFEBDDCAEADCBGDCGAGAAECEBADCGGEECAFDFBGACEDFBDEGDAECGCEDECBACEBBDEBAEDFGBDGEDDADGDGCAFFECCCCBGEEACEFAFAFCEFFFCDDGCCEGFDAAEBGABACBBDDCBFFAGFADFBFBEAEFBADBCBGECCDFGACAECFBEEFACFEADGGBEAFADEFCABCBEACGFAGCDDDCCCFACGCBBGCFGGBDBBCBCEFADBGGCFGCCGCFDGEBCBBGDAFFBAAGEECBFFFGDBCDFBFBGDCDEFDBEBEGAAEBEDFDGGGGEFBBACFAGBFBGGECDBDECAADCGBBCAAACBEDEGGDADCAACFGGABBEEGEADCEDCEDDAAFCBGEGADECADBGFCDFEFFBFBBGGAAAGDBAEDCAFDFACDAFDEEFECAFFGFECDAABGDEFEDECBBCBGFDCAGDDAFFGDBEB

View File

@ -1,117 +1,117 @@
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

View File

@ -1,83 +1,83 @@
#include <cstdio>
#include <iostream>
#include <limits>
#include <algorithm>
#include <queue>
#include <bitset>
using ll = long long;
auto &is = std::cin;
auto &os = std::cout;
struct Point{
ll x,y;
};
struct Status{
Point now;
ll step;
bool operator<(const Status &that)const noexcept{
return this->step > that.step;
}
};
const ll max_nm {200+5};
const ll ll_max {std::numeric_limits<decltype(ll_max)>::max()};
ll n, h, w, ans{ll_max};
char map[max_nm][max_nm];
Point me;
const int to_next[4][2] {
{1,0},
{0,1},
{-1,0},
{0,-1},
};
void bfs(const Point start)noexcept{
std::bitset<max_nm> vis[max_nm];
std::priority_queue<Status> q;
ans = ll_max;
vis[start.x][start.y] = true;
q.push({start,0});
while(q.empty()==false){
const auto status = q.top();
const auto nowchar = [&status]()->char{return map[status.now.x][status.now.y];};
q.pop();
if(nowchar()=='a'){
ans = std::min(ans,status.step);
return;
}
for(ll i{0};i<4;i++){
const Point next {status.now.x+to_next[i][0],status.now.y+to_next[i][1]};
if(vis[next.x][next.y])continue;
const auto nextchar = [&next]()->char{return map[next.x][next.y];};
ll cost {1};
if(next.x>h || next.x<=0 || next.y > w || next.y<=0
|| nextchar()=='#')continue;
if(nextchar()=='x')cost++;
const Status next_status {next,status.step+cost};
vis[next_status.now.x][next_status.now.y] = true;
q.push(next_status);
}
}
return;
}
int main(){
is>>n;
for(ll _{0};_<n;_++){
is>>h>>w;
for(ll i{1};i<=h;i++){
for(ll j{1};j<=w;j++){
is>>map[i][j];
if(map[i][j]=='r')me.x=i,me.y=j;
}
}
bfs(me);
if(ans==ll_max)os<<"Impossible\n";
else os<<ans<<'\n';
}
#include <cstdio>
#include <iostream>
#include <limits>
#include <algorithm>
#include <queue>
#include <bitset>
using ll = long long;
auto &is = std::cin;
auto &os = std::cout;
struct Point{
ll x,y;
};
struct Status{
Point now;
ll step;
bool operator<(const Status &that)const noexcept{
return this->step > that.step;
}
};
const ll max_nm {200+5};
const ll ll_max {std::numeric_limits<decltype(ll_max)>::max()};
ll n, h, w, ans{ll_max};
char map[max_nm][max_nm];
Point me;
const int to_next[4][2] {
{1,0},
{0,1},
{-1,0},
{0,-1},
};
void bfs(const Point start)noexcept{
std::bitset<max_nm> vis[max_nm];
std::priority_queue<Status> q;
ans = ll_max;
vis[start.x][start.y] = true;
q.push({start,0});
while(q.empty()==false){
const auto status = q.top();
const auto nowchar = [&status]()->char{return map[status.now.x][status.now.y];};
q.pop();
if(nowchar()=='a'){
ans = std::min(ans,status.step);
return;
}
for(ll i{0};i<4;i++){
const Point next {status.now.x+to_next[i][0],status.now.y+to_next[i][1]};
if(vis[next.x][next.y])continue;
const auto nextchar = [&next]()->char{return map[next.x][next.y];};
ll cost {1};
if(next.x>h || next.x<=0 || next.y > w || next.y<=0
|| nextchar()=='#')continue;
if(nextchar()=='x')cost++;
const Status next_status {next,status.step+cost};
vis[next_status.now.x][next_status.now.y] = true;
q.push(next_status);
}
}
return;
}
int main(){
is>>n;
for(ll _{0};_<n;_++){
is>>h>>w;
for(ll i{1};i<=h;i++){
for(ll j{1};j<=w;j++){
is>>map[i][j];
if(map[i][j]=='r')me.x=i,me.y=j;
}
}
bfs(me);
if(ans==ll_max)os<<"Impossible\n";
else os<<ans<<'\n';
}
}

View File

@ -1,76 +1,76 @@
#include <type_traits>
#define NDEBUG
#include <iostream>
#ifndef NDEBUG
#include <stdexcept>
#include <sstream>
#endif
#define NV(v)#v<<" : "<<(v)
using ull = unsigned long long;
#ifdef NDEBUG
#define ARR_NDB_NOEXCEPT noexcept
#define ARR_NDB_CONSTEXPR constexpr
#else
#define ARR_NDB_CONSTEXPR
#define ARR_NDB_NOEXCEPT
#endif
template<size_t a,size_t b>
constexpr bool test(){
return a>=b;
}
template<class T, size_t size>
class Array{
public:
private:
T arr[size];
public:
ARR_NDB_CONSTEXPR T& operator[](const size_t n)ARR_NDB_NOEXCEPT{
#ifndef NDEBUG
if(n>=size){
std::stringstream ss;
ss<<"\nYour [array size] is: "<<size<<"\nBut your [index] is :"<<n<<'\n';
throw std::range_error(ss.str());
}
#endif
return arr[n];
}
ARR_NDB_CONSTEXPR const T& operator[](const size_t n)const ARR_NDB_NOEXCEPT{
#ifndef NDEBUG
if(n>=size){
std::stringstream ss;
ss<<"\nYour [array size] is: "<<size<<"\nBut your [index] is :"<<n<<'\n';
throw std::range_error(ss.str());
}
#endif
return arr[n];
}
ARR_NDB_CONSTEXPR operator const T*()const ARR_NDB_NOEXCEPT{
return arr;
}
constexpr bool is_const()const{
return true;
}
constexpr bool is_const(){
return false;
}
};
constexpr size_t size {10};
constexpr Array<ull,size> arr{};
ull a;
int main(){
std::cout<<NV(arr)<<'\n';
// std::cout<<NV(&arr[size-1])<<'\n'<<NV(&a)<<'\n';
// std::cout<<NV(a)<<'\n';
// std::cout<<NV(++arr[size])<<'\n';
// std::cout<<NV(a)<<'\n';
constexpr ull a {arr[size-1]};
const constexpr ull *p {arr};
std::cout<<NV(a)<<'\n'<<NV(p)<<'\n';
#include <type_traits>
#define NDEBUG
#include <iostream>
#ifndef NDEBUG
#include <stdexcept>
#include <sstream>
#endif
#define NV(v)#v<<" : "<<(v)
using ull = unsigned long long;
#ifdef NDEBUG
#define ARR_NDB_NOEXCEPT noexcept
#define ARR_NDB_CONSTEXPR constexpr
#else
#define ARR_NDB_CONSTEXPR
#define ARR_NDB_NOEXCEPT
#endif
template<size_t a,size_t b>
constexpr bool test(){
return a>=b;
}
template<class T, size_t size>
class Array{
public:
private:
T arr[size];
public:
ARR_NDB_CONSTEXPR T& operator[](const size_t n)ARR_NDB_NOEXCEPT{
#ifndef NDEBUG
if(n>=size){
std::stringstream ss;
ss<<"\nYour [array size] is: "<<size<<"\nBut your [index] is :"<<n<<'\n';
throw std::range_error(ss.str());
}
#endif
return arr[n];
}
ARR_NDB_CONSTEXPR const T& operator[](const size_t n)const ARR_NDB_NOEXCEPT{
#ifndef NDEBUG
if(n>=size){
std::stringstream ss;
ss<<"\nYour [array size] is: "<<size<<"\nBut your [index] is :"<<n<<'\n';
throw std::range_error(ss.str());
}
#endif
return arr[n];
}
ARR_NDB_CONSTEXPR operator const T*()const ARR_NDB_NOEXCEPT{
return arr;
}
constexpr bool is_const()const{
return true;
}
constexpr bool is_const(){
return false;
}
};
constexpr size_t size {10};
constexpr Array<ull,size> arr{};
ull a;
int main(){
std::cout<<NV(arr)<<'\n';
// std::cout<<NV(&arr[size-1])<<'\n'<<NV(&a)<<'\n';
// std::cout<<NV(a)<<'\n';
// std::cout<<NV(++arr[size])<<'\n';
// std::cout<<NV(a)<<'\n';
constexpr ull a {arr[size-1]};
const constexpr ull *p {arr};
std::cout<<NV(a)<<'\n'<<NV(p)<<'\n';
}

View File

@ -1,37 +1,37 @@
#include <iostream>
#include <string>
#include <bitset>
#include <ranges>
static const size_t MAX_LEN {(size_t)2e3+5};
static std::string s,p;
static constexpr auto range {std::ranges::views::iota};
static std::bitset<MAX_LEN> dp[MAX_LEN];
int main(){
const auto get_p = [](const size_t n)noexcept->const char&{return p[n-1];};
const auto get_s = [](const size_t n)noexcept->const char&{return s[n-1];};
std::cin>>s>>p;
dp[0][0] = true;
for(const size_t j:range((size_t)1,p.size()+1)){
if(get_p(j)!='*'){
break;
}
dp[0][j]=true;
}
for(const size_t i:range((size_t)1,s.size()+1)){
for(const size_t j:range((size_t)1,p.size()+1)){
if(get_s(i) == get_p(j) || get_p(j)=='?'){
dp[i][j] = dp[i-1][j-1];
}else if(get_p(j)=='*'){
dp[i][j] = dp[i-1][j] || dp[i][j-1]; //01背包查看是否使用这个字符
}
}
}
std::cout<<(dp[s.size()][p.size()]==true?"yes":"no")<<'\n';
#include <iostream>
#include <string>
#include <bitset>
#include <ranges>
static const size_t MAX_LEN {(size_t)2e3+5};
static std::string s,p;
static constexpr auto range {std::ranges::views::iota};
static std::bitset<MAX_LEN> dp[MAX_LEN];
int main(){
const auto get_p = [](const size_t n)noexcept->const char&{return p[n-1];};
const auto get_s = [](const size_t n)noexcept->const char&{return s[n-1];};
std::cin>>s>>p;
dp[0][0] = true;
for(const size_t j:range((size_t)1,p.size()+1)){
if(get_p(j)!='*'){
break;
}
dp[0][j]=true;
}
for(const size_t i:range((size_t)1,s.size()+1)){
for(const size_t j:range((size_t)1,p.size()+1)){
if(get_s(i) == get_p(j) || get_p(j)=='?'){
dp[i][j] = dp[i-1][j-1];
}else if(get_p(j)=='*'){
dp[i][j] = dp[i-1][j] || dp[i][j-1]; //01背包查看是否使用这个字符
}
}
}
std::cout<<(dp[s.size()][p.size()]==true?"yes":"no")<<'\n';
}

View File

@ -1,60 +1,60 @@
# Wildcard Match
># wildcard_match
题目描述:
给定一个字符串 `s` 和一个模式 `p`,实现通配符模式匹配,支持 '?' 和 '*',其中:
- '?' 匹配任意单个字符。
- '*' 匹配任意长度的字符序列(包括空序列)。
匹配应覆盖整个输入字符串(不允许部分匹配)。
输入:
- 第一行是字符串 `s`
- 第二行是字符串 `p`
约束:
- 0 < s.length, p.length < 2000
- `s` 仅包含小写英文字母。
- `p` 仅包含小写英文字母、'?' 或 '*'。
输出:
- 输出 "yes" 或 "no"。
---
示例 1
输入:
```
app
ap
```
输出:
```
no
```
---
示例 2
输入:
```
app
a?p
```
输出:
```
yes
```
---
示例 3
输入:
```
abc
a*
```
输出:
```
yes
# Wildcard Match
># wildcard_match
题目描述:
给定一个字符串 `s` 和一个模式 `p`,实现通配符模式匹配,支持 '?' 和 '*',其中:
- '?' 匹配任意单个字符。
- '*' 匹配任意长度的字符序列(包括空序列)。
匹配应覆盖整个输入字符串(不允许部分匹配)。
输入:
- 第一行是字符串 `s`
- 第二行是字符串 `p`
约束:
- 0 < s.length, p.length < 2000
- `s` 仅包含小写英文字母。
- `p` 仅包含小写英文字母、'?' 或 '*'。
输出:
- 输出 "yes" 或 "no"。
---
示例 1
输入:
```
app
ap
```
输出:
```
no
```
---
示例 2
输入:
```
app
a?p
```
输出:
```
yes
```
---
示例 3
输入:
```
abc
a*
```
输出:
```
yes
```

86418
test.cpp

File diff suppressed because it is too large Load Diff