├── .clang-format ├── .gitignore ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── Checker ├── Adapters │ ├── BZOJJudger.cpp │ ├── DefaultJudger.cpp │ ├── LOJJudger.cpp │ └── UOJJudger.cpp ├── CMakeLists.txt ├── Checker.cpp ├── CheckerConfig.hpp.in ├── Common.cpp ├── Common.hpp ├── Judger.cpp ├── Judger.hpp ├── Network.cpp ├── Network.hpp ├── OJAPI.cpp ├── OJAPI.hpp ├── OJAdapter.cpp ├── OJAdapter.hpp ├── Platforms │ ├── Linux │ │ ├── PerfAnalyzer.cpp │ │ ├── PerfAnalyzer.hpp │ │ ├── PlatformLinux.cpp │ │ ├── PlatformLinux.hpp │ │ └── RunnerLinux.cpp │ ├── Platform.hpp │ └── Windows │ │ ├── PlatformWindows.cpp │ │ ├── PlatformWindows.hpp │ │ └── RunnerWindows.cpp ├── Runner.hpp ├── RunnerShared.cpp ├── Scanner.cpp ├── Scanner.hpp ├── Test │ ├── CheckerTest.cpp │ └── CheckerTestGen.cpp ├── Timer.cpp ├── Timer.hpp └── readme.md ├── OI-Source.code-workspace ├── Queue.md ├── Review ├── Backmatter.tex ├── Bib.tex ├── CG │ ├── Base.tex │ ├── CG.tex │ ├── Circle.tex │ ├── Convex.tex │ ├── Delaunay.tex │ ├── HPI.tex │ ├── Nearest.tex │ └── RCA.tex ├── Combinatorics │ ├── Bell.tex │ ├── BoxAndBall.tex │ ├── Catalan.tex │ ├── Combinatorics.tex │ ├── Lucas.tex │ ├── Permutation.tex │ └── Stirling.tex ├── DP │ ├── Bag.tex │ ├── Convex.tex │ ├── DP.tex │ ├── Dynamic.tex │ ├── Link.tex │ ├── Mono.tex │ ├── MultiBag.cpp │ ├── Number.tex │ ├── Power.tex │ ├── Quad.tex │ ├── Queue.tex │ ├── SDP.tex │ └── Slope.tex ├── DataStructure │ ├── BIT.tex │ ├── BST.tex │ ├── DLX.tex │ ├── DSU.tex │ ├── DataStructure.tex │ ├── ETT.tex │ ├── Functional.tex │ ├── HashTable.tex │ ├── Heap.tex │ ├── K-DTree.tex │ ├── LCT.tex │ ├── OldDriverTree.tex │ ├── PartitionedTree.cpp │ ├── PartitionedTree.tex │ ├── RandomTestA.cpp │ ├── RandomTestB.cpp │ ├── SegTree.tex │ └── UVA11987.cpp ├── GameTheory │ ├── AlphaBeta.tex │ ├── GameTheory.tex │ ├── Nim.tex │ ├── NimSG.cpp │ └── SGFunction.tex ├── Graph │ ├── 2-SAT.tex │ ├── CST.tex │ ├── Chord.tex │ ├── CutVertex.cpp │ ├── CutVertexAndBridge.tex │ ├── DominatorTree.tex │ ├── EulerPath.cpp │ ├── Graph.tex │ ├── Matching.tex │ ├── Other.tex │ ├── PEBC.tex │ ├── Path.tex │ └── SCC.tex ├── LinearAlgebra │ ├── Base.tex │ ├── Det.tex │ ├── Gauss.tex │ ├── InvMatGauss.cpp │ ├── LUP.tex │ ├── LeastSquares.tex │ ├── LinearAlgebra.tex │ └── LinearRecurrence.tex ├── Main.tex ├── Math │ ├── BerlekampMassey.tex │ ├── CharacteristicEquation.tex │ ├── Equation.tex │ ├── GeneratingFunction.tex │ ├── GeneratingGraph.tex │ ├── Inversion.tex │ ├── LIP.tex │ ├── LinearIP.tex │ ├── Math.tex │ ├── Probability.tex │ ├── Simpson.tex │ └── Taylor.tex ├── MathSymbol.tex ├── NetworkFlows │ ├── BGJudge.cpp │ ├── BipartiteGraph.tex │ ├── Gomory-HuTree.tex │ ├── LimitedNetworkFlows.tex │ ├── MCMF.tex │ ├── MaxFlow.tex │ ├── Models.tex │ ├── NetworkFlows.tex │ ├── PreFlow.cpp │ └── Tricks.tex ├── NumberTheory │ ├── CRT.tex │ ├── Dirichlet.tex │ ├── DiscreteLogarithm.tex │ ├── Euclidlike.tex │ ├── Euler.tex │ ├── GCD.tex │ ├── MultiplicativeFunction.tex │ ├── NumberTheory.tex │ ├── PollardRho.tex │ ├── PrimalityTest.tex │ ├── PrimitiveRoot.tex │ ├── RSA.tex │ ├── Residue.tex │ └── Sieve.tex ├── Optmize │ ├── FP.tex │ ├── GD.cpp │ ├── LP.tex │ ├── Optmize.tex │ ├── OptmizeMethod.tex │ └── Random.tex ├── Other │ ├── IOGen.cpp │ ├── IOTest.hpp │ ├── IOTestA.cpp │ ├── IOTestB.cpp │ ├── IOTestC.cpp │ ├── Mat.cpp │ ├── Other.tex │ ├── Owys.tex │ └── TricksAndIdeas.tex ├── Path │ ├── DCS.tex │ ├── KthSP.tex │ ├── Path.tex │ └── SMSSP.tex ├── Polynomial │ ├── Advanced.tex │ ├── FFT.tex │ ├── FMT.tex │ ├── FWT.tex │ ├── Module.tex │ ├── NTT.tex │ ├── Optmize.tex │ ├── Perf │ │ ├── LOJ150.cpp │ │ ├── LinuxTimer.hpp │ │ ├── MulTest.cpp │ │ ├── NTT.hpp │ │ ├── PolyExp.hpp │ │ ├── PolyExpTest.cpp │ │ ├── PolyInv.hpp │ │ ├── PolyInvTest.cpp │ │ ├── PolySqrt.hpp │ │ ├── PolySqrtTest.cpp │ │ ├── TestLib.hpp │ │ └── WindowsTimer.hpp │ └── Polynomial.tex ├── Recommendation.tex ├── SetAndGroupTheory │ ├── Lagrange.tex │ ├── PermutationGroups.tex │ ├── SetAndGroupTheory.tex │ └── SetTheory.tex ├── Source ├── SpanningTree │ ├── Kruskal.tex │ ├── MST.tex │ ├── Manhattan.tex │ ├── MatrixTree.tex │ ├── SpanningTree.tex │ └── SteinerTree.tex ├── String │ ├── ACM.tex │ ├── BOP.cpp │ ├── Convolution.tex │ ├── Hash.tex │ ├── Huffman.tex │ ├── KMP.tex │ ├── LLH.cpp │ ├── Manacher.tex │ ├── Min.tex │ ├── PAM.tex │ ├── Parser.tex │ ├── SA.tex │ ├── SAM.tex │ ├── SC.tex │ ├── ST.tex │ ├── String.tex │ ├── Trie.tex │ └── ZAlgorithm.tex ├── Summary │ ├── Input.tex │ ├── Keyword.tex │ ├── LinkBlock.tex │ ├── Summary.tex │ └── Time.tex ├── Theory │ ├── Analysis.tex │ ├── Coding.tex │ ├── NP.tex │ ├── Sort.tex │ └── Theory.tex ├── Tree │ ├── CBD.tex │ ├── Diameter.tex │ ├── DsuOnTree.tex │ ├── LCA.tex │ ├── PBD.tex │ ├── Purfer.tex │ ├── Tarjan.cpp │ ├── Tree.tex │ └── VirtualTree.tex ├── charCounter.cpp └── mypic.jpg ├── Source ├── 2-SAT │ ├── 3209.cpp │ ├── bzoj2649.cpp │ └── bzoj3495.cpp ├── ACM │ ├── BZOJ2780.cpp │ └── LOJ2180.cpp ├── BBT │ └── 3721.cpp ├── Block │ ├── 2801.cpp │ ├── 2801FHQTreap.cpp │ ├── 3396.cpp │ ├── 3591.cpp │ ├── 3645.cpp │ ├── 4108.cpp │ ├── LOJ2874.cpp │ ├── LOJ6277.cpp │ ├── LOJ6278.cpp │ ├── LOJ6279.cpp │ ├── LOJ6280.cpp │ ├── LOJ6281.cpp │ ├── LOJ6282.cpp │ ├── LOJ6283.cpp │ ├── LOJ6284.cpp │ ├── LOJ6285.cpp │ └── bzoj2741.cpp ├── CBD │ ├── CF1009F.cpp │ ├── LOJ2079.cpp │ ├── LOJ2558.cpp │ ├── LOJ2558BIT.cpp │ └── bzoj4543.cpp ├── CDQ │ ├── 3206.cpp │ ├── LOJ2049.cpp │ └── bzoj2989.cpp ├── CG │ ├── 3236.cpp │ ├── BZOJ4138.cpp │ ├── CIRUT.cpp │ └── LOJ6360.cpp ├── CST │ ├── 4320-bzoj3331.cpp │ ├── 4630.cpp │ ├── LOJ10099.cpp │ ├── LOJ2062A.cpp │ ├── LOJ2062B.cpp │ ├── LOJ2562.cpp │ ├── LOJ2587.cpp │ └── bzoj2125-Luogu5236.cpp ├── Cacti │ ├── 3687.cpp │ ├── 4244.cpp │ └── 4630.cpp ├── ChordAndMCS │ └── 3196.cpp ├── Competition │ ├── APIO │ │ ├── LOJ2310.cpp │ │ ├── LOJ2567.cpp │ │ ├── LOJ2586.cpp │ │ ├── LOJ2586LUT.cpp │ │ ├── LOJ2586Tab.cpp │ │ ├── LOJ2886.cpp │ │ ├── LOJ2886WA.cpp │ │ ├── LOJ2887A.cpp │ │ ├── LOJ2887B.cpp │ │ └── LOJ2887TLE.cpp │ ├── CTSC │ │ ├── LOJ2261.cpp │ │ ├── LOJ2263.cpp │ │ ├── LOJ2264A.cpp │ │ ├── LOJ2264B.cpp │ │ ├── LOJ2552.cpp │ │ ├── LOJ2555.cpp │ │ ├── LOJ2987.cpp │ │ └── LOJ3122.cpp │ ├── CodePlus6 │ │ ├── box.cpp │ │ ├── factor.cpp │ │ ├── tree.cpp │ │ ├── zuma.cpp │ │ └── zuma2.cpp │ ├── FCS2019 │ │ ├── Day1 │ │ │ ├── highway.cpp │ │ │ ├── highwayC.cpp │ │ │ ├── sailing.cpp │ │ │ ├── sailingC.cpp │ │ │ └── shopping.cpp │ │ ├── Day2 │ │ │ ├── farmer.cpp │ │ │ ├── farmerC.cpp │ │ │ ├── farmerSeg.cpp │ │ │ ├── max.cpp │ │ │ └── maxC.cpp │ │ ├── Day3 │ │ │ ├── game.cpp │ │ │ ├── game2.cpp │ │ │ ├── gameC.cpp │ │ │ └── string.cpp │ │ ├── Day4 │ │ │ ├── paths.cpp │ │ │ ├── paths2.cpp │ │ │ ├── quiz.cpp │ │ │ └── racing.cpp │ │ ├── Day5 │ │ │ ├── number.cpp │ │ │ ├── number2.cpp │ │ │ ├── numberC.cpp │ │ │ ├── table.cpp │ │ │ ├── table2.cpp │ │ │ └── tableC.cpp │ │ ├── Day6 │ │ │ ├── blue.cpp │ │ │ ├── blueC.cpp │ │ │ ├── secretC.cpp │ │ │ └── set.cpp │ │ └── Day7 │ │ │ ├── cac.cpp │ │ │ ├── cacdbg.cpp │ │ │ ├── island.cpp │ │ │ └── riverC.cpp │ ├── Multi2019 │ │ ├── LOJ3048.cpp │ │ ├── LOJ3050.cpp │ │ ├── LOJ3050Test1.cpp │ │ ├── LOJ3050Test2.cpp │ │ ├── LOJ3050Test3.cpp │ │ ├── LOJ3052.cpp │ │ └── LOJ3052LinearWA.cpp │ ├── NOI │ │ ├── LOJ2083.cpp │ │ ├── LOJ2084.cpp │ │ ├── LOJ2086.cpp │ │ ├── LOJ2129.cpp │ │ ├── LOJ2130.cpp │ │ ├── LOJ2132.cpp │ │ ├── LOJ2246A.cpp │ │ ├── LOJ2246B.cpp │ │ ├── LOJ2248.cpp │ │ ├── LOJ2249A.cpp │ │ ├── LOJ2302.cpp │ │ ├── LOJ2303.cpp │ │ ├── LOJ2305.cpp │ │ ├── LOJ2444.cpp │ │ ├── LOJ2445.cpp │ │ ├── LOJ2667.cpp │ │ ├── LOJ2667Hacked.cpp │ │ ├── LOJ2669.cpp │ │ ├── LOJ2670.cpp │ │ ├── LOJ2672.cpp │ │ ├── LOJ2718.cpp │ │ └── LOJ2721.cpp │ ├── THUPC2019 │ │ └── LOJ6620.cpp │ └── ZJOI2019 │ │ └── LOJ3043.cpp ├── Count │ ├── 2532.cpp │ ├── 3200.cpp │ ├── 3200CRT.cpp │ ├── 3757.cpp │ ├── 4187.cpp │ ├── 4678.cpp │ ├── CF348D.cpp │ ├── LOJ2027.cpp │ ├── LOJ547.cpp │ ├── LOJ6358.cpp │ ├── SP9507.cpp │ ├── bzoj2111.cpp │ ├── bzoj3198.cpp │ └── bzoj3501.cpp ├── DDP │ ├── 4513.cpp │ ├── LOJ2269.cpp │ ├── LOJ2955.cpp │ └── bzoj4712.cpp ├── DP │ ├── 1912.cpp │ ├── 2254.cpp │ ├── 2317.cpp │ ├── 2900.cpp │ ├── 3503.cpp │ ├── 3572.cpp │ ├── 3594.cpp │ ├── 3594G.cpp │ ├── 4104.cpp │ ├── 4127.cpp │ ├── 4577.cpp │ ├── 4767.cpp │ ├── 4769.cpp │ ├── 4769test.cpp │ ├── CF691E.cpp │ ├── CF868F.cpp │ ├── HDU5956.cpp │ ├── LOJ10188.cpp │ ├── LOJ10190.cpp │ ├── LOJ10192.cpp │ ├── LOJ2074.cpp │ ├── LOJ2110.cpp │ ├── LOJ2124.cpp │ ├── LOJ2157.cpp │ ├── LOJ2157B.cpp │ ├── LOJ2249.cpp │ ├── LOJ2353.cpp │ ├── LOJ2356.cpp │ ├── LOJ2481.cpp │ ├── LOJ2483DC.cpp │ ├── LOJ2483RBHPI.cpp │ ├── LOJ2688.cpp │ ├── LOJ535.cpp │ ├── LOJ6039.cpp │ ├── LOJ6081.cpp │ ├── P3994.cpp │ ├── bzoj2096.cpp │ ├── bzoj2739.cpp │ ├── bzoj3583.cpp │ ├── bzoj3675nklg.cpp │ ├── bzoj4709.cpp │ └── bzoj5311TLE.cpp ├── DSU │ └── BZOJ3712.cpp ├── Divide │ └── bzoj3110.cpp ├── DominatorTree │ ├── 2597.cpp │ └── LOJ6511.cpp ├── DsuOnTree │ ├── CF570D.cpp │ └── CF741D.cpp ├── FFT NTT │ ├── 3321.cpp │ ├── 3338.cpp │ ├── 3723.cpp │ ├── 4238.cpp │ ├── 4239.cpp │ ├── 4245.cpp │ ├── 4491.cpp │ ├── 4512.cpp │ ├── 4721.cpp │ ├── 4725.cpp │ ├── 4726.cpp │ ├── 5205.cpp │ ├── BZOJ3160.cpp │ ├── BZOJ4259.cpp │ ├── BZOJ4503.cpp │ ├── CF528D.cpp │ ├── CF553E.cpp │ ├── CF623E.cpp │ ├── CF662C.cpp │ ├── CF923E.cpp │ ├── LOJ150.cpp │ ├── LOJ151.cpp │ ├── LOJ2020.cpp │ ├── LOJ2058.cpp │ ├── LOJ2183.cpp │ ├── LOJ2527.cpp │ ├── LOJ2541.cpp │ ├── LOJ556.cpp │ ├── LOJ556X.cpp │ ├── LOJ6261.cpp │ ├── LOJ6261Test.cpp │ ├── LOJ6388.cpp │ ├── LOJ6503.cpp │ └── P4191.cpp ├── FHQTreap │ ├── 2596.cpp │ ├── 3165.cpp │ ├── 3278.cpp │ ├── 3285.cpp │ ├── 3285.txt │ ├── 3285gen.cpp │ ├── 3835.cpp │ └── LOJ516.cpp ├── FWT FMT │ ├── CF850E.cpp │ ├── LOJ152.cpp │ ├── LOJ153.cpp │ ├── LOJ154TLE.cpp │ ├── LOJ570.cpp │ ├── LuoguP5387.cpp │ ├── LuoguP5387TestA.cpp │ └── LuoguP5387TestB.cpp ├── Fractional Programming │ ├── 1642.cpp │ ├── 3288.cpp │ ├── LOJ2071.cpp │ ├── LOJ2214.cpp │ └── LOJ2734.cpp ├── Game Theory │ ├── 2197.cpp │ ├── 2252.cpp │ ├── 2252test.cpp │ ├── 2575.cpp │ ├── 2964.cpp │ ├── 2964dp.cpp │ ├── 3185.cpp │ ├── 3235.cpp │ ├── 3480.cpp │ └── 4279.cpp ├── Generating Function │ ├── 4091.cpp │ ├── 4389.cpp │ ├── 4451.cpp │ ├── 4705.cpp │ ├── BZOJ3456.cpp │ ├── BZOJ3684.cpp │ ├── CF438E.cpp │ ├── LOJ2271.cpp │ ├── LOJ2554.cpp │ └── P4548.cpp ├── Greed │ ├── 2570.cpp │ ├── BZOJ1398.cpp │ ├── LOJ6254.cpp │ ├── UOJ455WA.cpp │ └── bzoj2288.cpp ├── Groop │ ├── 4727.cpp │ ├── UVA10601.cpp │ ├── UVA10601X.cpp │ └── UVA11255.cpp ├── HPI │ ├── 2600.cpp │ ├── 3256.cpp │ ├── 3297.cpp │ ├── 4196.cpp │ └── bzoj2961.cpp ├── Hash │ └── bzoj3084TLE.cpp ├── Inversion │ ├── BZOJ3328.cpp │ └── LOJ6485.cpp ├── K-d Tree │ ├── 1648.cpp │ ├── 2093.cpp │ ├── 3769WA.cpp │ ├── 3810-2DTree.cpp │ ├── 3810-3DTree.cpp │ ├── 4148.cpp │ ├── 4169.cpp │ ├── 4793.cpp │ ├── 4793gen.cpp │ ├── LOJ6016A.cpp │ ├── LOJ6016B.cpp │ ├── bzoj2626.cpp │ ├── bzoj2648.cpp │ ├── bzoj2850.cpp │ └── bzoj4520.cpp ├── KMP │ ├── 3193.cpp │ └── LOJ2272.cpp ├── LCT │ ├── 1501.cpp │ ├── 2173.cpp │ ├── 2387.cpp │ ├── 3703.cpp │ ├── 4121.cpp │ ├── 4172.cpp │ ├── 4234.cpp │ ├── 4299A.cpp │ ├── 4299AX.cpp │ ├── 4299B.cpp │ ├── LOJ2001.cpp │ ├── LOJ2230.cpp │ ├── LOJ2245.cpp │ ├── LOJ2289.cpp │ ├── LOJ2497.cpp │ ├── LOJ558.cpp │ ├── LOJ6038.cpp │ ├── QTREE5.cpp │ ├── QTREE6A.cpp │ ├── QTREE6B.cpp │ ├── QTREE7.cpp │ ├── SP8791.cpp │ ├── UOJ207.cpp │ └── bzoj3514.cpp ├── LinearBasis │ ├── 3857.cpp │ ├── 4570.cpp │ ├── LOJ114.cpp │ ├── LOJ2312.cpp │ ├── bzoj4184.cpp │ ├── bzoj4184B.cpp │ └── bzoj4269.cpp ├── Link │ ├── 3190.cpp │ ├── 3886.cpp │ ├── 5056.cpp │ └── bzoj2310.cpp ├── Matrix │ ├── LOJ10025.cpp │ ├── LOJ2106.cpp │ ├── P3216.cpp │ ├── P5107.cpp │ ├── P5107B.cpp │ ├── P5110.cpp │ ├── P5110B.cpp │ ├── P5110Test.cpp │ └── bzoj4128.cpp ├── MergableHeap │ ├── 4331.cpp │ ├── CF671D.cpp │ └── bzoj2809.cpp ├── MinMax │ ├── LOJ2127.cpp │ └── LOJ2542.cpp ├── Mobius │ ├── 2257.cpp │ ├── 3455.cpp │ ├── 4318.cpp │ ├── LOJ2000.cpp │ ├── LOJ2000TLE.cpp │ ├── LOJ2095.cpp │ ├── LOJ2565.cpp │ └── LOJ528.cpp ├── Network Flows │ ├── 2046.cpp │ ├── 2057.cpp │ ├── 2172.cpp │ ├── 2469.cpp │ ├── 2570.cpp │ ├── 2754.cpp │ ├── 2761.cpp │ ├── 2762.cpp │ ├── 2763.cpp │ ├── 2764.cpp │ ├── 2766.cpp │ ├── 2770.cpp │ ├── 2774.cpp │ ├── 3163.cpp │ ├── 3254.cpp │ ├── 3280.cpp │ ├── 3329.cpp │ ├── 3355.cpp │ ├── 3356.cpp │ ├── 3357.cpp │ ├── 3358.cpp │ ├── 3980.cpp │ ├── 4009.cpp │ ├── 4011.cpp │ ├── 4012.cpp │ ├── 4013.cpp │ ├── 4014.cpp │ ├── 4015.cpp │ ├── 4016.cpp │ ├── 4043.cpp │ ├── 4123.cpp │ ├── 4174.cpp │ ├── 4553.cpp │ ├── 4843.cpp │ ├── CF739E.cpp │ ├── CF786E.cpp │ ├── LOJ115.cpp │ ├── LOJ116.cpp │ ├── LOJ117.cpp │ ├── LOJ2042.cpp │ ├── LOJ2100.cpp │ ├── LOJ2321.cpp │ ├── LOJ3097.cpp │ ├── LOJ3097TLE.cpp │ ├── LOJ569.cpp │ ├── LOJ6008.cpp │ ├── LOJ6014.cpp │ ├── LOJ6045.cpp │ ├── LOJ6511.cpp │ ├── LOJ6511E.cpp │ ├── POJ2175.cpp │ ├── POJ3469.cpp │ ├── UVA10480.cpp │ ├── bzoj1066.cpp │ ├── bzoj1189.cpp │ ├── bzoj1532.cpp │ ├── bzoj2163.cpp │ ├── bzoj2288.cpp │ ├── bzoj2864.cpp │ └── bzoj4439.cpp ├── Number Theory │ ├── 3307.cpp │ ├── 3579.cpp │ ├── 4549.cpp │ ├── LOJ161.cpp │ ├── LOJ2544.cpp │ ├── LOJ6053.cpp │ ├── LOJ6241.cpp │ ├── PE484.cpp │ ├── PE639.cpp │ ├── UVA756.cpp │ ├── bzoj2705.cpp │ ├── bzoj2813.cpp │ ├── bzoj3529.cpp │ ├── bzoj3529B.cpp │ ├── bzoj3884.cpp │ ├── bzoj3994.cpp │ ├── bzoj4407.cpp │ └── bzoj4454.cpp ├── OldDriverTree │ └── CF896C.cpp ├── Optmize │ ├── 3980.cpp │ ├── LOJ2671.cpp │ ├── bzoj2428.cpp │ ├── bzoj3112A.cpp │ ├── bzoj3112B.cpp │ ├── bzoj3550.cpp │ ├── bzoj3680.cpp │ └── bzoj3680GD.cpp ├── Other │ ├── CF1060H.cpp │ └── CF1060HChecker.cpp ├── PAM │ ├── BZOJ2565.cpp │ └── SPOJNUMOFVAL.cpp ├── Partition │ ├── LOJ2049.cpp │ ├── LOJ534.cpp │ ├── LOJ6198.cpp │ ├── P4755.cpp │ ├── UVA1608.cpp │ ├── bzoj2527.cpp │ ├── bzoj2738.cpp │ └── bzoj2738SL.cpp ├── Point-Based Partition │ ├── 2056.cpp │ ├── 2664.cpp │ ├── 3345.cpp │ ├── 3676.cpp │ ├── 3727A.cpp │ ├── 3727B.cpp │ ├── 3727SGA.cpp │ ├── 4115.cpp │ ├── 4115Old.cpp │ ├── 4115queue.cpp │ ├── 4149.cpp │ ├── 4292A.cpp │ ├── 4292B.cpp │ ├── 4292C.cpp │ ├── CF100570F.cpp │ ├── LOJ2013.cpp │ ├── LOJ2065A.cpp │ ├── LOJ2065B.cpp │ ├── LOJ2179.cpp │ ├── LOJ2259.cpp │ ├── QTree5.cpp │ ├── bzoj3730.cpp │ ├── bzoj4182.cpp │ ├── bzoj4543WA.cpp │ └── bzoj4675.cpp ├── Probability │ ├── 1297.cpp │ ├── 3211.cpp │ └── 3600.cpp ├── ProjectEulerEasy │ ├── PE1.cpp │ ├── PE10.cpp │ ├── PE11.cpp │ ├── PE12.cpp │ ├── PE13.cpp │ ├── PE14.cpp │ ├── PE15.cpp │ ├── PE16.cpp │ ├── PE17.cpp │ ├── PE18.cpp │ ├── PE2.cpp │ ├── PE20.cpp │ ├── PE21.cpp │ ├── PE22.cpp │ ├── PE23.cpp │ ├── PE24.cpp │ ├── PE25.cpp │ ├── PE26.cpp │ ├── PE27.cpp │ ├── PE28.cpp │ ├── PE29.cpp │ ├── PE3.cpp │ ├── PE30.cpp │ ├── PE31.cpp │ ├── PE32.cpp │ ├── PE33.cpp │ ├── PE34.cpp │ ├── PE35.cpp │ ├── PE36.cpp │ ├── PE37.cpp │ ├── PE38.cpp │ ├── PE39.cpp │ ├── PE4.cpp │ ├── PE40.cpp │ ├── PE41.cpp │ ├── PE42.cpp │ ├── PE43.cpp │ ├── PE44.cpp │ ├── PE45.cpp │ ├── PE46.cpp │ ├── PE47.cpp │ ├── PE48.cpp │ ├── PE49.cpp │ ├── PE5.cpp │ ├── PE50.cpp │ ├── PE51.cpp │ ├── PE53.cpp │ ├── PE6.cpp │ ├── PE7.cpp │ ├── PE8.cpp │ └── PE9.cpp ├── Queue │ └── 2698.cpp ├── SA │ ├── LOJ111.cpp │ ├── LOJ2059.cpp │ ├── LOJ2133.cpp │ ├── LOJ2525.cpp │ ├── LOJ6041NSqrtNlgN.cpp │ ├── SP1811.cpp │ └── bzoj4453.cpp ├── SAM │ ├── 1117.cpp │ ├── 1368.cpp │ ├── 2178.cpp │ ├── 2463.cpp │ ├── 2852.cpp │ ├── 3181.cpp │ ├── 3346.cpp │ ├── 3763.cpp │ ├── 3975.cpp │ ├── 4022.cpp │ ├── 4070.cpp │ ├── 4081.cpp │ ├── 4094.cpp │ ├── 4248.cpp │ ├── 4770.cpp │ ├── BZOJ2780.cpp │ ├── BZOJ3277.cpp │ ├── CF235C.cpp │ ├── LOJ2033.cpp │ ├── LOJ2059.cpp │ ├── LOJ2064.cpp │ ├── LOJ2064X.cpp │ ├── LOJ2172.cpp │ ├── LOJ2377.cpp │ ├── LOJ2720lg.cpp │ ├── LOJ2720sqrt.cpp │ ├── LOJ6031.cpp │ ├── LOJ6041.cpp │ ├── LOJ6198.cpp │ ├── SP8222.cpp │ ├── bzoj2555.cpp │ └── bzoj4545.cpp ├── SSSP │ └── BZOJ2622&2617.cpp ├── Search │ ├── 2324.cpp │ └── LOJ10022.cpp ├── SegmentTree │ ├── 4097.cpp │ ├── 4198.cpp │ ├── 4254.cpp │ ├── 4556.cpp │ ├── 4587.cpp │ ├── 5025.cpp │ ├── BZOJ4695.cpp │ ├── CF786B.cpp │ ├── LOJ121.cpp │ ├── LOJ2032.cpp │ ├── LOJ2055.cpp │ ├── LOJ2116.cpp │ ├── LOJ6034.cpp │ ├── LOJ6057.cpp │ ├── LOJ6346.cpp │ ├── P4585.cpp │ ├── UOJ218.cpp │ ├── bzoj3073.cpp │ ├── bzoj3545.cpp │ ├── bzoj3585.cpp │ ├── bzoj4025.cpp │ ├── bzoj4311.cpp │ └── bzoj5312.cpp ├── Sieve │ ├── 1829.cpp │ ├── DIVCNT2.cpp │ ├── DIVCNT3.cpp │ ├── DIVCNTK.cpp │ ├── LOJ124A.cpp │ ├── LOJ124B.cpp │ ├── LOJ125.cpp │ ├── LOJ2085.cpp │ ├── LOJ2085Test.cpp │ ├── LOJ509Test.cpp │ ├── LOJ6027.cpp │ ├── LOJ6028.cpp │ ├── LOJ6229.cpp │ ├── LOJ6235.cpp │ └── LOJ6491.cpp ├── SpanningTree │ ├── 3280.cpp │ ├── 3280Tarjan.cpp │ └── LOJ6271.cpp ├── Splay │ └── LOJ516.cpp ├── Swap │ ├── 3207.cpp │ └── 4128.cpp ├── TopSort │ ├── 3573.cpp │ └── CF915D.cpp ├── TreeOfTree │ ├── 1527.cpp │ ├── 2617.cpp │ ├── 3242.cpp │ ├── 3248.cpp │ ├── 3380.cpp │ ├── 3759.cpp │ ├── 4093.cpp │ └── 4728.cpp ├── Trie │ ├── 3449.cpp │ ├── 3732.cpp │ ├── 4098.cpp │ ├── 4592.cpp │ └── 4735.cpp ├── Virtual Tree │ ├── 3320.cpp │ ├── 3783.cpp │ ├── 4426.cpp │ ├── CF613D.cpp │ ├── LOJ2206.cpp │ ├── LOJ2219.cpp │ └── bzoj3589.cpp ├── WQS │ ├── 2619.cpp │ ├── CF321E.cpp │ ├── CF739E.cpp │ ├── LOJ2478.cpp │ ├── bzoj3675nlg.cpp │ ├── bzoj4367.cpp │ └── bzoj5311.cpp └── ZAlgorithm │ └── P3893.cpp ├── TemplateList.md ├── Templates ├── 2-SAT.cpp ├── ACM.cpp ├── AGM.cpp ├── BSGS.cpp ├── BailliePSW.cpp ├── BerlekampMassey.cpp ├── Blossom.cpp ├── Boruvka.cpp ├── CDQ.cpp ├── CIRU.cpp ├── CST.cpp ├── Catalan.cpp ├── Cover.cpp ├── DLX.cpp ├── DinicA.cpp ├── DinicB.cpp ├── DinicC.cpp ├── DsuOnTree.cpp ├── EXCRT.cpp ├── Euclidlike.cpp ├── Evaluator.cpp ├── FDSU.cpp ├── FFT.cpp ├── FMT.cpp ├── FWT.cpp ├── GBT.cpp ├── GHT.cpp ├── HLPPA.cpp ├── HLPPB.cpp ├── HPI.cpp ├── Hall.cpp ├── ISAP.cpp ├── InvMat.cpp ├── KMP.cpp ├── LCT.cpp ├── LOJ102-zkwMCMF.cpp ├── LR.cpp ├── LUP.cpp ├── Lagrange.cpp ├── Leftist Tree.cpp ├── Link.cpp ├── MCMF.cpp ├── MCS.cpp ├── MillerRabin+PollardRho.cpp ├── NOSPFA.cpp ├── NTT.cpp ├── Nearest.cpp ├── NegRing.cpp ├── PAM.cpp ├── PBD.cpp ├── PairingHeap.cpp ├── PhiMuSum.cpp ├── PohligHellman.cpp ├── PollardRhoDL.cpp ├── QuickHull2D.cpp ├── QuickHull3D.cpp ├── Rotate.cpp ├── SA.cpp ├── SAM.cpp ├── SAM2SA.cpp ├── SSKTP.cpp ├── SimplexSLP.cpp ├── Splay.cpp ├── Stoer-Wagner.cpp ├── Stoer-WagnerV3.cpp ├── TDDP.cpp ├── TMD.cpp ├── Taylor.cpp ├── TreeDivide.cpp ├── TreeHash.cpp ├── UOJ179-Simplex.cpp ├── UOJ179.py ├── VirtualTree.cpp ├── ZAlgorithm.cpp ├── exBSGS.cpp ├── fhqtreap.cpp └── min_25.cpp ├── Test ├── AGMTest.cpp ├── ArgTest.cpp ├── BitTest.cpp ├── LOJ118.cpp ├── LocaleTest.cpp ├── MulTest.cpp ├── PreDivTest.cpp ├── RegexTest.cpp ├── SieveTest.cpp ├── StatusError.cpp └── strtodTest.cpp ├── Unclassified ├── Done │ ├── 3640 │ │ ├── Task3Codes.zip │ │ ├── bin │ │ │ ├── FloydWarshall.cppx │ │ │ ├── Gamble1.cppx │ │ │ ├── Gamble2.cppx │ │ │ ├── ModifiedDijkstra.cppx │ │ │ ├── OptimizedBellmanFord.cppx │ │ │ └── RecursiveBacktracking.cppx │ │ ├── checker.cpp │ │ ├── data │ │ │ ├── 1.txt │ │ │ ├── 2.txt │ │ │ ├── 3.txt │ │ │ ├── 4.txt │ │ │ ├── 5.txt │ │ │ ├── 6.txt │ │ │ ├── 7.txt │ │ │ ├── 8.txt │ │ │ ├── Dijkstra.cpp │ │ │ ├── Floyd.cpp │ │ │ ├── Gamble.cpp │ │ │ ├── SPFA.cpp │ │ │ ├── SPFA2.cpp │ │ │ └── args.txt │ │ └── tmp.txt │ ├── 4137 │ │ ├── 4137.cpp │ │ ├── 4137gen.cpp │ │ └── 4137std.cpp │ ├── 4639 │ │ ├── 4639.cpp │ │ └── compile.bat │ ├── 1004.cpp │ ├── 1005.cpp │ ├── 1006.cpp │ ├── 1024.cpp │ ├── 1027.cpp │ ├── 1041.cpp │ ├── 1049.cpp │ ├── 1054.cpp │ ├── 1057.cpp │ ├── 1064.cpp │ ├── 1070.cpp │ ├── 1072.cpp │ ├── 1073.cpp │ ├── 1076.cpp │ ├── 1077.cpp │ ├── 1078.cpp │ ├── 1108.cpp │ ├── 1110.cpp │ ├── 1111.cpp │ ├── 1113.cpp │ ├── 1114.cpp │ ├── 1119.cpp │ ├── 1120.cpp │ ├── 1122.cpp │ ├── 1128.cpp │ ├── 1129.cpp │ ├── 1131.cpp │ ├── 1134.cpp │ ├── 1137.cpp │ ├── 1144.cpp │ ├── 1155.cpp │ ├── 1155old.cpp │ ├── 1156.cpp │ ├── 1158.cpp │ ├── 1159.cpp │ ├── 1169.cpp │ ├── 1171.cpp │ ├── 1175.cpp │ ├── 1176.cpp │ ├── 1182.cpp │ ├── 1183.cpp │ ├── 1186.cpp │ ├── 1191.cpp │ ├── 1194.cpp │ ├── 1195.cpp │ ├── 1196.cpp │ ├── 1197.cpp │ ├── 1220.cpp │ ├── 1224.cpp │ ├── 1231.cpp │ ├── 1232.cpp │ ├── 1251.cpp │ ├── 1260.cpp │ ├── 1262.cpp │ ├── 1265.cpp │ ├── 1266.cpp │ ├── 1273.cpp │ ├── 1282.cpp │ ├── 1284.cpp │ ├── 1295.cpp │ ├── 1297.cpp │ ├── 1309.cpp │ ├── 1323.cpp │ ├── 1333.cpp │ ├── 1336.cpp │ ├── 1337.cpp │ ├── 1339.cpp │ ├── 1342.cpp │ ├── 1343.cpp │ ├── 1344.cpp │ ├── 1346.cpp │ ├── 1352.cpp │ ├── 1354.cpp │ ├── 1355.cpp │ ├── 1356.cpp │ ├── 1377.cpp │ ├── 1390.cpp │ ├── 1392.cpp │ ├── 1394.cpp │ ├── 1396.cpp │ ├── 1397.cpp │ ├── 1397old.cpp │ ├── 1401.cpp │ ├── 1402.cpp │ ├── 1407.cpp │ ├── 1412.cpp │ ├── 1414.cpp │ ├── 1417.cpp │ ├── 1419.cpp │ ├── 1430.cpp │ ├── 1437.cpp │ ├── 1440.cpp │ ├── 1445.cpp │ ├── 1446.cpp │ ├── 1447.cpp │ ├── 1450.cpp │ ├── 1462.cpp │ ├── 1463.cpp │ ├── 1466.cpp │ ├── 1472.cpp │ ├── 1483.cpp │ ├── 1486.cpp │ ├── 1491.cpp │ ├── 1494.cpp │ ├── 1499.cpp │ ├── 1499WA40.cpp │ ├── 1502.cpp │ ├── 1503.cpp │ ├── 1511.cpp │ ├── 1513.cpp │ ├── 1514.cpp │ ├── 1516.cpp │ ├── 1525.cpp │ ├── 1529.cpp │ ├── 1530.cpp │ ├── 1537.cpp │ ├── 1542.cpp │ ├── 1546.cpp │ ├── 1550.cpp │ ├── 1552.cpp │ ├── 1552TLE.cpp │ ├── 1559.cpp │ ├── 1564.cpp │ ├── 1565.cpp │ ├── 1576.cpp │ ├── 1592.cpp │ ├── 1602.cpp │ ├── 1608.cpp │ ├── 1613.cpp │ ├── 1621.cpp │ ├── 1625.cpp │ ├── 1630.cpp │ ├── 1631.cpp │ ├── 1637.cpp │ ├── 1638.cpp │ ├── 1640.cpp │ ├── 1641.cpp │ ├── 1645.cpp │ ├── 1650.cpp │ ├── 1653.cpp │ ├── 1656.cpp │ ├── 1659.cpp │ ├── 1712.cpp │ ├── 1714.cpp │ ├── 1715.cpp │ ├── 1730.cpp │ ├── 1737.cpp │ ├── 1748.cpp │ ├── 1767.cpp │ ├── 1769.cpp │ ├── 1772.cpp │ ├── 1773.cpp │ ├── 1776.cpp │ ├── 1782.cpp │ ├── 1783.cpp │ ├── 1801.cpp │ ├── 1835.cpp │ ├── 1840.cpp │ ├── 1841.cpp │ ├── 1842.cpp │ ├── 1852.cpp │ ├── 1854.cpp │ ├── 1856.cpp │ ├── 1873.cpp │ ├── 1875.cpp │ ├── 1878.cpp │ ├── 1879.cpp │ ├── 1880.cpp │ ├── 1890.cpp │ ├── 1892.cpp │ ├── 1896.cpp │ ├── 1901.cpp │ ├── 1903.cpp │ ├── 1938.cpp │ ├── 1948.cpp │ ├── 1954.cpp │ ├── 1971.cpp │ ├── 1973.cpp │ ├── 1975.cpp │ ├── 1975.cpp~ │ ├── 1982.cpp │ ├── 1983.cpp │ ├── 1991.cpp │ ├── 1995.cpp │ ├── 1995old.cpp │ ├── 2002.cpp │ ├── 2003.cpp │ ├── 2015.cpp │ ├── 2016.cpp │ ├── 2024.cpp │ ├── 2032.cpp │ ├── 2034.cpp │ ├── 2042.cpp │ ├── 2044.cpp │ ├── 2047.cpp │ ├── 2048.cpp │ ├── 2050.cpp │ ├── 2052.cpp │ ├── 2053.cpp │ ├── 2054.cpp │ ├── 2055.cpp │ ├── 2059.cpp │ ├── 2060.cpp │ ├── 2061.cpp │ ├── 2062.cpp │ ├── 2065.cpp │ ├── 20652.cpp │ ├── 2070.cpp │ ├── 2071.cpp │ ├── 2082.cpp │ ├── 2085.cpp │ ├── 2086.cpp │ ├── 2086WA.cpp │ ├── 2086WA2.cpp │ ├── 2094.cpp │ ├── 2107.cpp │ ├── 2109.cpp │ ├── 2114.cpp │ ├── 2115.cpp │ ├── 2144.cpp │ ├── 2146.cpp │ ├── 2147.cpp │ ├── 2148.cpp │ ├── 2148table.cpp │ ├── 2149.cpp │ ├── 2151.cpp │ ├── 2153.cpp │ ├── 2154.cpp │ ├── 2155.cpp │ ├── 2157.cpp │ ├── 2170.cpp │ ├── 2176.cpp │ ├── 2183.cpp │ ├── 2184.cpp │ ├── 2205.cpp │ ├── 2207.cpp │ ├── 2212.cpp │ ├── 2214.cpp │ ├── 2215.cpp │ ├── 2216.cpp │ ├── 2219.cpp │ ├── 2220.cpp │ ├── 2221.cpp │ ├── 2246.cpp │ ├── 2247.cpp │ ├── 2253.cpp │ ├── 2255.cpp │ ├── 2260.cpp │ ├── 2261.cpp │ ├── 2279.cpp │ ├── 2285.cpp │ ├── 2286.cpp │ ├── 2290.cpp │ ├── 2292.cpp │ ├── 2294.cpp │ ├── 2303.cpp │ ├── 2305.cpp │ ├── 2318.cpp │ ├── 2320.cpp │ ├── 2323.cpp │ ├── 2327.cpp │ ├── 2336.cpp │ ├── 2338.cpp │ ├── 2341.cpp │ ├── 2342.cpp │ ├── 2344.cpp │ ├── 2345.cpp │ ├── 2350.cpp │ ├── 2354.cpp │ ├── 2357.cpp │ ├── 2358.cpp │ ├── 2359.cpp │ ├── 2367.cpp │ ├── 2388.cpp │ ├── 2391.cpp │ ├── 2394.cpp │ ├── 2397.cpp │ ├── 2398.cpp │ ├── 2401.cpp │ ├── 2402.cpp │ ├── 2403.cpp │ ├── 2412.cpp │ ├── 2414.cpp │ ├── 2414TLE.cpp │ ├── 2417.cpp │ ├── 2420.cpp │ ├── 2422.cpp │ ├── 2446.cpp │ ├── 2448.cpp │ ├── 2461.cpp │ ├── 2464.cpp │ ├── 2464TLE.cpp │ ├── 2467.cpp │ ├── 2468.cpp │ ├── 2468WA20.cpp │ ├── 2469.cpp │ ├── 2470.cpp │ ├── 2471.cpp │ ├── 2472.cpp │ ├── 2473.cpp │ ├── 2474.cpp │ ├── 2475.cpp │ ├── 2476.cpp │ ├── 2480.cpp │ ├── 2483.cpp │ ├── 2484.cpp │ ├── 2485.cpp │ ├── 2486.cpp │ ├── 2487.cpp │ ├── 2489.cpp │ ├── 2490.cpp │ ├── 2491.cpp │ ├── 2495.cpp │ ├── 2496Unknown.cpp │ ├── 2498.cpp │ ├── 2501.cpp │ ├── 2502.cpp │ ├── 2503.cpp │ ├── 2505.cpp │ ├── 2508.cpp │ ├── 2509.cpp │ ├── 2511.cpp │ ├── 2512.cpp │ ├── 2513.cpp │ ├── 25132.cpp │ ├── 2515.cpp │ ├── 2518.cpp │ ├── 2519.cpp │ ├── 2520.cpp │ ├── 2521.cpp │ ├── 2522.cpp │ ├── 25222.cpp │ ├── 2555.cpp │ ├── 2564.cpp │ ├── 2567.cpp │ ├── 2568.cpp │ ├── 2568tmp.cpp │ ├── 2569.cpp │ ├── 2569t.cpp │ ├── 2571.cpp │ ├── 2572.cpp │ ├── 2577.cpp │ ├── 2585.cpp │ ├── 2590.cpp │ ├── 2592.cpp │ ├── 2594.cpp │ ├── 2597.cpp │ ├── 2598.cpp │ ├── 2599.cpp │ ├── 2601.cpp │ ├── 2601TLE.cpp │ ├── 2602.cpp │ ├── 2604.cpp │ ├── 2605.cpp │ ├── 2607.cpp │ ├── 2609.cpp │ ├── 2610.cpp │ ├── 2613.cpp │ ├── 2613B.cpp │ ├── 2618.cpp │ ├── 2622.cpp │ ├── 2624'.cpp │ ├── 2624.cpp │ ├── 2625.cpp │ ├── 2629.cpp │ ├── 2633.cpp │ ├── 2633TLE.cpp │ ├── 2634.cpp │ ├── 2654.cpp │ ├── 2657.cpp │ ├── 2667.cpp │ ├── 2700.cpp │ ├── 2704.cpp │ ├── 2717.cpp │ ├── 2731.cpp │ ├── 2734.cpp │ ├── 2738.cpp │ ├── 2740.cpp │ ├── 2746.cpp │ ├── 2747.cpp │ ├── 2751.cpp │ ├── 2756.cpp │ ├── 2759.cpp │ ├── 2765.cpp │ ├── 2777.cpp │ ├── 2805.cpp │ ├── 2824.cpp │ ├── 2825.cpp │ ├── 2831.cpp │ ├── 2832.cpp │ ├── 2835.cpp │ ├── 2842.cpp │ ├── 2846.cpp │ ├── 2851.cpp │ ├── 2853.cpp │ ├── 2872.cpp │ ├── 2879.cpp │ ├── 2880.cpp │ ├── 2882.cpp │ ├── 2888.cpp │ ├── 2894.cpp │ ├── 2912.cpp │ ├── 2915.cpp │ ├── 2966.cpp │ ├── 2982.cpp │ ├── 2986.cpp │ ├── 3003.cpp │ ├── 3008.cpp │ ├── 3026.cpp │ ├── 3038.cpp │ ├── 3038ac.cpp │ ├── 3045.cpp │ ├── 3047.cpp │ ├── 3048.cpp │ ├── 3071.cpp │ ├── 3080.cpp │ ├── 3084.cpp │ ├── 3092.cpp │ ├── 3093.cpp │ ├── 30932.cpp │ ├── 3106.cpp │ ├── 3110.cpp │ ├── 3112.cpp │ ├── 3114.cpp │ ├── 3118.cpp │ ├── 3118WA.cpp │ ├── 3128.cpp │ ├── 3147.cpp │ ├── 3152.cpp │ ├── 3153.cpp │ ├── 3157.cpp │ ├── 3159.cpp │ ├── 3166.cpp │ ├── 3168.cpp │ ├── 3171.cpp │ ├── 3172.cpp │ ├── 3174.cpp │ ├── 3177.cpp │ ├── 3178.cpp │ ├── 3195.cpp │ ├── 3197.cpp │ ├── 3199.cpp │ ├── 3201.cpp │ ├── 3203.cpp │ ├── 3205.cpp │ ├── 3214.cpp │ ├── 3214dp.cpp │ ├── 3214test.cpp │ ├── 3222.cpp │ ├── 3222WA80.cpp │ ├── 3224.cpp │ ├── 3224TLE.cpp │ ├── 3225.cpp │ ├── 3227.cpp │ ├── 3228.cpp │ ├── 3231.cpp │ ├── 3231WA.cpp │ ├── 3232.cpp │ ├── 3233.cpp │ ├── 3233old.cpp │ ├── 3238.cpp │ ├── 3246.cpp │ ├── 3250.cpp │ ├── 3258.cpp │ ├── 3261.cpp │ ├── 3264.cpp │ ├── 3265.cpp │ ├── 3267.cpp │ ├── 3268.cpp │ ├── 3273.cpp │ ├── 3273WA.cpp │ ├── 3275.cpp │ ├── 3279.cpp │ ├── 3281.cpp │ ├── 3292.cpp │ ├── 3293.cpp │ ├── 3294.cpp │ ├── 3295.cpp │ ├── 3302.cpp │ ├── 3304.cpp │ ├── 3305.cpp │ ├── 3306.cpp │ ├── 3309.cpp │ ├── 3311.cpp │ ├── 3312.cpp │ ├── 3313.cpp │ ├── 3317.cpp │ ├── 3324.cpp │ ├── 3327.cpp │ ├── 3332.cpp │ ├── 3336.cpp │ ├── 3343.cpp │ ├── 3353.cpp │ ├── 3369.cpp │ ├── 3377.cpp │ ├── 3384.cpp │ ├── 3389.cpp │ ├── 3391.cpp │ ├── 3393.cpp │ ├── 3398.cpp │ ├── 3402.cpp │ ├── 3402TLE.cpp │ ├── 3404.cpp │ ├── 3411.cpp │ ├── 3414.cpp │ ├── 3498.cpp │ ├── 3522.cpp │ ├── 3531.cpp │ ├── 3565.cpp │ ├── 3567.cpp │ ├── 3605.cpp │ ├── 3609.cpp │ ├── 3619.cpp │ ├── 3620.cpp │ ├── 3621.cpp │ ├── 3627.cpp │ ├── 3628.cpp │ ├── 3642.cpp │ ├── 3642WA30.cpp │ ├── 3642err.cpp │ ├── 3643-WA.cpp │ ├── 3643.cpp │ ├── 3644.cpp │ ├── 3644WA55.cpp │ ├── 3648.cpp │ ├── 3653.cpp │ ├── 3659.cpp │ ├── 3660.cpp │ ├── 3661.cpp │ ├── 3662.cpp │ ├── 3663.cpp │ ├── 3672.cpp │ ├── 3674.cpp │ ├── 3676TLE.cpp │ ├── 3688.cpp │ ├── 3690TLE.cpp │ ├── 3698.cpp │ ├── 3702.cpp │ ├── 3704.cpp │ ├── 3704TLE60.cpp │ ├── 3705.cpp │ ├── 3706.cpp │ ├── 3706RE60.cpp │ ├── 3706SparseMatrix40.cpp │ ├── 3707.cpp │ ├── 3708.cpp │ ├── 3719.cpp │ ├── 3740.cpp │ ├── 3745.cpp │ ├── 3746.cpp │ ├── 3746mat.cpp │ ├── 3747.cpp │ ├── 3749.cpp │ ├── 3750.cpp │ ├── 3752.cpp │ ├── 3755.cpp │ ├── 3758.cpp │ ├── 3760.cpp │ ├── 3768-WA60.cpp │ ├── 3768.cpp │ ├── 3773.cpp │ ├── 3806.cpp │ ├── 3813.cpp │ ├── 3819.cpp │ ├── 3822.cpp │ ├── 3823.cpp │ ├── 3825.cpp │ ├── 3829.cpp │ ├── 3830.cpp │ ├── 3833.cpp │ ├── 3842.cpp │ ├── 3868.cpp │ ├── 3871.cpp │ ├── 3879.cpp │ ├── 3880.cpp │ ├── 3899.cpp │ ├── 3899WA36.cpp │ ├── 3901.cpp │ ├── 3902.cpp │ ├── 3904.cpp │ ├── 3908.cpp │ ├── 3908test.cpp │ ├── 3909.cpp │ ├── 3913.cpp │ ├── 3914.cpp │ ├── 3916.cpp │ ├── 3917.cpp │ ├── 3927.cpp │ ├── 3929.cpp │ ├── 3931.cpp │ ├── 3932.cpp │ ├── 3935.cpp │ ├── 3938.cpp │ ├── 3939.cpp │ ├── 3941.cpp │ ├── 3942.cpp │ ├── 3948.cpp │ ├── 3950.cpp │ ├── 3953.cpp │ ├── 3959.cpp │ ├── 3960.cpp │ ├── 3964.cpp │ ├── 3965.cpp │ ├── 3966.cpp │ ├── 39662.cpp │ ├── 3970.cpp │ ├── 3974.cpp │ ├── 3978.cpp │ ├── 3997.cpp │ ├── 3997WA.cpp │ ├── 3998.cpp │ ├── 4000.cpp │ ├── 4000test.cpp │ ├── 4001.cpp │ ├── 4008.cpp │ ├── 4027WA.cpp │ ├── 4031.cpp │ ├── 4032MLE.cpp │ ├── 4054.cpp │ ├── 4060.cpp │ ├── 4064.cpp │ ├── 4064overflow20.cpp │ ├── 4070TLE.cpp │ ├── 4071.cpp │ ├── 4072.cpp │ ├── 4072TLE60.cpp │ ├── 4092.cpp │ ├── 4101.cpp │ ├── 4113.cpp │ ├── 4114.cpp │ ├── 4116.cpp │ ├── 4124.cpp │ ├── 4126.cpp │ ├── 4130.cpp │ ├── 4131.cpp │ ├── 4151.cpp │ ├── 4155.cpp │ ├── 4180.cpp │ ├── 4180WA20.cpp │ ├── 4207.cpp │ ├── 4208.cpp │ ├── 4211.cpp │ ├── 4216.cpp │ ├── 4219.cpp │ ├── 4219TLE50.cpp │ ├── 4247.cpp │ ├── 4250.cpp │ ├── 4251.cpp │ ├── 4284.cpp │ ├── 4301.cpp │ ├── 4306.cpp │ ├── 4322.cpp │ ├── 4336.cpp │ ├── 4340.cpp │ ├── 4358.cpp │ ├── 4361.cpp │ ├── 4363.cpp │ ├── 4363AlphaBeta.cpp │ ├── 4364.cpp │ ├── 4404.cpp │ ├── 4424.cpp │ ├── 4427Delta.cpp │ ├── 4427TA.cpp │ ├── 4454.cpp │ ├── 4455.cpp │ ├── 4456.cpp │ ├── 4457.cpp │ ├── 4458.cpp │ ├── 4458Area.cpp │ ├── 4458gen.cpp │ ├── 4462.cpp │ ├── 4482HashWrong.cpp │ ├── 4503.cpp │ ├── 4526.cpp │ ├── 4564.cpp │ ├── 4578.cpp │ ├── 4602.cpp │ ├── 4620.cpp │ ├── 4631.cpp │ ├── 4724.cpp │ ├── 4735.cpp │ ├── 4768.cpp │ ├── 4774.cpp │ ├── 4820.cpp │ ├── BST │ │ └── BST.cpp │ ├── CF915E.cpp │ ├── CF920F.cpp │ ├── FFT.cpp │ ├── FJ-0527 │ │ ├── cheese │ │ │ └── cheese.cpp │ │ ├── complexity │ │ │ └── complexity.cpp │ │ ├── math │ │ │ └── math.cpp │ │ ├── park │ │ │ └── park.cpp │ │ ├── phalanx │ │ │ └── phalanx.cpp │ │ └── treasure │ │ │ └── treasure.cpp │ ├── Fib │ │ ├── Fib.cpp │ │ └── mat.txt │ ├── Fib2 │ │ └── Fib2.cpp │ ├── KMP │ │ └── kmp.cpp │ ├── LAN.cpp │ ├── SA │ │ └── SA.cpp │ ├── SAM.cpp │ ├── TA.cpp │ ├── auto │ │ ├── auto.cpp │ │ └── autotmp.cpp │ ├── bintree.cpp │ ├── box │ │ └── box.cpp │ ├── building.cpp │ ├── color.cpp │ ├── compute │ │ └── main.cpp │ ├── cow.cpp │ ├── cut │ │ └── cut.cpp │ ├── cycle │ │ └── cycle.cpp │ ├── dog.cpp │ ├── drink │ │ └── drink.cpp │ ├── energy │ │ └── energy.cpp │ ├── fib.cpp │ ├── fiborial.cpp │ ├── hero │ │ └── hero.cpp │ ├── link │ │ ├── link.cpp │ │ └── link2.cpp │ ├── lucas │ │ └── lucas.cpp │ ├── manager │ │ └── manager.cpp │ ├── mat │ │ ├── mat.cpp │ │ └── mat.txt │ ├── match │ │ ├── match.cpp │ │ └── match2.cpp │ ├── mean.cpp │ ├── mean2.cpp │ ├── mod.cpp │ ├── mul.cpp │ ├── mul │ │ └── mul.cpp │ ├── nth.cpp │ ├── pair.cpp │ ├── random │ │ ├── mat.txt │ │ └── random.cpp │ ├── range │ │ ├── range.cpp │ │ └── range2.cpp │ ├── saw.cpp │ ├── seq.cpp │ ├── space.cpp │ ├── stream │ │ └── stream.cpp │ ├── string │ │ └── string.cpp │ ├── test.cpp │ ├── tree │ │ └── tree.cpp │ ├── var.cpp │ ├── weight │ │ └── weight.cpp │ ├── word │ │ └── word.cpp │ ├── words │ │ └── words.cpp │ ├── xor.cpp │ └── xor │ │ └── xor.cpp ├── ToDo.txt └── ToDo │ ├── 1335 │ ├── 1335.cpp │ └── run.bat │ ├── 3782 │ ├── 3782.cpp │ └── check.cpp │ ├── 2020.cpp │ ├── 2081.cpp │ ├── 2304.cpp │ ├── 2305.cpp │ ├── 2500.cpp │ ├── 3219.cpp │ ├── 3240.cpp │ ├── 3301.cpp │ ├── 3689.cpp │ ├── 3699.cpp │ ├── 3700.cpp │ ├── 3770.cpp │ ├── 3771C.cpp │ ├── 3772B.cpp │ ├── 3780.cpp │ ├── 4006E.cpp │ ├── 4175.cpp │ ├── 4191D.cpp │ ├── 4337.cpp │ ├── 4338.cpp │ ├── 4357.cpp │ ├── 4382.cpp │ ├── 4428.cpp │ ├── 4428test.cpp │ ├── 4429.cpp │ ├── 4463.cpp │ ├── 4463dp.cpp │ ├── 4484.cpp │ ├── 4484double.cpp │ ├── 4484test.cpp │ ├── 4492.cpp │ ├── 4501.cpp │ ├── 4501std.cpp │ ├── 4577.cpp │ ├── 4587F.cpp │ ├── 4605.cpp │ ├── 4606.cpp │ ├── 4618.cpp │ ├── 4619.cpp │ ├── 4629.cpp │ ├── 4635.cpp │ ├── 4643.cpp │ └── testdata.txt ├── keyboard.cpp ├── keyboard.md ├── readme.md └── url.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | #Binary 35 | /bin 36 | /latex 37 | *.log 38 | -------------------------------------------------------------------------------- /Checker/Checker.cpp: -------------------------------------------------------------------------------- 1 | #include "OJAdapter.hpp" 2 | #include "Platforms/Platform.hpp" 3 | #include "Runner.hpp" 4 | #include "Scanner.hpp" 5 | #include 6 | int main() { 7 | initPlatform(); 8 | std::cout.precision(2); 9 | std::cout << std::fixed; 10 | 11 | line("Checker for " CHECKER_PLATFORM " 2.9.1", 12 | '*'); 13 | std::cout << "Built at " << __TIME__ << " on " 14 | << __DATE__ << std::endl; 15 | fs::path exec = scanExec(); 16 | std::cout << "found program:" << exec << std::endl; 17 | autoRun(exec); 18 | line("", '*'); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Checker/CheckerConfig.hpp.in: -------------------------------------------------------------------------------- 1 | #define CHECKER_PLATFORM "@CMAKE_SYSTEM_NAME@" 2 | #cmakedefine USE_SYZOJTOOLS 3 | #cmakedefine USE_PERF 4 | -------------------------------------------------------------------------------- /Checker/Judger.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runner.hpp" 3 | enum class CompareMode { Text, FloatingPoint }; 4 | RunResult test(const Option& opt, const Data& data, 5 | const Timer& timer); 6 | -------------------------------------------------------------------------------- /Checker/Network.cpp: -------------------------------------------------------------------------------- 1 | #include "Network.hpp" 2 | bool download(const std::string& url, 3 | const fs::path& dst) { 4 | std::cout << "Downloading file " << url 5 | << std::endl; 6 | line("wget"); 7 | std::string cmd = "wget --dns-timeout=20 " 8 | "--connect-timeout=20 " 9 | "--read-timeout=600 " 10 | "--tries=5 -v " 11 | "--no-use-server-" 12 | "timestamps -O " + 13 | dst.string() + " " + url; 14 | std::cout << cmd << std::endl; 15 | int res = system(cmd.c_str()); 16 | line(""); 17 | return res == 0; 18 | } 19 | -------------------------------------------------------------------------------- /Checker/Network.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.hpp" 3 | bool access(const std::string& url, 4 | const std::string& name); 5 | bool download(const std::string& url, 6 | const fs::path& dst); 7 | -------------------------------------------------------------------------------- /Checker/OJAPI.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | bool loadProblemInfo(const std::string& OJ, int id, 4 | std::string& problem); 5 | -------------------------------------------------------------------------------- /Checker/OJAdapter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.hpp" 3 | #include 4 | #include 5 | class OJAdapterInfo final { 6 | private: 7 | std::string mName; 8 | std::regex mPattern; 9 | std::function mFunc; 10 | int mPriority; 11 | 12 | public: 13 | OJAdapterInfo( 14 | const std::string& name, 15 | const std::regex& pattern, 16 | const std::function& 17 | func, 18 | int priority = 0); 19 | bool match(const fs::path& exec) const; 20 | bool call(const fs::path& exec) const; 21 | std::string name() const; 22 | bool operator<(const OJAdapterInfo& rhs) const; 23 | }; 24 | void autoRun(const fs::path& exec); 25 | bool runAll(const Option& opt, 26 | const std::vector& data); 27 | -------------------------------------------------------------------------------- /Checker/Platforms/Linux/PerfAnalyzer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../Common.hpp" 3 | class PerformanceInfo { 4 | private: 5 | int64_t cacheRef, cacheMiss, branchCnt, branchMiss, 6 | cycleCnt, instCnt; 7 | 8 | public: 9 | explicit PerformanceInfo(const std::string& str); 10 | PerformanceInfo(); 11 | PerformanceInfo& 12 | operator+=(const PerformanceInfo& rhs); 13 | void report() const; 14 | }; 15 | PerformanceInfo perf(const Option& opt, 16 | const Data& data); 17 | -------------------------------------------------------------------------------- /Checker/Platforms/Linux/PlatformLinux.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../Common.hpp" 3 | std::string getCallName(long callid); 4 | -------------------------------------------------------------------------------- /Checker/Platforms/Platform.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Common.hpp" 3 | #include "../Runner.hpp" 4 | #ifdef __WIN32 5 | #include "Windows/PlatformWindows.hpp" 6 | #else 7 | #include "Linux/PerfAnalyzer.hpp" 8 | #include "Linux/PlatformLinux.hpp" 9 | #endif 10 | void initPlatform(); 11 | void reportJudgeError(const RunResult& res); 12 | int getConsoleWidth(); 13 | -------------------------------------------------------------------------------- /Checker/Scanner.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.hpp" 3 | #include 4 | std::vector 5 | scanData(const fs::path& dataPath = 6 | fs::temp_directory_path() / "data"); 7 | fs::path scanExec(); 8 | -------------------------------------------------------------------------------- /Checker/Test/CheckerTestGen.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() { 5 | int n; 6 | std::cin >> n; 7 | for(int i = 1; i <= n; ++i) { 8 | std::string str = "data/" + std::to_string(i); 9 | std::ofstream in(str + ".in"), 10 | ans(str + ".ans"); 11 | in << i << std::endl; 12 | ans << i << std::endl; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Checker/Timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Common.hpp" 3 | enum class TimeMode { allTask, perTask }; 4 | class Timer final { 5 | public: 6 | void addTask(int64_t time); 7 | bool isTLE(int64_t time) const; 8 | Timer(const Option& opt); 9 | bool isTLE() const; 10 | void report() const; 11 | int64_t remain() const; 12 | void addSample(); 13 | 14 | private: 15 | int64_t mTotTime, mMaxTime, mTimeLimit, 16 | mLocalSamples, mRemoteSamples; 17 | TimeMode mMode; 18 | fs::path mSamples; 19 | }; 20 | -------------------------------------------------------------------------------- /Review/CG/CG.tex: -------------------------------------------------------------------------------- 1 | \chapter{计算几何} 2 | \minitoc 3 | \input{CG/Base} 4 | \input{CG/Convex} 5 | \input{CG/Circle} 6 | \input{CG/HPI} 7 | \input{CG/RCA} 8 | \input{CG/Nearest} 9 | %\input{CG/Delaunay} 10 | -------------------------------------------------------------------------------- /Review/CG/HPI.tex: -------------------------------------------------------------------------------- 1 | \section{半平面交} 2 | \index{H!Half-Plane Intersection} 3 | \subsection{基本算法} 4 | 基本思路是对半平面极角排序,然后按照极角序加入半平面,同时将无效的半平面(交点 5 | 在其它半平面外)删除。这里使用双端队列实现,同时对已加入的半平面的两个端口进行 6 | 剔除。注意两半平面平行的情况,此时保留较近的半平面。注意最后要用处理两端口``交叉'' 7 | 的情况,应当使用一端直线消去另一端,然后确定首尾交点作为最后一个交点。 8 | 9 | 代码如下: 10 | \lstinputlisting{Source/Templates/HPI.cpp} 11 | 12 | 一般可将线性不等式转换为半平面,然后使用半平面交来判断是否有解/计算最优解, 13 | 除去排序后时间复杂度$O(n)$。较复杂的最优化问题应当作为线性规划问题使用单纯形算法 14 | 解决,参见第~\ref{LP}节。 15 | \subsection{线性判空集} 16 | 半平面交的时间复杂度为$O(n\lg n)$,但当只要求 17 | 半平面交是否为空集时,可以使用期望时间复杂度为$O(n)$的随机化算法。 18 | 19 | 该算法维护当前半平面交的纵坐标最高点$P$。每次{\bfseries 随机}加入新半平面$L$时, 20 | 若$P$在$L$内,则直接跳过;否则新的$P'$必然在$L$与之前的半平面的交点上,用 21 | 之前的半平面在当前直线上截出可行线段,保留最高点作为新的点$P$。 22 | 23 | 该方法源自WC2012上钟诚的讲稿《概率与随机化算法》与解轶伦的文章《随机增量算法》。 24 | -------------------------------------------------------------------------------- /Review/CG/Nearest.tex: -------------------------------------------------------------------------------- 1 | \section{平面最近点对} 2 | 平面最近点对的经典算法采用分治思想,即每次将点集分成等规模的两组, 3 | 递归求两组点内部的最近距离,然后根据返回的距离来求两组间的点的最近 4 | 距离。时间复杂度$O(n\lg n)$。 5 | 6 | 步骤如下: 7 | \begin{enumerate} 8 | \item 若点集规模$\leq 3$,直接暴力解决,避免遇到点集规模$=1$的情况; 9 | \item 将点分割为左右大小相等的点集(已预先按照$x$排序)递归求解; 10 | \item 若子区间内的最小距离为$d$,则将整个区间内的距中轴距离$\leq d$的 11 | 点加入候选集合,同时维持候选集合的点的纵坐标有序(可以$O(n)$归并), 12 | 对于每个点与$y$值差$\leq d$的点更新答案。 13 | \end{enumerate} 14 | 15 | \paragraph{时间复杂度分析} 16 | 关键在于证明对于每个点枚举的点数不超过某个常数。 17 | 18 | 由于左右子集都保证了其子集内部最近点对距离$\geq d$,使用计算步骤中所述的 19 | 简单剪枝,可以保证$2d*d$的矩形中需要检查的点最多为7个(每边最多4个,再扣除自己)。 20 | 21 | 代码如下(使用了全局最优值优化): 22 | \lstinputlisting{Source/Templates/Nearest.cpp} 23 | -------------------------------------------------------------------------------- /Review/Combinatorics/Permutation.tex: -------------------------------------------------------------------------------- 1 | \section{康托展开} 2 | \index{C!Cantor Expansion} 3 | 康托展开可用于将一个排列映射到一个自然数(在所有排列中的字典序排名,从0开始)。 4 | 5 | 排列$P$的康托展开为$\displaystyle \sum_{i=2}^n{(i-1)!a_i}$, 6 | 其中$a_i$为位置$i$后小于$P_i$的数的个数,即$\displaystyle \sum_{j=1}^{i-1}[P_i>P_j]$。 7 | 8 | 相反已知字典序排名可以将其映射到一个排列,这就是逆康托展开。首先根据排名值计算出$a$数组, 9 | 数组$a$是唯一确定的,因为$a_i (i-1)!a_i$,从前到后取模确定。 10 | 计算出数组$a$后,维护一个支持删除和询问第$k$大的数据结构,从前到后确定每一位数。 11 | -------------------------------------------------------------------------------- /Review/DP/DP.tex: -------------------------------------------------------------------------------- 1 | \chapter{动态规划} 2 | \minitoc 3 | \input{DP/Bag} 4 | \input{DP/Number} 5 | \input{DP/Link} 6 | \input{DP/Queue} 7 | \input{DP/Slope} 8 | \input{DP/Quad} 9 | \input{DP/Power} 10 | \input{DP/Dynamic} 11 | \input{DP/Mono} 12 | \input{DP/Convex} 13 | \input{DP/SDP} 14 | \section{杂记} 15 | \begin{itemize} 16 | \item 我原先写区间dp时首先枚举长度,然后枚举左端点: 17 | \begin{lstlisting} 18 | for(int len=1;len<=n;++len) 19 | for(int l=1,r=len;r<=n;++r) 20 | \end{lstlisting} 21 | 22 | 这样子长度较小的区间先于长度较大的区间dp完毕。 23 | 24 | 不过还有另一种写法: 25 | \begin{lstlisting} 26 | for(int l=n;l>=1;--l) 27 | for(int r=l;r<=n;++r) 28 | \end{lstlisting} 29 | 30 | 这种区间枚举方式代码简短,在缓存友好方面倒是没有什么优势。 31 | \end{itemize} 32 | -------------------------------------------------------------------------------- /Review/DP/Number.tex: -------------------------------------------------------------------------------- 1 | \section{数位动规} 2 | 问题一般是询问区间内数位满足指定要求的数的个数。 3 | 区间计数可转换为前缀和差分,因此原问题可转换为询问小于$n$ 4 | 的满足指定要求的数的个数。 5 | 6 | 一般思路如下: 7 | \begin{enumerate} 8 | \item 将$n$拆位为$n_k,n_{k-1},\cdots,n_1$; 9 | \item 从最低位开始dp一直做到最高位; 10 | \item 从最低位开始统计到次高位,因为这部分答案是满的; 11 | \item 从最高位开始做到最低位,假设做到第$i$位,表示处理该位以前 12 | 的位都固定为$n$,枚举当前位$j 2 | const int mod = 2147483647, p = mod - 1; 3 | typedef long long Int64; 4 | Int64 powm(Int64 a, int k) { 5 | Int64 res = 1; 6 | while(k) { 7 | if(k & 1) 8 | res = res * a % mod; 9 | k >>= 1, a = a * a % mod; 10 | } 11 | return res; 12 | } 13 | bool test(int g) { 14 | int x = p; 15 | for(int i = 2; i * i <= x; ++i) 16 | if(x % i == 0) { 17 | do 18 | x /= i; 19 | while(x % i == 0); 20 | if(powm(g, p / i) == 1) 21 | return false; 22 | } 23 | if(x != 1) 24 | return powm(g, p / x) != 1; 25 | return true; 26 | } 27 | int main() { 28 | int g; 29 | scanf("%d", &g); 30 | puts(test(g) ? "Yes" : "No"); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Review/DataStructure/RandomTestB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int getRand() { 6 | static int seed = 347; 7 | return seed = seed * 48271LL % 2147483647; 8 | } 9 | const int size = 1 << 23, pool = 1 << 10; 10 | int cnt[pool]; 11 | int main() { 12 | for(int i = 1; i <= size; ++i) 13 | ++cnt[getRand() >> 21]; 14 | int minv = 1 << 30, maxv = 0, avg = size / pool; 15 | double s2 = 0.0; 16 | for(int i = 0; i < pool; ++i) { 17 | minv = std::min(minv, cnt[i]); 18 | maxv = std::max(maxv, cnt[i]); 19 | double delta = cnt[i] - avg; 20 | s2 += delta * delta; 21 | } 22 | s2 /= pool; 23 | printf("minc=%d maxc=%d except=%d s2=%.3lf\n", 24 | minv, maxv, avg, sqrt(s2)); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Review/GameTheory/GameTheory.tex: -------------------------------------------------------------------------------- 1 | \chapter{博弈论} 2 | \minitoc 3 | \input{GameTheory/SGFunction} 4 | \input{GameTheory/Nim} 5 | \input{GameTheory/AlphaBeta} 6 | \section{本章注记} 7 | 更多博弈论模型参见~博弈游戏的各种经典模型(备忘) - Randolph87 - 博客园 8 | \url{http://www.cnblogs.com/Randolph87/p/5804798.html},待补充。 9 | \index{*TODO!补充博弈论经典模型} 10 | -------------------------------------------------------------------------------- /Review/GameTheory/NimSG.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size = 25; 4 | int SG[size]; 5 | int getSG(int x) { 6 | if(SG[x] == -1) { 7 | bool flag[size] = {}; 8 | for(int i = 0; i < x; ++i) 9 | flag[getSG(i)] = true; 10 | for(int i = 0; i <= x; ++i) 11 | if(!flag[i]) { 12 | SG[x] = i; 13 | break; 14 | } 15 | } 16 | return SG[x]; 17 | } 18 | int main() { 19 | memset(SG, -1, sizeof(SG)); 20 | for(int i = 0; i <= 20; ++i) 21 | printf("SG(%d)=%d\n", i, getSG(i)); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Review/Graph/DominatorTree.tex: -------------------------------------------------------------------------------- 1 | \section{支配树} 2 | \index{D!DominatorTree} 3 | \subsection{定义} 4 | 支配树基于某个原点$s$,若$s$到某个点$v$的节点必定经过$u$,则称$u$支配$v$。 5 | 起点$s$与自己$v$称为平凡支配点。 6 | 7 | 若$v$的某个支配点$w$满足其被$v$的其余非平凡支配点支配,则$w$为$v$的最近支配点, 8 | 记作$idom(v)=w$。每个点到自己的$idom$连边,则构造出了一棵树,称为支配树。 9 | \subsection{DAG的支配树} 10 | DAG的支配树构造较为简单。考虑按照top序加入节点,当前节点的$idom$就是其前驱节点在支配树上的LCA。 11 | 由于树的形态是固定的,使用倍增可以$O((n+m)\lg n)$实现。 12 | \subsection{一般图的支配树} 13 | 该内容留坑待补。 14 | \index{*TODO!一般图支配树} 15 | 16 | 上述内容参考了MoebiusMeow的博客\footnote{ 17 | 康复计划\#4 快速构造支配树的Lengauer-Tarjan算法\\ 18 | \url{https://www.cnblogs.com/meowww/archive/2017/02/27/6475952.html} 19 | }。 20 | -------------------------------------------------------------------------------- /Review/Graph/Graph.tex: -------------------------------------------------------------------------------- 1 | \chapter{图论} 2 | \minitoc 3 | \input{Graph/CutVertexAndBridge} 4 | \input{Graph/SCC} 5 | \input{Graph/PEBC} 6 | \input{Graph/2-SAT} 7 | \input{Graph/CST} 8 | \input{Graph/Path} 9 | \input{Graph/Chord} 10 | \input{Graph/Matching} 11 | \input{Graph/DominatorTree} 12 | \input{Graph/Other} 13 | -------------------------------------------------------------------------------- /Review/LinearAlgebra/LinearAlgebra.tex: -------------------------------------------------------------------------------- 1 | \chapter{线性代数} 2 | \minitoc 3 | \input{LinearAlgebra/Gauss} 4 | \input{LinearAlgebra/LUP} 5 | \input{LinearAlgebra/Det} 6 | \input{LinearAlgebra/Base} 7 | \input{LinearAlgebra/LeastSquares} 8 | \input{LinearAlgebra/LinearRecurrence} 9 | -------------------------------------------------------------------------------- /Review/Math/CharacteristicEquation.tex: -------------------------------------------------------------------------------- 1 | \section{特征方程} 2 | 特征方程用于推导线性递推数列的通项。 3 | 4 | 给定数列递推式$a_n=\displaystyle \sum_{i=1}^k{c_ia_{n-i}}$,以及 5 | 数列初始项$a_0,a_1,\cdots,a_{k-1}$,求$a_n$。 6 | 7 | 虽然求$a_n$可以使用矩阵快速幂或者常系数项齐次线性递推解决,但是像「JLOI2015」 8 | 有意义的字符串这类涉及取整的题目,它们毫无办法。因此研究$a_n$的通项并且利用其中 9 | 的性质十分重要。 10 | 11 | 首先将递推式改写为特征方程$x^k=\displaystyle \sum_{i=1}^k{c_ix^{k-i}}$,然后 12 | 求出它的根$x_1,x_2,\cdots,x_k$,那么$a_n$就是这些根$n$次幂的线性加权和。 13 | 带入前$k$项求出系数就可以得到通项。 14 | 15 | 注意以下特殊情况: 16 | \begin{itemize} 17 | \item 重根:若根$x$重复$b$次,则其系数为$\displaystyle \sum_{i=0}^{b-1}{f_in^i}$ 18 | 的形式。 19 | \item 复根:若$r$为复根,将$r$表示为$se^{\omega i}$的形式,将$r^k$拆为 20 | $s^k\cos k\omega+is^k\sin k\omega$,实部和虚部都是合法的实根。 21 | \end{itemize} 22 | 23 | \index{*TODO!特征方程相关证明} 24 | -------------------------------------------------------------------------------- /Review/Math/Math.tex: -------------------------------------------------------------------------------- 1 | \chapter{数学杂项} 2 | \minitoc 3 | \input{Math/Taylor} 4 | \input{Math/Simpson} 5 | \input{Math/Probability} 6 | \input{Math/GeneratingFunction} 7 | \input{Math/LIP} 8 | \input{Math/Inversion} 9 | \input{Math/Equation} 10 | \input{Math/LinearIP} 11 | \input{Math/BerlekampMassey} 12 | \input{Math/GeneratingGraph} 13 | \input{Math/CharacteristicEquation} 14 | -------------------------------------------------------------------------------- /Review/Math/Taylor.tex: -------------------------------------------------------------------------------- 1 | \section{泰勒级数展开} 2 | \index{T!Taylor Series} 3 | \subsection{形式} 4 | 函数$f$在点$a$上的泰勒级数展开为 5 | \begin{displaymath} 6 | \sum_{n=0}^\infty{\frac{f^{(n)}(a)}{n!}(x-a)^n} 7 | \end{displaymath} 8 | \index{M!Maclaurin Series} 9 | $a=0$时称为麦克劳林级数。 10 | \subsection{常见泰勒级数展开} 11 | 通常使用麦克劳林级数推导。 12 | \begin{eqnarray*} 13 | e^x&=&\sum_{n=0}^\infty{\frac{x^n}{n!}}\\ 14 | \ln(1-x)&=&-\sum_{n=1}^\infty{\frac{x^n}{n}} \textrm{~for all $|x|<1$}\\ 15 | \frac{1}{1-x}&=&\sum_{n=0}^\infty{x^n}\\ 16 | \frac{1}{(1-x)^k}&=&\sum_{n=0}^\infty{(x^n)^{(k)}}\\ 17 | (1+x)^\alpha&=&\sum_{n=0}^\infty{\binomial{\alpha}{n}x^n}\\ 18 | \sin(x)&=&\sum_{n=0}^\infty{\frac{(-1)^n}{(2n+1)!}x^{2n+1}}\\ 19 | \cos(x)&=&\sum_{n=0}^\infty{\frac{(-1)^n}{(2n)!}x^{2n}}\\ 20 | \end{eqnarray*} 21 | -------------------------------------------------------------------------------- /Review/MathSymbol.tex: -------------------------------------------------------------------------------- 1 | \newtheorem{theorem}{定理}[chapter] 2 | \newtheorem{lemma}[theorem]{引理} 3 | \newtheorem{property}[theorem]{性质} 4 | \newtheorem{inference}[theorem]{推论} 5 | \newcommand{\ud}{\textrm{d}} 6 | \newcommand{\binomial}[2]{\left(#1 \atop #2\right)} 7 | \newcommand{\stirlingA}[2]{\left[#1 \atop #2\right]} 8 | \newcommand{\stirlingB}[2]{\left\{#1 \atop #2\right\}} 9 | \newcommand{\Legendre}[2]{\left(\frac{#1}{#2}\right)} 10 | \newcommand{\Jacobi}[2]{\left(\frac{#1}{#2}\right)} 11 | -------------------------------------------------------------------------------- /Review/NetworkFlows/NetworkFlows.tex: -------------------------------------------------------------------------------- 1 | \chapter{网络流} 2 | \minitoc 3 | \input{NetworkFlows/BipartiteGraph} 4 | \input{NetworkFlows/MaxFlow} 5 | \input{NetworkFlows/MCMF} 6 | \input{NetworkFlows/LimitedNetworkFlows} 7 | \input{NetworkFlows/Models} 8 | \input{NetworkFlows/Gomory-HuTree} 9 | \input{NetworkFlows/Tricks} 10 | -------------------------------------------------------------------------------- /Review/NumberTheory/NumberTheory.tex: -------------------------------------------------------------------------------- 1 | \chapter{数论} 2 | \minitoc 3 | \input{NumberTheory/GCD} 4 | \input{NumberTheory/Euler} 5 | \input{NumberTheory/PrimalityTest} 6 | \input{NumberTheory/PollardRho} 7 | \input{NumberTheory/RSA} 8 | \input{NumberTheory/CRT} 9 | \input{NumberTheory/MultiplicativeFunction} 10 | \input{NumberTheory/Dirichlet} 11 | \input{NumberTheory/Sieve} 12 | \input{NumberTheory/DiscreteLogarithm} 13 | \input{NumberTheory/PrimitiveRoot} 14 | \input{NumberTheory/Residue} 15 | \input{NumberTheory/Euclidlike} 16 | -------------------------------------------------------------------------------- /Review/Optmize/GD.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | typedef double FT; 4 | const FT p = 1e-12, g = 1e-3; 5 | const int maxStep = 1 << 20; 6 | FT f(FT x) { 7 | return (x - 3.0) * x * x * x + 2.0; 8 | } 9 | FT df(FT x) { 10 | return (4.0 * x - 9.0) * x * x; 11 | } 12 | int main() { 13 | FT cur = 6.0; 14 | int step; 15 | for(step = 0; step < maxStep; ++step) { 16 | FT delta = -g * df(cur); 17 | cur += delta; 18 | if(fabs(delta) < p) 19 | break; 20 | } 21 | printf("step=%d res=(%.12lf,%.12lf)\n", step, cur, 22 | f(cur)); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Review/Optmize/Optmize.tex: -------------------------------------------------------------------------------- 1 | \chapter{最优化问题} 2 | \minitoc 3 | \input{Optmize/OptmizeMethod} 4 | \input{Optmize/FP} 5 | \input{Optmize/LP} 6 | \input{Optmize/Random} 7 | -------------------------------------------------------------------------------- /Review/Optmize/Random.tex: -------------------------------------------------------------------------------- 1 | \section{随机化算法} 2 | 随机化算法一般用来解决判定性问题与最优化问题。 3 | \subsection{Monte Carlo算法} 4 | \subsubsection{有关枚举元素的问题} 5 | 该问题需要枚举每个子集,然后对单个枚举进行计算。 6 | 7 | 对于这种问题我们有复杂度无法接受的穷举法,将穷举改为随机选取固定次数 8 | 的子集,可以在规定时间内完成计算。 9 | 10 | 使用一些贪心技巧或利用题目性质可以提高单次枚举正确率与采样数。 11 | \subsubsection{线性加权和问题} 12 | 每次随机生成一个权重向量与向量做内积/与矩阵做乘法。 13 | \subsubsection{复杂度与正确率} 14 | OI中一般只需设计产生单侧错误算法。 15 | 16 | 若单次正确率为$p$,复杂度为$O(f(n))$,则测量$k$次的正确率为$1-(1-p)^k$, 17 | 复杂度为$O(kf(n))$。 18 | \subsection{Las Vegas算法} 19 | 留坑待补。 20 | 21 | 上述内容参考了国家集训队2014论文集胡泽聪的《随机化算法在信息学竞赛中的应用》。 22 | -------------------------------------------------------------------------------- /Review/Other/IOGen.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int getRandom() { 3 | static int seed = 2351432; 4 | return seed = seed * 48271LL % 2147483647; 5 | } 6 | int main() { 7 | const int size = 1 << 27; 8 | freopen("data/IO1.in", "w", stdout); 9 | printf("%d\n", size); 10 | for(int i = 1; i <= size; ++i) 11 | printf("%d\n", getRandom()); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Review/Other/IOTest.hpp: -------------------------------------------------------------------------------- 1 | int read() { 2 | int res = 0; 3 | char c; 4 | do 5 | c = IO::getc(); 6 | while(c < '0' || c > '9'); 7 | while('0' <= c && c <= '9') { 8 | res = res * 10 + c - '0'; 9 | c = IO::getc(); 10 | } 11 | return res; 12 | } 13 | void writeImpl(int x) { 14 | if(x >= 10) 15 | writeImpl(x / 10); 16 | IO::putc('0' + x % 10); 17 | } 18 | void write(int x) { 19 | writeImpl(x); 20 | IO::putc('\n'); 21 | } 22 | int main() { 23 | IO::init(); 24 | int n = read(); 25 | write(n); 26 | while(n--) 27 | write(read()); 28 | IO::uninit(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Review/Other/IOTestA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace IO { 3 | void init() {} 4 | void uninit() {} 5 | char getc() { 6 | return getchar(); 7 | } 8 | void putc(int ch) { 9 | putchar(ch); 10 | } 11 | } 12 | #include "IOTest.hpp" 13 | -------------------------------------------------------------------------------- /Review/Other/IOTestB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | namespace IO { 4 | void init() { 5 | assert(setvbuf(stdin, 0, _IONBF, 0) == 0); 6 | assert(setvbuf(stdout, 0, _IONBF, 0) == 0); 7 | } 8 | const int size = 1 << 23; 9 | char in[size]; 10 | char getc() { 11 | static char *S = in, *T = in; 12 | if(S == T) 13 | S = in, T = in + fread(in, 1, size, stdin); 14 | return S == T ? EOF : *S++; 15 | } 16 | char out[size], *S = out, *T = out + size; 17 | void putc(char ch) { 18 | if(S == T) { 19 | fwrite(out, size, 1, stdout); 20 | S = out; 21 | } 22 | *S++ = ch; 23 | } 24 | void uninit() { 25 | fwrite(out, S - out, 1, stdout); 26 | } 27 | } 28 | #include "IOTest.hpp" 29 | -------------------------------------------------------------------------------- /Review/Other/IOTestC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | namespace IO { 4 | void init() { 5 | const int size = 1 << 23; 6 | assert(setvbuf(stdin, 0, _IOFBF, size) == 0); 7 | assert(setvbuf(stdout, 0, _IOFBF, size) == 0); 8 | } 9 | void uninit() {} 10 | char getc() { 11 | return getchar(); 12 | } 13 | void putc(int ch) { 14 | putchar(ch); 15 | } 16 | } 17 | #include "IOTest.hpp" 18 | -------------------------------------------------------------------------------- /Review/Other/Other.tex: -------------------------------------------------------------------------------- 1 | \chapter{杂项} 2 | \minitoc 3 | \input{Other/TricksAndIdeas} 4 | \input{Other/Owys} 5 | -------------------------------------------------------------------------------- /Review/Path/Path.tex: -------------------------------------------------------------------------------- 1 | \chapter{最短路相关问题} 2 | \minitoc 3 | \input{Path/SMSSP} 4 | \input{Path/DCS} 5 | \input{Path/KthSP} 6 | -------------------------------------------------------------------------------- /Review/Polynomial/Perf/PolyInvTest.cpp: -------------------------------------------------------------------------------- 1 | #include "PolyInv.hpp" 2 | #include 3 | int main() { 4 | init(); 5 | const int n = 1 << 22; 6 | Duration base = benchmark("NTT", n, benchmarkNTT); 7 | Duration invA = benchmark("PolyInv", n, [](int n) { 8 | return benchmarkInv(n, getInv); 9 | }); 10 | Duration invB = 11 | benchmark("PolyInvFast", n, [](int n) { 12 | return benchmarkInv(n, getInvFast); 13 | }); 14 | printf("ratio(Inv)=%.2lf\n", 15 | calcRatio(invA, base)); 16 | printf("ratio(InvFast)=%.2lf\n", 17 | calcRatio(invB, base)); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Review/Polynomial/Perf/PolySqrtTest.cpp: -------------------------------------------------------------------------------- 1 | #include "PolySqrt.hpp" 2 | #include 3 | int main() { 4 | init(); 5 | const int n = 1 << 22; 6 | Duration base = benchmark("NTT", n, benchmarkNTT); 7 | Duration sqrtA = 8 | benchmark("PolySqrt", n, [](int n) { 9 | return benchmarkSqrt(n, getSqrt); 10 | }); 11 | Duration sqrtB = 12 | benchmark("PolySqrtFast", n, [](int n) { 13 | return benchmarkSqrt(n, getSqrtFast); 14 | }); 15 | printf("ratio(Sqrt)=%.2lf\n", 16 | calcRatio(sqrtA, base)); 17 | printf("ratio(SqrtFast)=%.2lf\n", 18 | calcRatio(sqrtB, base)); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Review/Polynomial/Perf/WindowsTimer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | using Clock = std::chrono::high_resolution_clock; 4 | using TimePoint = Clock::time_point; 5 | using Duration = Clock::duration; 6 | 7 | void resetTimer() {} 8 | 9 | TimePoint now() { 10 | return Clock::now(); 11 | } 12 | 13 | double count(const Duration& dur) { 14 | return dur.count(); 15 | } 16 | 17 | double toMilliSecond(const Duration& dur) { 18 | constexpr double fac = 19 | static_cast(std::milli::den) / 20 | static_cast(Clock::period::den); 21 | return dur.count() * fac; 22 | } 23 | -------------------------------------------------------------------------------- /Review/Polynomial/Polynomial.tex: -------------------------------------------------------------------------------- 1 | \chapter{多项式} 2 | \minitoc 3 | \input{Polynomial/FFT} 4 | \input{Polynomial/NTT} 5 | \input{Polynomial/FWT} 6 | \input{Polynomial/FMT} 7 | \input{Polynomial/Advanced} 8 | \input{Polynomial/Module} 9 | \input{Polynomial/Optmize} 10 | \section{本章注记} 11 | Miskcoo的博客中有大量非常优秀的FFT系列文章 12 | \footnote{\url{http://blog.miskcoo.com/tag/fft}}。 13 | 14 | HocRiser对此系列做了全面的总结 15 | \footnote{\url{http://www.cnblogs.com/HocRiser/p/8207295.html}}。 16 | -------------------------------------------------------------------------------- /Review/SetAndGroupTheory/Lagrange.tex: -------------------------------------------------------------------------------- 1 | \section{拉格朗日定理} 2 | \index{L!Lagrange's Theorem} 3 | \begin{theorem}[Lagrange's Theorem]\label{LT} 4 | 若$(S,\oplus)$是一个有限群,$(S',\oplus)$是$(S,\oplus)$的子群,则 5 | $|S'|$是$|S|$的约数。 6 | \end{theorem} 7 | 证明留坑待补。 8 | \index{*TODO!拉格朗日定理证明} 9 | -------------------------------------------------------------------------------- /Review/SetAndGroupTheory/SetAndGroupTheory.tex: -------------------------------------------------------------------------------- 1 | \chapter{集合论~群论} 2 | \minitoc 3 | \input{SetAndGroupTheory/SetTheory} 4 | \input{SetAndGroupTheory/Lagrange} 5 | \input{SetAndGroupTheory/PermutationGroups} 6 | -------------------------------------------------------------------------------- /Review/Source: -------------------------------------------------------------------------------- 1 | ../ -------------------------------------------------------------------------------- /Review/SpanningTree/SpanningTree.tex: -------------------------------------------------------------------------------- 1 | \chapter{生成树} 2 | \minitoc 3 | \input{SpanningTree/MST} 4 | \input{SpanningTree/Kruskal} 5 | \input{SpanningTree/Manhattan} 6 | \input{SpanningTree/MatrixTree} 7 | \input{SpanningTree/SteinerTree} 8 | -------------------------------------------------------------------------------- /Review/String/Hash.tex: -------------------------------------------------------------------------------- 1 | \section{Hash} 2 | \subsection{BKDRHash} 3 | BKDRHash在一般情况下表现良好,速度快,Hash质量高。 4 | 代码如下: 5 | \begin{lstlisting} 6 | typedef unsigned long long HashT; 7 | HashT BKDRHash(const char* str) { 8 | HashT res=0; 9 | while(*str) { 10 | res=res*131+*str; 11 | ++str; 12 | } 13 | return res; 14 | } 15 | \end{lstlisting} 16 | \subsection{混合Hash} 17 | 若要快速求得子串Hash,预处理前缀Hash值,查询时化到同一幂次再差分。 18 | 19 | 若要判断两个串是否为同一子串或对称子串,可以同时预处理后缀Hash值, 20 | 然后将正向Hash值与逆向Hash值相乘得到新的Hash值。 21 | 22 | 若要忽略子串的某一连续区间,可以将其前缀的前缀Hash与后缀的后缀Hash 23 | 加权混合([CTSC2014]企鹅QQ)。 24 | \subsection{子串Hash} 25 | 有时会遇到与不重复连续子串相关的问题,可以$O(n\lg n)$枚举(调和级数)。 26 | 一般来说二分长度+Hash是个不错的思路。 27 | -------------------------------------------------------------------------------- /Review/String/Parser.tex: -------------------------------------------------------------------------------- 1 | \section{算术表达式解析} 2 | 此类表达式由三种元素构成:操作数,从左到右结合的二元运算符和括号。 3 | 4 | 解析算法如下: 5 | \begin{itemize} 6 | \item 实现简易的词法分析器区分出操作数、运算符和括号; 7 | \item 维护操作数栈和运算符栈(优先级单调递增),扫到: 8 | \begin{itemize} 9 | \item 操作数:将其压入操作数栈 10 | \item 左括号:将其压入运算符栈 11 | \item 运算符:取出不低于其优先级的运算符,并取出对应的操作数 12 | 进行运算,将左操作数折叠完毕后将其压入运算符栈; 13 | \item 右括号:取出从左括号到栈顶的运算符进行计算。 14 | \end{itemize} 15 | \item 不断取出操作数和运算符更新栈,直至运算符栈为空,此时 16 | 操作数栈只剩1个操作数(如果表达式合法),该数即为结果。 17 | \end{itemize} 18 | 19 | 实例:四则运算表达式解析(不支持一元运算符) 20 | \lstinputlisting{String/BOP.cpp} 21 | -------------------------------------------------------------------------------- /Review/String/ST.tex: -------------------------------------------------------------------------------- 1 | \section{后缀树} 2 | \index{S!Suffix Tree} 3 | 后缀树是由串S的所有后缀组成的压缩Trie。 4 | 5 | 为了避免压缩过程隐藏了某个后缀,插入每个后缀后再 6 | 插入一个不出现的字符。 7 | \subsection{构造} 8 | 常规的构造方法是$O(n^2)$的,一般采用Ukkonen算法在线性时间内完成构造。 9 | \index{U!Ukkonen's Algorithm} 10 | \index{*TODO!线性构造后缀树} 11 | 留坑待补(还是去学后缀仙人掌吧)。 12 | \subsection{广义后缀树} 13 | 广义后缀树在插入不同的串时用的结尾字符不同,以区分不同的字符串。 14 | 15 | 查询最长公共子串时要找到最深的拥有2种结束标记的节点。 16 | \subsection{应用} 17 | 后缀树满足如下性质: 18 | \begin{itemize} 19 | \item 每个节点代表一个子串。 20 | 21 | 查询串P在串S的出现次数可以按照Trie的方法匹配,然后 22 | 统计其所在节点的子树中的叶子节点个数。 23 | \item 每个非叶节点至少有两个儿子。 24 | 25 | 统计串S的最长重复子串要找到其最深非叶子节点。 26 | \end{itemize} 27 | 以上内容参考了v\_JULY\_v的博客\footnote{ 28 | 从Trie树(字典树)谈到后缀树(10.28修订) 29 | \url{https://blog.csdn.net/v\_july\_v/article/details/6897097} 30 | }。 31 | -------------------------------------------------------------------------------- /Review/String/String.tex: -------------------------------------------------------------------------------- 1 | \chapter{字符串} 2 | \minitoc 3 | \input{String/Hash} 4 | \input{String/Trie} 5 | \input{String/ACM} 6 | \input{String/Huffman} 7 | \input{String/KMP} 8 | \input{String/Manacher} 9 | \input{String/PAM} 10 | \input{String/ST} 11 | \input{String/SA} 12 | \input{String/SC} 13 | \input{String/SAM} 14 | \input{String/Parser} 15 | \input{String/ZAlgorithm} 16 | \input{String/Convolution} 17 | \input{String/Min} 18 | -------------------------------------------------------------------------------- /Review/Summary/Keyword.tex: -------------------------------------------------------------------------------- 1 | \section{基于关键字/特征} 2 | \subsubsection{恰好} 3 | \begin{itemize} 4 | \item 统计:将恰好改为至少/至多,然后使用容斥解决。 5 | \item 最优化:WQS二分 6 | \end{itemize} 7 | \subsubsection{约束} 8 | \begin{itemize} 9 | \item 布尔条件约束:2-SAT 10 | \item 不等式条件约束: 11 | \begin{itemize} 12 | \item 线性规划 13 | \item 网络流 14 | \item 差分约束 15 | \end{itemize} 16 | \item 等式条件约束:拉格朗日乘子法 17 | \end{itemize} 18 | \subsubsection{位运算} 19 | \begin{itemize} 20 | \item 按位贪心 21 | \item 线性基 22 | \item 子集卷积 23 | \end{itemize} 24 | \subsubsection{在指定范围内存在} 25 | \begin{itemize} 26 | \item 时间线段树 27 | \item 扫描线 28 | \end{itemize} 29 | \subsubsection{两项乘积小于定值} 30 | 分块/对数据分治,步长小的一起转移,步长大的单独转移。 31 | \subsubsection{最大化最小值/第k大} 32 | 使用(整体)二分。 33 | -------------------------------------------------------------------------------- /Review/Summary/Summary.tex: -------------------------------------------------------------------------------- 1 | \chapter{总结} 2 | \minitoc 3 | \input{Summary/Input} 4 | \input{Summary/Keyword} 5 | \input{Summary/Time} 6 | \input{Summary/LinkBlock} 7 | -------------------------------------------------------------------------------- /Review/Theory/Coding.tex: -------------------------------------------------------------------------------- 1 | \section{数值编码} 2 | \subsection{整数编码} 3 | 以下三种编码的首位都是符号位,正0负1。 4 | \paragraph{原码}数值位为真值的绝对值。 5 | \paragraph{反码}正数不变,负数数值位为原码数值位取反。 6 | \paragraph{补码}正数不变,负数数值位为原码数值位取反+1。补码转反码 7 | 时-1取反或者取反+1。 8 | \subsection{浮点数编码} 9 | 留坑待补。 10 | \index{*TODO!浮点数编码} 11 | -------------------------------------------------------------------------------- /Review/Theory/NP.tex: -------------------------------------------------------------------------------- 1 | \section{NP完全性} 2 | \subsection{定义} 3 | \paragraph{P} P类问题是在多项式时间内可被解决的问题。 4 | \paragraph{NP} NP类问题是在多项式时间内解可被检验的问题。 5 | \paragraph{NP-Complete} NP完全问题是所有NP类问题在多项式时间内 6 | 可约化的NP问题,若存在NPC问题有多项式算法,则P=NP。 7 | \paragraph{NP-Hard}NP-Hard问题是所有NP类问题在多项式时间内可约化的问题(包括NP与 8 | 非NP问题)。 9 | \subsection{常见NPC问题} 10 | \begin{itemize} 11 | \item $k-SAT,k>2$ 12 | \item 哈密尔顿回路 13 | \item 最大团 14 | \item 最小点覆盖 15 | \item 旅行商问题 16 | \item 子集和问题 17 | \item 子图同构问题 18 | \item 整数线性规划问题 19 | \item 集合划分问题 20 | \item 最长简单回路问题 21 | \end{itemize} 22 | -------------------------------------------------------------------------------- /Review/Theory/Theory.tex: -------------------------------------------------------------------------------- 1 | \chapter{理论} 2 | \minitoc 3 | \input{Theory/Analysis} 4 | \input{Theory/Coding} 5 | \input{Theory/Sort} 6 | \input{Theory/NP} 7 | -------------------------------------------------------------------------------- /Review/Tree/Tree.tex: -------------------------------------------------------------------------------- 1 | \chapter{树} 2 | \minitoc 3 | \input{Tree/LCA} 4 | \input{Tree/CBD} 5 | \input{Tree/Diameter} 6 | \input{Tree/DsuOnTree} 7 | \input{Tree/Purfer} 8 | \input{Tree/VirtualTree} 9 | \input{Tree/PBD} 10 | -------------------------------------------------------------------------------- /Review/charCounter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | int main() { 7 | std::locale::global(std::locale("")); 8 | system("pdftotext ../latex/Main.pdf"); 9 | std::wifstream in("../latex/Main.txt"); 10 | int cntA = 0, cntB = 0; 11 | while(in) { 12 | wchar_t c = in.get(); 13 | if(iswgraph(c)) { 14 | ++cntA; 15 | if(0x4E00 <= c && c <= 0x9FA5) 16 | ++cntB; 17 | } 18 | } 19 | std::wofstream out("../latex/charcnt"); 20 | out << cntA << "(" << cntB << ")" << std::flush; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Review/mypic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Review/mypic.jpg -------------------------------------------------------------------------------- /Source/Cacti/4630.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Source/Cacti/4630.cpp -------------------------------------------------------------------------------- /Source/Competition/APIO/LOJ2586Tab.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using Int64 = long long; 5 | using FT = double; 6 | const FT base = 1000000000; 7 | std::pair A[1005]; 8 | int main() { 9 | int n; 10 | scanf("%d", &n); 11 | FT pi2 = acos(-1.0); 12 | for(int i = 1; i <= n; ++i) { 13 | FT angle = pi2 / n * i; 14 | A[i].first = base * cos(angle); 15 | A[i].second = base * sin(angle); 16 | } 17 | std::random_shuffle(A + 1, A + n + 1); 18 | for(int i = 1; i <= n; ++i) { 19 | printf("{%lld,%lld},", A[i].first, 20 | A[i].second); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Source/Competition/FCS2019/Day5/number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | typedef long long Int64; 4 | std::bitset<250000005> A; 5 | void build(int x) { 6 | x /= 4; 7 | for(int i = 2; i * i <= x; ++i) { 8 | int base = i * i, end = x / base; 9 | for(int j = 1; j <= end; ++j) 10 | A.set(base * j); 11 | } 12 | } 13 | Int64 query(int x) { 14 | Int64 res = 0; 15 | for(int i = 2; i * i <= x; ++i) { 16 | int base = i * i, end = x / base; 17 | for(int j = 1; j <= end; ++j) { 18 | if(!A.test(j)) 19 | res += end / j; 20 | } 21 | } 22 | return res; 23 | } 24 | int main() { 25 | int L, R; 26 | scanf("%d%d", &L, &R); 27 | build(R); 28 | printf("%lld\n", query(R) - query(L - 1)); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Source/Competition/FCS2019/Day5/number2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long Int64; 3 | Int64 query(int x) { 4 | Int64 res = 0; 5 | for(int i = 2; i * i <= x; ++i) { 6 | bool flag = false; 7 | for(int j = 2; j * j <= i; ++j) 8 | if(i % j == 0) { 9 | flag = true; 10 | break; 11 | } 12 | if(flag) 13 | continue; 14 | int base = i * i, end = x / base; 15 | for(int j = 1; j <= end; ++j) 16 | res += end / j; 17 | } 18 | return res; 19 | } 20 | int main() { 21 | int L, R; 22 | scanf("%d%d", &L, &R); 23 | printf("%lld\n", query(R) - query(L - 1)); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Source/Competition/FCS2019/Day5/table.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Source/Competition/FCS2019/Day5/table.cpp -------------------------------------------------------------------------------- /Source/Competition/FCS2019/Day5/table2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Source/Competition/FCS2019/Day5/table2.cpp -------------------------------------------------------------------------------- /Source/Competition/FCS2019/Day5/tableC.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Source/Competition/FCS2019/Day5/tableC.cpp -------------------------------------------------------------------------------- /Source/Competition/FCS2019/Day7/cacdbg.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | freopen("data/sample-C.2.in", "r", stdin); 5 | freopen("G.dot", "w", stdout); 6 | puts("graph G{"); 7 | int n, m, q; 8 | scanf("%d%d%d", &n, &m, &q); 9 | for(int i = 1; i <= m; ++i) { 10 | int u, v; 11 | scanf("%d%d", &u, &v); 12 | printf("%d--%d;\n", u, v); 13 | if(i >= 100) 14 | break; 15 | } 16 | puts("}"); 17 | system("dot G.dot -T png -o G.png"); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/Competition/Multi2019/LOJ3050Test1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | std::bitset<200> bit( 5 | "111011000010100000010001011000101100110100011" 6 | "011010010100001001101000001101100111010001110" 7 | "000100100101011100101010101001110010010"); 8 | for(int i = 1000000; i <= 10000000; ++i) { 9 | long long res = 1, a = 19; 10 | for(int j = 0; j < 200; ++j) { 11 | if(bit[j]) 12 | res = res * a % i; 13 | a = a * a % i; 14 | } 15 | if(res == 642666) 16 | printf("%d\n", i); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/Competition/Multi2019/LOJ3050Test3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | unsigned int cur = 1; 4 | for(long long i = 0;; ++i, cur *= 19U) { 5 | if(cur == 1 && i) { 6 | printf("%lld\n", i); 7 | break; 8 | } 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Source/Count/SP9507.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; 4 | scanf("%d", &n); 5 | for(int i = 1; i <= n; ++i) { 6 | int m, k; 7 | scanf("%d%d", &m, &k); 8 | printf("Case #%d: %.8lf\n", i, 9 | 1.0 / (m * k + 1 + k)); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Source/FHQTreap/3285.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 7 8 9 10 2 | 1 2 11 (2):1 11 3 4 5 6 7 8 9 10 3 | 3 11 (2) :1 3 4 5 6 7 8 9 10 11 4 | 2 3 (2) :3 1 4 5 6 7 8 9 10 11 5 | 3 5 (4) :3 1 4 6 7 8 9 10 11 5 6 | 2 4 (3) :4 3 1 6 7 8 9 10 11 5 7 | 2 7 (5) :7 4 3 1 6 8 9 10 11 5 8 | 2 6 (5) :6 7 4 3 1 8 9 10 11 5 9 | 3 9 (7) :6 7 4 3 1 8 10 11 5 9 10 | 2 11 (8) :11 6 7 4 3 1 8 10 5 9 11 | 4 1 (11) :11 6 7 4 3 1 8 10 5 9 12 | -------------------------------------------------------------------------------- /Source/FWT FMT/LuoguP5387TestA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int sg[2005]; 3 | void calcSG(int x) { 4 | bool use[2005] = {}; 5 | for (int y = 1; y < x; ++y) 6 | if ((x ^ y) < x && (x ^ y) >= 1) 7 | use[sg[x ^ y]] = true; 8 | for (int z = 0;; ++z) 9 | if (!use[z]) { 10 | sg[x] = z; 11 | return; 12 | } 13 | } 14 | int sgo1(int x) { 15 | return x - (1 << (31 - __builtin_clz(x))); 16 | } 17 | int main() { 18 | for (int i = 1; i <= 2000; ++i) { 19 | calcSG(i); 20 | printf("%d %d %d\n", i, sg[i], sgo1(i)); 21 | if (sg[i] != sgo1(i)) 22 | throw; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Source/FWT FMT/LuoguP5387TestB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int sg(int x) { 3 | return x - (1 << (31 - __builtin_clz(x))); 4 | } 5 | int cnt = 0; 6 | void DFS(int v, int m, int xorv) { 7 | if (v) { 8 | for (int i = 1; i <= m; ++i) 9 | DFS(v - 1, m, xorv ^ sg(i)); 10 | } else 11 | cnt += (xorv != 0); 12 | } 13 | int main() { 14 | int v, m; 15 | scanf("%d%d", &v, &m); 16 | DFS(v, m, 0); 17 | printf("%d\n", cnt); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/Game Theory/2197.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | bool foo(){ 13 | int n=read(),res=0; 14 | while(n--)res^=read(); 15 | return res; 16 | } 17 | int main(){ 18 | int t=read(); 19 | while(t--)puts(foo()?"Yes":"No"); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Source/Game Theory/2252.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() { 5 | int a, b; 6 | scanf("%d%d", &a, &b); 7 | if(a > b) 8 | std::swap(a, b); 9 | double phi = 0.5 * (sqrt(5.0) + 1.0); 10 | bool flag = a != static_cast((b - a) * phi); 11 | puts(flag ? "1" : "0"); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Source/Game Theory/2964.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | const int size=2005; 5 | int n,c[size],cache[size][size]; 6 | int query(int d,int maxop){ 7 | if(maxop<=0)return 0; 8 | if(cache[d][maxop]==-1){ 9 | int res=0; 10 | for(int i=1;i<=maxop;++i){ 11 | int end=d+i; 12 | res=std::max(res,c[d]-query(end,std::min(i<<1,n-end+1))); 13 | } 14 | cache[d][maxop]=res; 15 | } 16 | return cache[d][maxop]; 17 | } 18 | int main(){ 19 | memset(cache,-1,sizeof(cache)); 20 | scanf("%d",&n); 21 | for(int i=1;i<=n;++i) 22 | scanf("%d",&c[i]); 23 | for(int i=n;i>=1;--i) 24 | c[i]+=c[i+1]; 25 | printf("%d\n",query(1,std::min(n,2))); 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Source/Game Theory/2964dp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size=2005; 4 | int n,c[size],dp[size][size]; 5 | int main(){ 6 | scanf("%d",&n); 7 | for(int i=n;i>=1;--i) 8 | scanf("%d",&c[i]); 9 | for(int i=1;i<=n;++i) 10 | c[i]+=c[i-1]; 11 | for(int i=1;i<=n;++i){ 12 | int res=1<<30; 13 | for(int j=1;j<=n;++j){ 14 | int k1=j<<1; 15 | if(i>=k1)res=std::min(res,dp[i-k1][k1]); 16 | int k2=k1-1; 17 | if(i>=k2)res=std::min(res,dp[i-k2][k2]); 18 | dp[i][j]=c[i]-res; 19 | } 20 | } 21 | printf("%d\n",dp[n][1]); 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Source/Game Theory/3480.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | bool foo(){ 13 | int n=read(); 14 | int res=0,last=0,mask=n&1; 15 | for(int i=1;i<=n;++i){ 16 | int val=read(); 17 | if((i&1)==mask)res^=val-last; 18 | last=val; 19 | } 20 | return res; 21 | } 22 | int main(){ 23 | int t=read(); 24 | while(t--)puts(foo()?"TAK":"NIE"); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Source/Game Theory/4279.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int read() { 3 | int res = 0, c; 4 | do 5 | c = getchar(); 6 | while(c < '0' || c > '9'); 7 | while('0' <= c && c <= '9') { 8 | res = res * 10 + c - '0'; 9 | c = getchar(); 10 | } 11 | return res; 12 | } 13 | bool foo() { 14 | int n = read(), sg = 0; 15 | bool flag = true; 16 | while(n--) { 17 | int x = read(); 18 | sg ^= x; 19 | flag &= x == 1; 20 | } 21 | return static_cast(sg) ^ flag; 22 | } 23 | int main() { 24 | int t = read(); 25 | while(t--) 26 | puts(foo() ? "John" : "Brother"); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Source/Generating Function/4451.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size = 1000005, mod = 1000000007; 3 | long long f[size]; 4 | int main() { 5 | int n; 6 | scanf("%d", &n); 7 | f[1] = 1; 8 | for(int i = 2; i <= n; ++i) 9 | f[i] = (2 * f[i - 1] + f[i - 2]) % mod; 10 | printf("%lld\n", f[n]); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Source/Number Theory/3579.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int foo(int a, int b, int c, int d) { 4 | --a, --c; 5 | int end = sqrt(b > d ? b : d), res = 0; 6 | for (int i = 1; i <= end; ++i) { 7 | int div[4] = {a / i, b / i, c / i, d / i}; 8 | if (i > res && div[0] < div[1] && div[2] < div[3]) res = i; 9 | for (int j = 0; j < 4; ++j) { 10 | int x = div[j]; 11 | if (x > res && a / x < b / x && c / x < d / x) res = x; 12 | } 13 | } 14 | return res; 15 | } 16 | int main() { 17 | int t; 18 | scanf("%d", &t); 19 | while (t--) { 20 | int a, b, c, d; 21 | scanf("%d%d%d%d", &a, &b, &c, &d); 22 | printf("%d\n", foo(a, b, c, d)); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Source/Number Theory/4549.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int gcd(int a, int b) { 3 | return b ? gcd(b, a % b) : a; 4 | } 5 | int main() { 6 | int n, res = 0; 7 | scanf("%d", &n); 8 | while(n--) { 9 | int x; 10 | scanf("%d", &x); 11 | res = gcd(res, x); 12 | } 13 | printf("%d\n", res >= 0 ? res : -res); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Source/Number Theory/UVA756.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int foo(int p, int e, int i, int d) { 3 | const int k1 = 5544, k2 = 14421, k3 = 1288, 4 | mod = 21252; 5 | int res = (k1 * p + k2 * e + k3 * i) % mod - d; 6 | while(res <= 0) 7 | res += mod; 8 | return res; 9 | } 10 | int main() { 11 | int p, e, i, d, cnt = 0; 12 | while(scanf("%d%d%d%d", &p, &e, &i, &d) != EOF && 13 | p >= 0) { 14 | printf("Case %d: the next triple peak occurs " 15 | "in %d days.\n", 16 | ++cnt, foo(p, e, i, d)); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/Probability/1297.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int n, A, B, C, a; 5 | scanf("%d%d%d%d%d", &n, &A, &B, &C, &a); 6 | double first = a % C + 1, last = a % C + 1, 7 | res = 0.0; 8 | for(int i = 2; i <= n; ++i) { 9 | a = (static_cast(a) * A + B) % 10 | 100000001; 11 | double cur = a % C + 1; 12 | res += std::min(cur, last) / (cur * last); 13 | last = cur; 14 | } 15 | res += std::min(first, last) / (first * last); 16 | printf("%.3lf\n", res); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; 4 | scanf("%d", &n); 5 | int res = 0; 6 | for(int i = 1; i < n; ++i) 7 | if(i % 3 == 0 || i % 5 == 0) 8 | res += i; 9 | printf("%d\n", res); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE10.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int n = 2000000; 3 | bool flag[n + 5]; 4 | int main() { 5 | int pcnt = 0; 6 | long long sum = 0; 7 | for(int i = 2; i <= n; ++i) 8 | if(!flag[i]) { 9 | sum += i; 10 | for(int j = i * 2; j <= n; j += i) 11 | flag[j] = true; 12 | } 13 | printf("%lld\n", sum); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int A[40][40]; 4 | int main() { 5 | for(int i = 5; i < 25; ++i) 6 | for(int j = 5; j < 25; ++j) 7 | scanf("%d", &A[i][j]); 8 | int res = 0; 9 | for(int i = 5; i < 25; ++i) 10 | for(int j = 5; j < 25; ++j) { 11 | int valA = 1, valB = 1, valC = 1, valD = 1; 12 | for(int k = 0; k < 4; ++k) { 13 | valA *= A[i][j + k]; 14 | valB *= A[i + k][j]; 15 | valC *= A[i + k][j + k]; 16 | valD *= A[i + k][j - k]; 17 | } 18 | res = std::max( 19 | res, std::max(std::max(valA, valB), 20 | std::max(valC, valD))); 21 | } 22 | printf("%d\n", res); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE12.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; 4 | scanf("%d", &n); 5 | for(int i = 1, x = 1;; ++i, x += i) { 6 | int cnt = 1, nx = x; 7 | for(int j = 2; j * j <= nx; ++j) 8 | if(nx % j == 0) { 9 | int pc = 1; 10 | do 11 | nx /= j, ++pc; 12 | while(nx % j == 0); 13 | cnt *= pc; 14 | } 15 | if(nx != 1) 16 | cnt *= 2; 17 | if(cnt > n) { 18 | printf("%d\n", x); 19 | break; 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE14.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int mx = 1, mcnt = 1; 4 | for(int i = 1; i < 1000000; ++i) { 5 | long long x = i; 6 | int cnt = 1; 7 | while(x != 1) { 8 | if(x & 1) 9 | x = 3 * x + 1; 10 | else 11 | x >>= 1; 12 | ++cnt; 13 | } 14 | if(cnt > mcnt) 15 | mcnt = cnt, mx = i; 16 | } 17 | printf("%d %d\n", mx, mcnt); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE15.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long Int64; 3 | Int64 C[45][25]; 4 | int main() { 5 | C[0][0] = 1; 6 | for(int i = 1; i <= 40; ++i) { 7 | C[i][0] = 1; 8 | for(int j = 1; j <= 20; ++j) 9 | C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; 10 | } 11 | printf("%lld\n", C[40][20]); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE17.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int A[20] = { 0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3 | 3, 6, 6, 8, 8, 7, 7, 9, 8, 8 }; 4 | int B[10] = { 0, 0, 6, 6, 5, 5, 5, 7, 6, 6 }; 5 | int count(int x) { 6 | if(x >= 100) 7 | return A[x / 100] + 7 + (x % 100 ? 3 : 0) + 8 | count(x % 100); 9 | if(x >= 20) 10 | return B[x / 10] + A[x % 10]; 11 | return A[x]; 12 | } 13 | int main() { 14 | int cnt = 11; 15 | for(int i = 1; i < 1000; ++i) 16 | cnt += count(i); 17 | printf("%d\n", cnt); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE18.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int A[40][40], B[40][40]; 4 | int main() { 5 | int n; 6 | scanf("%d", &n); 7 | for(int i = 1; i <= n; ++i) 8 | for(int j = 1; j <= i; ++j) 9 | scanf("%d", &A[i][j]); 10 | for(int i = 1; i <= n; ++i) { 11 | for(int j = 1; j <= i; ++j) { 12 | B[i][j] = std::max(B[i - 1][j - 1], 13 | B[i - 1][j]) + 14 | A[i][j]; 15 | } 16 | } 17 | int res = 0; 18 | for(int i = 1; i <= n; ++i) 19 | res = std::max(res, B[n][i]); 20 | printf("%d\n", res); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size = 100; 3 | int A[size]; 4 | int main() { 5 | int n; 6 | scanf("%d", &n); 7 | A[0] = A[1] = 1; 8 | long long sum = 0; 9 | for(int i = 2;; ++i) { 10 | A[i] = A[i - 1] + A[i - 2]; 11 | if(A[i] > n) 12 | break; 13 | if((A[i] & 1) == 0) 14 | sum += A[i]; 15 | } 16 | printf("%lld\n", sum); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE21.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int A[10005]; 3 | int main() { 4 | int res = 0; 5 | for(int i = 1; i < 10000; ++i) { 6 | for(int j = 1; j < i; ++j) 7 | if(i % j == 0) 8 | A[i] += j; 9 | if(A[i] < i && A[A[i]] == i) 10 | res += A[i] + i; 11 | } 12 | printf("%d\n", res); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE23.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int A[30000]; 3 | bool B[30000]; 4 | int main() { 5 | int acnt = 0; 6 | for(int i = 1; i <= 28123; ++i) { 7 | int sum = 0; 8 | for(int j = 1; j < i; ++j) 9 | if(i % j == 0) 10 | sum += j; 11 | if(sum > i) { 12 | A[++acnt] = i; 13 | B[i] = true; 14 | } 15 | } 16 | int sum = 0; 17 | for(int i = 1; i <= 28123; ++i) { 18 | bool flag = false; 19 | for(int j = 1; j <= acnt && i > A[j]; ++j) 20 | if(B[i - A[j]]) { 21 | flag = true; 22 | break; 23 | } 24 | if(!flag) 25 | sum += i; 26 | } 27 | printf("%d\n", sum); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE26.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int maxc = 0, maxi = 0; 5 | for(int i = 1; i < 1000; ++i) { 6 | int c = 1, cc = 0, cnt = 0; 7 | std::map r; 8 | while(c) { 9 | ++cc; 10 | c = c * 10 % i; 11 | if(r.count(c)) { 12 | cnt = cc - r[c]; 13 | break; 14 | } else 15 | r[c] = cc; 16 | } 17 | printf("%d %d\n", i, cnt); 18 | if(cnt > maxc) 19 | maxc = cnt, maxi = i; 20 | } 21 | printf("%d\n", maxi); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long Int64; 3 | int main() { 4 | Int64 n; 5 | scanf("%lld", &n); 6 | Int64 res = 1; 7 | for(Int64 i = 2; i * i <= n; ++i) { 8 | if(n % i == 0) { 9 | res = i; 10 | do 11 | n /= i; 12 | while(n % i == 0); 13 | } 14 | } 15 | if(n) 16 | res = n; 17 | printf("%lld\n", res); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE30.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int A[10]; 3 | int main() { 4 | for(int i = 0; i < 10; ++i) { 5 | int x = 1; 6 | for(int j = 0; j < 5; ++j) 7 | x *= i; 8 | A[i] = x; 9 | } 10 | long long res = 0; 11 | for(int i = 10; i <= 300000; ++i) { 12 | int x = i, sum = 0; 13 | while(x) { 14 | sum += A[x % 10]; 15 | x /= 10; 16 | } 17 | if(sum == i) 18 | res += i; 19 | } 20 | printf("%lld\n", res); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE31.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int A[8] = { 1, 2, 5, 10, 20, 50, 100, 200 }; 3 | int dp[205]; 4 | int main() { 5 | dp[0] = 1; 6 | for(int i = 0; i < 8; ++i) 7 | for(int j = A[i]; j <= 200; ++j) 8 | dp[j] += dp[j - A[i]]; 9 | printf("%d\n", dp[200]); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE33.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int gcd(int a, int b) { 3 | return b ? gcd(b, a % b) : a; 4 | } 5 | int main() { 6 | int x = 1, y = 1; 7 | for(int i = 10; i < 100; ++i) 8 | for(int j = i + 1; j < 100; ++j) { 9 | int a = i / 10, b = i % 10, c = j / 10, 10 | d = j % 10; 11 | bool flag = false; 12 | flag |= (a == c && i * d == b * j); 13 | flag |= (a == d && i * c == b * j); 14 | flag |= (b == c && i * d == a * j); 15 | flag |= (b == d && i * c == a * j); 16 | if(flag && b && d) { 17 | printf("%d %d\n", i, j); 18 | x *= i, y *= j; 19 | } 20 | } 21 | int d = gcd(x, y); 22 | printf("%d %d\n", x / d, y / d); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE34.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int A[10]; 4 | A[0] = 1; 5 | for(int i = 1; i < 10; ++i) 6 | A[i] = A[i - 1] * i; 7 | int n; 8 | scanf("%d", &n); 9 | long long res = 0; 10 | for(int i = 10; i <= n; ++i) { 11 | int ci = i, s = 0; 12 | while(ci) { 13 | s += A[ci % 10]; 14 | ci /= 10; 15 | } 16 | if(s == i) { 17 | res += i; 18 | printf("%d\n", i); 19 | } 20 | if((i & 0xfffff) == 0) 21 | printf("cur %d\n", i); 22 | } 23 | printf("%lld\n", res); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE36.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | template 3 | bool check(int x) { 4 | int b[25], icnt = 0; 5 | while(x) { 6 | b[icnt++] = x % base; 7 | x /= base; 8 | } 9 | --icnt; 10 | for(int i = 0; i < icnt - i; ++i) 11 | if(b[i] != b[icnt - i]) 12 | return false; 13 | return true; 14 | } 15 | int main() { 16 | int n; 17 | scanf("%d", &n); 18 | long long res = 0; 19 | for(int i = 1; i < n; ++i) 20 | if(check<10>(i) && check<2>(i)) { 21 | printf("%d\n", i); 22 | res += i; 23 | } 24 | printf("%lld\n", res); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE38.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | for(int i = 1; i < 100000; ++i) { 4 | bool use[10] = {}; 5 | use[0] = true; 6 | int uc = 0; 7 | for(int j = 1; j <= 9; ++j) { 8 | long long val = 1LL * i * j; 9 | while(val) { 10 | int v = val % 10; 11 | if(use[v]) 12 | goto err; 13 | use[v] = true, ++uc; 14 | val /= 10; 15 | } 16 | if(uc == 9 && j > 1) 17 | break; 18 | } 19 | printf("%d\n", i); 20 | err : {} 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE39.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int mcnt = 0, mi = 0; 4 | for(int i = 3; i <= 1000; ++i) { 5 | int cnt = 0; 6 | for(int j = 1; j <= i; ++j) 7 | for(int k = j; i - (j + k) >= k; ++k) { 8 | int l = i - (j + k); 9 | if(j * j + k * k == l * l) 10 | ++cnt; 11 | } 12 | if(cnt > mcnt) 13 | mcnt = cnt, mi = i; 14 | } 15 | printf("%d %d\n", mi, mcnt); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int res = 0; 5 | for(int i = 100; i < 1000; ++i) 6 | for(int j = i; j < 1000; ++j) { 7 | int val = i * j; 8 | int b[6]; 9 | for(int k = 0; k < 6; ++k) { 10 | b[k] = val % 10; 11 | val /= 10; 12 | } 13 | if(b[0] == b[5] && b[1] == b[4] && 14 | b[2] == b[3]) 15 | res = std::max(res, i * j); 16 | } 17 | printf("%d\n", res); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE40.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() { 5 | std::stringstream ss; 6 | for(int i = 0; i <= 200000; ++i) 7 | ss << i; 8 | std::string str = ss.str(); 9 | int res = 1; 10 | for(int i = 1; i <= 1000000; i *= 10) 11 | res *= str[i] - '0'; 12 | printf("%d\n", res); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE42.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int read() { 4 | int res = 0, c; 5 | do { 6 | c = getchar(); 7 | if(c == EOF) 8 | throw c; 9 | } while(c < 'A' || c > 'Z'); 10 | while('A' <= c && c <= 'Z') { 11 | const int off = 'A' - 1; 12 | res += c - off; 13 | c = getchar(); 14 | } 15 | return res; 16 | } 17 | bool flag[2000]; 18 | int main() { 19 | freopen("p042_words.txt", "r", stdin); 20 | for(int i = 1; i <= 40; ++i) 21 | flag[i * (i + 1) / 2] = true; 22 | int res = 0; 23 | try { 24 | while(true) 25 | res += flag[read()]; 26 | } catch(...) { 27 | } 28 | printf("%d\n", res); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE43.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int A[10]; 4 | const int p[10] = { 0, 2, 3, 5, 7, 11, 13, 17 }; 5 | int main() { 6 | for(int i = 0; i < 10; ++i) 7 | A[i] = i; 8 | long long res = 0; 9 | do { 10 | long long val = 0; 11 | for(int i = 1; i <= 7; ++i) { 12 | int sum = 0; 13 | for(int j = 0; j < 3; ++j) 14 | sum = sum * 10 + A[i + j]; 15 | if(sum % p[i]) 16 | goto err; 17 | } 18 | for(int i = 0; i < 10; ++i) 19 | val = val * 10 + A[i]; 20 | res += val; 21 | printf("%lld\n", val); 22 | err : {} 23 | } while(std::next_permutation(A, A + 10)); 24 | printf("%lld\n", res); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE44.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int f(int x) { 5 | return x * (3 * x - 1) / 2; 6 | } 7 | int main() { 8 | int n; 9 | scanf("%d", &n); 10 | std::set A; 11 | for(int i = 1; i <= n; ++i) 12 | A.insert(f(i)); 13 | int res = 1 << 30; 14 | for(int i = 1; i <= n; ++i) 15 | for(int j = 1; j <= i; ++j) { 16 | if(A.count(f(i) + f(j)) && 17 | A.count(f(i) - f(j))) 18 | res = std::min(res, f(i) - f(j)); 19 | } 20 | printf("%d\n", res); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE45.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long Int64; 3 | Int64 T(Int64 n) { 4 | return n * (n + 1) / 2; 5 | } 6 | Int64 P(Int64 n) { 7 | return n * (3 * n - 1) / 2; 8 | } 9 | Int64 H(Int64 n) { 10 | return n * (2 * n - 1); 11 | } 12 | int main() { 13 | Int64 i = 1, j = 1, k = 1; 14 | while(true) { 15 | Int64 vi = T(i), vj = P(j), vk = H(k); 16 | if(vi == vj && vi == vk) 17 | printf("%lld %lld %lld %lld\n", i, j, k, 18 | vi); 19 | if(vi <= vj && vi <= vk) 20 | ++i; 21 | else if(vj <= vi && vj <= vk) 22 | ++j; 23 | else 24 | ++k; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE46.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size = 1000000; 3 | bool flag[size + 5]; 4 | bool check(int x) { 5 | for(int i = 1; 2 * i * i <= x; ++i) { 6 | int val = x - 2 * i * i; 7 | if(!flag[val]) 8 | return true; 9 | } 10 | return false; 11 | } 12 | int main() { 13 | flag[0] = flag[1] = true; 14 | for(int i = 2; i < size; ++i) 15 | if(!flag[i]) 16 | for(int j = i * 2; j < size; j += i) 17 | flag[j] = true; 18 | for(int i = 3; i < size; i += 2) 19 | if(flag[i] && !check(i)) { 20 | printf("%d\n", i); 21 | break; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE47.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int last = -1, lcnt = 0; 4 | for(int i = 1;; ++i) { 5 | int pcnt = 0, ci = i; 6 | for(int j = 2; j * j <= ci; ++j) 7 | if(ci % j == 0) { 8 | ++pcnt; 9 | do 10 | ci /= j; 11 | while(ci % j == 0); 12 | } 13 | if(ci != 1) 14 | ++pcnt; 15 | if(pcnt != last) 16 | last = pcnt, lcnt = 0; 17 | ++lcnt; 18 | if(pcnt == 4 && lcnt == 4) { 19 | printf("%d\n", i - 3); 20 | break; 21 | } 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | for(int i = 20;; ++i) { 4 | bool flag = true; 5 | for(int j = 1; j <= 20; ++j) 6 | if(i % j) { 7 | flag = false; 8 | break; 9 | } 10 | if(flag) { 11 | printf("%d\n", i); 12 | break; 13 | } 14 | } 15 | printf("%d\n", 16 * 9 * 5 * 7 * 11 * 13 * 17 * 19); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE53.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int C[105][105]; 4 | int main() { 5 | int n, res = 0; 6 | scanf("%d", &n); 7 | C[0][0] = 1; 8 | for(int i = 1; i <= n; ++i) { 9 | C[i][0] = 1; 10 | for(int j = 1; j <= i; ++j) { 11 | C[i][j] = 12 | std::min(1 << 20, C[i - 1][j - 1] + 13 | C[i - 1][j]); 14 | res += C[i][j] > 1000000; 15 | } 16 | } 17 | printf("%d\n", res); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long Int64; 3 | int main() { 4 | Int64 n; 5 | scanf("%lld", &n); 6 | Int64 a = n * (n + 1) / 2; 7 | Int64 b = n * (n + 1) * (2 * n + 1) / 6; 8 | printf("%lld\n", a * a - b); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int n = 1000000; 3 | bool flag[n + 5]; 4 | int main() { 5 | int pcnt = 0; 6 | for(int i = 2; i <= n; ++i) 7 | if(!flag[i]) { 8 | if(++pcnt == 10001) { 9 | printf("%d\n", i); 10 | break; 11 | } 12 | for(int j = i * 2; j <= n; j += i) 13 | flag[j] = true; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Source/ProjectEulerEasy/PE9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | for(int i = 1; i < 1000; ++i) 4 | for(int j = i + 1; i + j < 1000; ++j) { 5 | int k = 1000 - i - j; 6 | if(i * i + j * j == k * k) { 7 | printf("%d\n", i * j * k); 8 | break; 9 | } 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Source/Sieve/LOJ2085Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int gcd(int a, int b) { 3 | return b ? gcd(b, a % b) : a; 4 | } 5 | int main() { 6 | int n, m, k; 7 | scanf("%d%d%d", &n, &m, &k); 8 | long long res = 0; 9 | for(int y = 1; y <= m; ++y) { 10 | if((y & 127) == 0) 11 | printf("%d\n", y); 12 | if(gcd(y, k) != 1) 13 | continue; 14 | for(int x = 1; x <= n; ++x) 15 | res += (gcd(x, y) == 1); 16 | } 17 | printf("%lld\n", res); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Source/Sieve/LOJ509Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int n, m; 5 | scanf("%d%d", &n, &m); 6 | int cnt = 0; 7 | for(int i = 1; i <= n; ++i) { 8 | for(int j = 1; j <= m; ++j) { 9 | long long mul = 1LL * i * j; 10 | long long val = sqrt(mul); 11 | if(val * val == mul) 12 | ++cnt; 13 | } 14 | if(i % 100 == 0) 15 | printf("%d\n", i); 16 | } 17 | printf("%d\n", cnt); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Templates/Catalan.cpp: -------------------------------------------------------------------------------- 1 | // P1044 2 | #include 3 | int main() { 4 | int n; 5 | long long cur = 1; 6 | scanf("%d", &n); 7 | for(int i = 1; i <= n; ++i) 8 | cur = cur * (4 * i - 2) / (i + 1); 9 | printf("%lld\n", cur); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Test/ArgTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char* argv[]) { 3 | for(int i = 0; i < argc; ++i) 4 | puts(argv[i]); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /Test/BitTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int bcnt(int x) { 4 | return __builtin_popcount(x); 5 | } 6 | const int maxa = 233333, maxn = 211985; 7 | int A[20]; 8 | int main() { 9 | for(int i = 1; i <= maxa; ++i) 10 | ++A[bcnt(i)]; 11 | int res = 0, rem = maxn; 12 | for(int i = 1; i < 20; ++i) { 13 | if(A[i] < rem) { 14 | rem -= A[i]; 15 | res += A[i] << i; 16 | } else 17 | res += rem << i; 18 | } 19 | printf("%d\n", res); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Test/LocaleTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main() { 6 | system("chcp 65001"); 7 | setlocale(LC_ALL, ""); 8 | puts("@我是中国人@@@"); 9 | _putws(L"@我是中国人@@@"); 10 | // std::locale loc(""); 11 | // std::locale::global(loc); 12 | // std::cout << loc.name() << std::endl; 13 | std::cout << "@我是中国人@@@" << std::endl; 14 | std::wcout << u"@我是中国人@@@" << std::endl; 15 | std::cin.get(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Test/PreDivTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size = 10000000; 3 | bool flag[size + 5]; 4 | int main() { 5 | flag[1] = true; 6 | int pd[] = { 2, 3, 5, 7, 11, 13 }; 7 | for(auto x : pd) 8 | for(int i = x + x; i <= size; i += x) 9 | flag[i] = true; 10 | int cnt = 0; 11 | for(int i = 1; i <= size; ++i) 12 | cnt += flag[i]; 13 | printf("%lf\n", static_cast(cnt) / size); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Test/RegexTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() { 5 | std::string str("000VmPeak:270588kBVmSize:"); 6 | std::regex pattern("VmPeak:([0-9]*)kB"); 7 | std::cout << pattern.mark_count() << std::endl; 8 | std::smatch match; 9 | std::regex_search(str, match, pattern); 10 | std::cout << match.size() << std::endl; 11 | for(auto m : match) 12 | std::cout << m << std::endl; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Test/StatusError.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | system("chcp 936"); 5 | char buf[1024] = {}; 6 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 7 | EXCEPTION_STACK_OVERFLOW, 0, buf, 8 | sizeof(buf), 0); 9 | // puts(buf); 10 | while(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 11 | NULL, GetLastError(), 0, buf, 12 | sizeof(buf), 0) == 0) 13 | puts("XXX"); 14 | puts(buf); 15 | const char* str = R"( 16 | #include 17 | )"; 18 | puts(str); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Test/strtodTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | const char* A = "1.00"; 5 | double B = strtod(A, nullptr); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /Unclassified/Done/1004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int w[10][10],dp[10][10][10][10]={}; 3 | void CAS(int& a,int b){ 4 | if(a 2 | typedef long long int128; 3 | int128 dp[81][81],A[81]; 4 | void print(int128 x){ 5 | if(x>=10)print(x/10); 6 | putchar('0'+x%10); 7 | } 8 | int128 maxv(int128 a,int128 b){ 9 | return a>b?a:b; 10 | } 11 | int main(){ 12 | int n,m,x; 13 | scanf("%d%d",&n,&m); 14 | int128 ans=0; 15 | for(int i=1;i<=n;++i){ 16 | for(int j=1;j<=m;++j){ 17 | scanf("%d",&x); 18 | A[j]=dp[j][j]=x; 19 | dp[j][j]<<=m; 20 | } 21 | for(int k=2;k<=m;++k) 22 | for(int r=k;r<=m;++r){ 23 | int l=r-k+1,sh=m-k+1; 24 | dp[l][r]=maxv((A[l]< 2 | int dp[51][51][51][51]={},w[51][51]; 3 | void CAS(int& a,int b){ 4 | if(a 2 | double a,b,c,d; 3 | double f(double x){ 4 | return ((a*x+b)*x+c)*x+d; 5 | } 6 | double calc(double l,double r){ 7 | while(r-l>1e-3){ 8 | double mid=(l+r)/2.0; 9 | if(f(mid)*f(l)<=0.0)r=mid; 10 | else l=mid; 11 | } 12 | return l; 13 | } 14 | int main(){ 15 | scanf("%lf%lf%lf%lf",&a,&b,&c,&d); 16 | for(double i=-100.1124;i<100.0;++i) 17 | if(f(i)*f(i+1)<0.0) 18 | printf("%.2lf ",calc(i,i+1)); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Unclassified/Done/1049.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | bool dp[20001]={}; 3 | int v[31]; 4 | int main(){ 5 | int mv,n,x; 6 | scanf("%d%d",&mv,&n); 7 | for(int i=1;i<=n;++i) 8 | scanf("%d",&v[i]); 9 | dp[0]=true; 10 | for(int i=1;i<=n;++i){ 11 | for(int j=mv;j>=v[i];--j) 12 | dp[j]|=dp[j-v[i]]; 13 | } 14 | 15 | for(int i=mv;i>=0;--i) 16 | if(dp[i]){ 17 | printf("%d\n",mv-i); 18 | break; 19 | } 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Unclassified/Done/1057.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[31][31]={}; 3 | int main(){ 4 | int n,m; 5 | scanf("%d%d",&n,&m); 6 | dp[0][0]=1; 7 | for(int i=1;i<=m;++i){ 8 | for(int j=0;j 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int key[10000][100],f[10000][100],cnt[10000]={}; 13 | int main(){ 14 | int n,m,s; 15 | n=read(); 16 | m=read(); 17 | for(int i=0;i 2 | const int mod=1000007; 3 | int A[105],dp[105][105]={}; 4 | int main(){ 5 | int n,m; 6 | scanf("%d%d",&n,&m); 7 | for(int i=1;i<=n;++i) 8 | scanf("%d",&A[i]); 9 | dp[0][0]=1; 10 | for(int i=1;i<=n;++i) 11 | for(int j=0;j<=m;++j) 12 | for(int k=0;k<=A[i] && k<=j;++k) 13 | dp[i][j]=(dp[i][j]+dp[i-1][j-k])%mod; 14 | printf("%d\n",dp[n][m]); 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Unclassified/Done/1108.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int w[5001],dp[5001]={},c[5001]={}; 4 | int main(){ 5 | int n; 6 | scanf("%d",&n); 7 | w[0]=2147483647; 8 | for(int i=1;i<=n;++i) 9 | scanf("%d",&w[i]); 10 | int ans=0; 11 | for(int i=1;i<=n;++i){ 12 | for(int j=0;j 2 | #include 3 | int read(){ 4 | int res=0,c; 5 | do c=getchar(); 6 | while(c<'0'||c>'9'); 7 | while('0'<=c&&c<='9'){ 8 | res=res*10+c-'0'; 9 | c=getchar(); 10 | } 11 | return res; 12 | } 13 | int dp[10001]; 14 | int main(){ 15 | int n=read(),ans=0; 16 | memset(dp,0x3f,sizeof(dp)); 17 | dp[0]=0; 18 | for(int i=1;i<=n;++i){ 19 | read(); 20 | int len=read(),x,maxt=0; 21 | while(x=read()) 22 | if(dp[x]>maxt) 23 | maxt=dp[x]; 24 | dp[i]=maxt+len; 25 | if(dp[i]>ans)ans=dp[i]; 26 | } 27 | printf("%d\n",ans); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Unclassified/Done/1114.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int head[200010]={}; 3 | int main(){ 4 | int n; 5 | scanf("%d",&n); 6 | int d=100000,x,ans=0; 7 | head[d]=1; 8 | for(int i=2;i<=n+1;++i){ 9 | scanf("%d",&x); 10 | d+=(x?1:-1); 11 | if(head[d]){ 12 | if(ans 2 | #include 3 | const int size=16001; 4 | struct Edge{ 5 | int to,next; 6 | } E[size<<1]; 7 | int last[size]={},cnt=0,w[size],ans=-2147483647; 8 | void addEdge(int u,int v){ 9 | ++cnt; 10 | E[cnt].to=v,E[cnt].next=last[u]; 11 | last[u]=cnt; 12 | } 13 | int DFS(int x,int p){ 14 | int res=w[x]; 15 | for(int i=last[x];i;i=E[i].next) 16 | if(E[i].to!=p) 17 | res+=std::max(0,DFS(E[i].to,x)); 18 | ans=std::max(ans,res); 19 | return res; 20 | } 21 | int main(){ 22 | int n; 23 | scanf("%d",&n); 24 | for(int i=1;i<=n;++i) 25 | scanf("%d",&w[i]); 26 | int u,v; 27 | for(int i=1;i 2 | int lowbit(int x){ 3 | while(x%10==0)x/=10; 4 | return x%10; 5 | } 6 | int powm(int a,int k){ 7 | int res=1; 8 | while(k){ 9 | if(k&1)res=res*a%10; 10 | k>>=1,a=a*a%10; 11 | } 12 | return res; 13 | } 14 | int main(){ 15 | int n,x=1,y,c2=0,c5=0; 16 | scanf("%d",&n); 17 | for(int i=2;i<=n;++i){ 18 | y=i; 19 | while(!(y&1))y>>=1,++c2; 20 | while(y%5==0)y/=5,++c5; 21 | x=x*y%10; 22 | } 23 | if(c2>c5)x=x*powm(2,c2-c5)%10; 24 | else x=x*powm(5,c5-c2)%10; 25 | printf("%d\n",x); 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Unclassified/Done/1159.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char name[100][101],code[21]; 4 | std::queue u,d; 5 | bool lock[100]={}; 6 | int main(){ 7 | int n; 8 | scanf("%d",&n); 9 | for(int i=0;i 2 | #include 3 | bool flag[1001][1001]; 4 | int cnt[1001][1001]={}; 5 | const int mod=100003; 6 | int main(){ 7 | memset(flag,1,sizeof(flag)); 8 | int n,m; 9 | scanf("%d%d",&n,&m); 10 | int x,y; 11 | for(int i=0;i 2 | int P[100][2]; 3 | int calc(int a,int b){ 4 | int dax=P[0][0]-P[a][0], 5 | day=P[0][1]-P[a][1], 6 | dbx=P[0][0]-P[b][0], 7 | dby=P[0][1]-P[b][1]; 8 | return dax*dby-day*dbx; 9 | } 10 | int main(){ 11 | int n; 12 | scanf("%d",&n); 13 | for(int i=0;i>1); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Unclassified/Done/1191.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int sum[151][151]={}; 3 | char buf[160]; 4 | int query(int bx,int by,int ex,int ey){ 5 | return sum[ex][ey]-sum[ex][by]-sum[bx][ey]+sum[bx][by]; 6 | } 7 | int main(){ 8 | int n,ans=0; 9 | scanf("%d",&n); 10 | for(int i=1;i<=n;++i){ 11 | scanf("%s",buf+1); 12 | for(int j=1;j<=n;++j) 13 | sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+(buf[j]=='W'); 14 | } 15 | for(int i=0;i 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | const int size=200005; 13 | int id[size],dfs[size]; 14 | bool flag[size]={}; 15 | int main(){ 16 | int n=read(); 17 | for(int i=1;i<=n;++i)id[read()]=i; 18 | for(int i=1;i<=n;++i)dfs[i]=id[read()]; 19 | int ans=4,l=2,r=n+1,siz=2; 20 | flag[1]=flag[2]=true; 21 | for(int i=3;i<=n;++i){ 22 | if(dfs[i]>1,ans&1?5:0); 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Unclassified/Done/1284.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int A[40]; 4 | bool flag[810][810]={}; 5 | int S(int a,int b,int c){ 6 | double p=(a+b+c)/2.0; 7 | double s2=p*(p-a)*(p-b)*(p-c); 8 | return s2>0.0?static_cast(sqrt(s2)*100.0):-1; 9 | } 10 | int main(){ 11 | int n,len=0; 12 | scanf("%d",&n); 13 | for(int i=0;i>1,ans=-1; 18 | flag[0][0]=true; 19 | for(int i=0;i=0;--j) 21 | for(int k=len-j-1;k>=0;--k){ 22 | flag[j][k]|=(j>=A[i] && flag[j-A[i]][k]); 23 | flag[j][k]|=(k>=A[i] && flag[j][k-A[i]]); 24 | if(flag[j][k]){ 25 | int s=S(j,k,len-j-k); 26 | if(ans 2 | int n,k,len[10000]; 3 | bool check(int x){ 4 | if(x==0)return false; 5 | int cnt=k; 6 | for(int i=0;i0;++i) 7 | cnt-=len[i]/x; 8 | return cnt<=0; 9 | } 10 | void CAS(int& a,int b){ 11 | if(a>1; 24 | if(check(mid))l=mid+1,CAS(ans,mid); 25 | else r=mid-1; 26 | } 27 | int a=ans/100; 28 | int b=(ans%100)/10; 29 | int c=ans%10; 30 | printf("%d.%d%d",a,b,c); 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Unclassified/Done/1336.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | long long dp[201]; 4 | int A[21],B[21]; 5 | void CAS(long long& a,long long b){ 6 | if(a>b)a=b; 7 | } 8 | long long ipow(int a,int k){ 9 | long long res=1; 10 | while(k--)res*=a; 11 | return res; 12 | } 13 | int main(){ 14 | int n,m; 15 | scanf("%d%d",&n,&m); 16 | memset(dp,0x3f,sizeof(dp)); 17 | dp[0]=0; 18 | for(int i=1;i<=m;++i) 19 | scanf("%d%d",&A[i],&B[i]); 20 | 21 | for(int i=1;i<=m;++i) 22 | for(int j=n;j>=1;--j) 23 | for(int k=1;k<=j;++k){ 24 | long long t=A[i]*ipow(k,B[i]); 25 | CAS(dp[j],dp[j-k]+t); 26 | } 27 | 28 | printf("%lld\n",dp[n]); 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Unclassified/Done/1346.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int dis[101][101]; 4 | int main(){ 5 | int n,a,b; 6 | scanf("%d%d%d",&n,&a,&b); 7 | memset(dis,0x3f,sizeof(dis)); 8 | int k,u; 9 | for(int i=1;i<=n;++i){ 10 | scanf("%d",&k); 11 | for(int j=1;j<=k;++j){ 12 | scanf("%d",&u); 13 | dis[i][u]=(j!=1); 14 | } 15 | } 16 | for(int i=1;i<=n;++i) 17 | dis[i][i]=0; 18 | for(int k=1;k<=n;++k) 19 | for(int i=1;i<=n;++i) 20 | if(dis[i][k]!=0x3f3f3f3f) 21 | for(int j=1;j<=n;++j) 22 | if(dis[i][j]>dis[i][k]+dis[k][j]) 23 | dis[i][j]=dis[i][k]+dis[k][j]; 24 | if(dis[a][b]!=0x3f3f3f3f) 25 | printf("%d\n",dis[a][b]); 26 | else 27 | puts("-1"); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Unclassified/Done/1356.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | bool dp[2][100]; 4 | int clamp(int x,int k){ 5 | return (x%k+k)%k; 6 | } 7 | bool foo(){ 8 | memset(dp,0,sizeof(dp)); 9 | int n,k; 10 | scanf("%d%d",&n,&k); 11 | int c=0,x; 12 | scanf("%d",&x); 13 | dp[c][clamp(x,k)]=true; 14 | for(int i=1;i 2 | long long f[2000001]; 3 | int main(){ 4 | int n; 5 | scanf("%d",&n); 6 | long long ans=0; 7 | for(int i=n;i>=1;--i){ 8 | f[i]=n/i; 9 | f[i]*=f[i]; 10 | for(int j=i<<1;j<=n;j+=i)f[i]-=f[j]; 11 | ans+=f[i]*i; 12 | } 13 | ans-=1LL*n*(n+1)/2; 14 | ans>>=1; 15 | printf("%lld\n",ans); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Unclassified/Done/1394.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | bool link[301][301]={},flag[301]={}; 3 | int h[301],n,cnt=0; 4 | void DFS(int x){ 5 | if(flag[x])return; 6 | flag[x]=true; 7 | ++cnt; 8 | for(int i=1;i<=n;++i) 9 | if(link[x][i]) 10 | DFS(i); 11 | } 12 | int main(){ 13 | int m; 14 | scanf("%d%d",&n,&m); 15 | int maxh=0,mi; 16 | for(int i=1;i<=n;++i){ 17 | scanf("%d",&h[i]); 18 | if(maxhh[v])link[u][v]=true; 25 | else if(h[v]>h[u])link[v][u]=true; 26 | } 27 | DFS(mi); 28 | if(cnt==n) printf("Oui, j'ai trouve la solution.\n%d\n",mi); 29 | else puts("Non"); 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Unclassified/Done/1407.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int main(){ 13 | int t=read(); 14 | while(t--){ 15 | int n=read(),cnt=0,x; 16 | for(int i=0;i 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int t[100001],x[100001]; 13 | double maxv(double a,double b){ 14 | return a>b?a:b; 15 | } 16 | int main(){ 17 | int n,k,c,w; 18 | n=read();k=read();c=read();w=read(); 19 | for(int i=1;i<=n;++i){ 20 | t[i]=read(); 21 | x[i]=read(); 22 | } 23 | double ans=0.0,mk=1.0-0.01*k,mc=1.0+0.01*c; 24 | for(int i=n;i>0;--i) 25 | if(t[i]==1)ans=maxv(ans,ans*mk+x[i]); 26 | else ans=maxv(ans,ans*mc-x[i]); 27 | printf("%.2lf\n",ans*w); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Unclassified/Done/1414.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int cnt[1000000]={}; 3 | int main(){ 4 | int n,x,fac=0; 5 | scanf("%d",&n); 6 | for(int i=0;ifac)fac=x; 9 | for(int j=1;j*j<=x;++j) 10 | if(x%j==0){ 11 | ++cnt[j]; 12 | if(j*j!=x)++cnt[x/j]; 13 | } 14 | } 15 | for(int i=1;i<=n;++i){ 16 | while(cnt[fac] 2 | #include 3 | int mat[60][60],dp[2][60][1300]={}; 4 | int maxv(int a,int b){ 5 | return a>b?a:b; 6 | } 7 | void CAS(int& a,int b){ 8 | if(a=1;--i){ 17 | int c=i&1,l=!c,sum=0; 18 | memset(dp[c],0,sizeof(dp[c])); 19 | for(int j=1;j<=n-i+1;++j)sum+=mat[j][i]; 20 | for(int j=n-i+1;j>=0;--j){ 21 | for(int k=maxv(2*j-1,0);k<=m;++k){ 22 | CAS(dp[c][j][k],maxv(dp[c][j+1][k],dp[l][maxv(j-1,0)][k-j]+sum)); 23 | CAS(ans,dp[c][j][k]); 24 | } 25 | sum-=mat[j][i]; 26 | } 27 | } 28 | printf("%d\n",ans); 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Unclassified/Done/1440.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size=2000000; 3 | int v[size],q[size]; 4 | int read(){ 5 | int res=0,c; 6 | do c=getchar(); 7 | while(c<'0'||c>'9'); 8 | while('0'<=c && c<='9'){ 9 | res=res*10+c-'0'; 10 | c=getchar(); 11 | } 12 | return res; 13 | } 14 | int main(){ 15 | int n,m; 16 | n=read(); 17 | m=read(); 18 | for(int i=0;i1){ 25 | while(b 2 | long long f[100001]; 3 | int main(){ 4 | long long n,m,ans=0; 5 | scanf("%lld%lld",&n,&m); 6 | int maxv=n>m?n:m,minv=n=1;--i){ 8 | f[i]=(n/i)*(m/i); 9 | for(int j=i<<1;j<=maxv;j+=i)f[i]-=f[j]; 10 | ans+=f[i]*i; 11 | } 12 | ans+=ans-m*n; 13 | printf("%lld\n",ans); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Unclassified/Done/1450.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | long long dp[100001]={}; 3 | int main(){ 4 | int c[4],tot; 5 | scanf("%d%d%d%d%d",&c[0],&c[1],&c[2],&c[3],&tot); 6 | dp[0]=1; 7 | for(int k=0;k<4;++k) 8 | for(int i=c[k];i<=100000;++i) 9 | dp[i]+=dp[i-c[k]]; 10 | 11 | for(int i=0;i 2 | #include 3 | const int p[12]={2,3,5,7,11,13,17,19,23,29,31,37}; 4 | int n,cnt[5001]; 5 | void DFS(int c,int x,int fac,int mp){ 6 | if(cnt[fac]>x)cnt[fac]=x; 7 | if(c==12)return; 8 | for(int i=1;i<=mp;++i){ 9 | if(1LL*x*p[c]=1;--i) 20 | if(cnt[i]<=n && cnt[i]ans)ans=cnt[i]; 23 | } 24 | printf("%d\n",ans); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Unclassified/Done/1466.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | long long dp[1000]={}; 3 | int main(){ 4 | int n; 5 | scanf("%d",&n); 6 | int sum=(n*(n+1))>>1; 7 | if(sum&1)puts("0"); 8 | else{ 9 | sum>>=1; 10 | dp[0]=1; 11 | for(int i=1;i<=n;++i) 12 | for(int j=sum;j>=i;--j) 13 | dp[j]+=dp[j-i]; 14 | printf("%lld\n",dp[sum]>>1); 15 | } 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Unclassified/Done/1472.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int mod=9901; 3 | int dp[101][201]={}; 4 | int main(){ 5 | int n,k; 6 | scanf("%d%d",&n,&k); 7 | for(int i=1;i<=k;++i) 8 | dp[i][1]=1; 9 | 10 | for(int i=2;i<=k;++i) 11 | for(int j=1;j<=n;j+=2) 12 | for(int l=1;l 2 | const int size=1000001; 3 | int sum[size]={},a[size]; 4 | int main(){ 5 | int n,m; 6 | scanf("%d%d",&n,&m); 7 | for(int i=1;i<=n;++i) 8 | scanf("%d",&a[i]); 9 | int c,x,y; 10 | for(int i=0;i 2 | #include 3 | int stack[50001],cnt=0; 4 | int main(){ 5 | std::set point; 6 | typedef std::set::iterator iter; 7 | int n,m; 8 | scanf("%d%d",&n,&m); 9 | point.insert(0); 10 | point.insert(n+1); 11 | char c[2]; 12 | int x; 13 | for(int i=0;i 2 | #include 3 | double x[100],y[100]; 4 | int main(){ 5 | int n; 6 | double r; 7 | scanf("%d%lf",&n,&r); 8 | for(int i=0;i 2 | typedef long long LL; 3 | LL exgcd(LL a,LL b,LL &x,LL &y,LL &d){ 4 | if(b){ 5 | exgcd(b,a%b,y,x,d); 6 | y-=a/b*x; 7 | } 8 | else x=1,y=0,d=a; 9 | } 10 | LL clamp(LL a,LL m){ 11 | return (a%m+m)%m; 12 | } 13 | int main(){ 14 | LL x,y,m,n,l; 15 | scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l); 16 | LL a=m-n,b=y-x,X,Y,D; 17 | exgcd(a,l,X,Y,D); 18 | if(b%D)puts("Impossible"); 19 | else { 20 | l/=D; 21 | printf("%lld\n",clamp(clamp(X,l)*clamp(b/D,l),l)); 22 | } 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Unclassified/Done/1525.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Edge{ 4 | int u,v,w; 5 | bool operator<(const Edge& rhs) const{ 6 | return w>rhs.w; 7 | } 8 | } E[100000]; 9 | int fa[40010]; 10 | int find(int x){ 11 | return fa[x]==x?x:fa[x]=find(fa[x]); 12 | } 13 | int main(){ 14 | int n,m; 15 | scanf("%d%d",&n,&m); 16 | for(int i=0;i 2 | #include 3 | int sum[2501]={}; 4 | int iabs(int a){ 5 | return a>0?a:-a; 6 | } 7 | bool query(int l,int r,int m){ 8 | int w=iabs(sum[r]-sum[l-1]); 9 | return w==(r-l+1)||w<=m; 10 | } 11 | void CAS(int& a,int b){ 12 | if(a>b)a=b; 13 | } 14 | int dp[2501]; 15 | int main(){ 16 | int n,m,t; 17 | scanf("%d%d",&n,&m); 18 | for(int i=1;i<=n;++i){ 19 | scanf("%d",&t); 20 | if(t==1)sum[i]=1; 21 | else sum[i]=-1; 22 | } 23 | for(int i=1;i<=n;++i) 24 | sum[i]+=sum[i-1]; 25 | memset(dp,0x3f,sizeof(dp)); 26 | dp[0]=0; 27 | for(int i=1;i<=n;++i){ 28 | dp[i]=dp[i-1]+1; 29 | for(int j=0;j 2 | bool gcd(int a,int b){ 3 | return b?gcd(b,a%b):a==1; 4 | } 5 | int A[1000001]; 6 | int main(){ 7 | int n,k,cnt=0; 8 | scanf("%d%d",&n,&k); 9 | --k; 10 | for(int i=1;i 2 | #include 3 | typedef __int128 bint; 4 | void print(bint x){ 5 | if(x>=10)print(x/10); 6 | putchar('0'+x%10); 7 | } 8 | bool flag[1001]={}; 9 | int main(){ 10 | std::deque,std::greater > q; 11 | int n,m; 12 | scanf("%d%d",&n,&m); 13 | for(int i=1;i 2 | int f[10001]; 3 | const int mod=10000; 4 | int powm(int a,int b){ 5 | int res=1; 6 | while(b){ 7 | if(b&1)res=res*a%mod; 8 | b>>=1,a=a*a%mod; 9 | } 10 | return res; 11 | } 12 | void foo(){ 13 | int a,b; 14 | scanf("%d%d",&a,&b); 15 | f[0]=0; 16 | for(int i=1;i<=10000;++i) 17 | f[i]=(f[i-1]+powm(i,b))%mod; 18 | int res=(f[a%mod]+f[10000]*(a/mod)%mod)%mod; 19 | printf("%d\n",res); 20 | } 21 | int main(){ 22 | int n; 23 | scanf("%d",&n); 24 | while(n--)foo(); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Unclassified/Done/1631.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size=100001; 4 | int A[size],B[size]; 5 | struct Node{ 6 | int v,a,b; 7 | bool operator<(const Node& rhs) const{ 8 | return v>rhs.v; 9 | } 10 | }; 11 | std::priority_queue heap; 12 | int main(){ 13 | int n; 14 | scanf("%d",&n); 15 | for(int i=0;i 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int cnt[2001]={}; 13 | int A[1000001]={}; 14 | int main(){ 15 | int n,m; 16 | n=read(); 17 | m=read(); 18 | for(int i=1;i<=n;++i)A[i]=read(); 19 | int w=1<<30,pa=0,pb=0,num=0; 20 | for(int l=1,r=1;r<=n;++r){ 21 | if(++cnt[A[r]]==1)++num; 22 | while(num==m && cnt[A[l]]>1){ 23 | --cnt[A[l]]; 24 | ++l; 25 | } 26 | if(num==m){ 27 | int cw=r-l; 28 | if(cw 2 | const int mod=20100403,size=2000100; 3 | long long fac[size],ifac[size]; 4 | int main(){ 5 | int n,m; 6 | scanf("%d%d",&n,&m); 7 | fac[0]=ifac[0]=ifac[1]=1; 8 | int end=n+m; 9 | for(int i=1;i<=end;++i) 10 | fac[i]=fac[i-1]*i%mod; 11 | for(int i=2;i<=end;++i) 12 | ifac[i]=(mod-mod/i)*ifac[mod%i]%mod; 13 | for(int i=2;i<=end;++i) 14 | ifac[i]=ifac[i-1]*ifac[i]%mod; 15 | long long A=(fac[n+m]*ifac[n]%mod)*ifac[m]%mod; 16 | long long B=(fac[n+m]*ifac[n+1]%mod)*ifac[m-1]%mod; 17 | printf("%lld\n",(A-B+mod)%mod); 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Unclassified/Done/1645.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Range{ 4 | int l,r,c; 5 | bool operator<(Range rhs) const{ 6 | return r0;--j) 21 | if(!flag[j]){ 22 | flag[j]=true; 23 | --A[i].c; 24 | ++cnt; 25 | } 26 | } 27 | printf("%d\n",cnt); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Unclassified/Done/1714.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int s[500001],q[500001],b=0,e=0,m; 3 | void push(int i){ 4 | while(e>b && s[i]'9'); 14 | while('0'<=c&&c<='9'){ 15 | res=res*10+c-'0'; 16 | c=getchar(); 17 | } 18 | return flag?-res:res; 19 | } 20 | int main(){ 21 | int n=read(),ans=-1<<30; 22 | m=read(); 23 | s[0]=0; 24 | for(int i=1;i<=n;++i) 25 | s[i]+=s[i-1]+read(); 26 | push(0); 27 | for(int i=1;i<=n;++i){ 28 | while(i-q[b]>m)++b; 29 | int ps=s[i]-s[q[b]]; 30 | if(ans 2 | long long h[10001]; 3 | void CAS(long long& a,long long b){ 4 | if(a>b && b>0)a=b; 5 | } 6 | const long long fac[4]={2,3,5,7}; 7 | int main(){ 8 | int n,l[4]={1,1,1,1}; 9 | scanf("%d",&n); 10 | h[1]=1; 11 | for(int i=2;i<=n;++i){ 12 | h[i]=1LL<<60; 13 | for(int k=0;k<4;++k){ 14 | for(int j=l[k];j 2 | #include 3 | #include 4 | int prime[50001]; 5 | bool flag[50001],mark[1000010]; 6 | int main(){ 7 | int l,r,cnt=0; 8 | scanf("%d%d",&l,&r); 9 | l=std::max(2,l); 10 | int d=r-l+1; 11 | memset(flag,1,sizeof(flag)); 12 | memset(mark,1,sizeof(mark)); 13 | for(int i=2;1LL*i*i<=r;++i){ 14 | if(flag[i]){ 15 | prime[++cnt]=i; 16 | int begin=std::max(l,i)/i*i; 17 | if(begin 2 | #include 3 | const int size=50000; 4 | int w[size],s[size],id[size]; 5 | bool cmp(int a,int b){ 6 | return w[a]+s[a] 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int A[1000000]; 13 | bool check(int x,int n,int m){ 14 | for(int i=0;ix && (m-=A[i]-x)<=0) 16 | return true; 17 | return false; 18 | } 19 | int main(){ 20 | int n,m; 21 | n=read(); 22 | m=read(); 23 | int l=0,r=0; 24 | for(int i=0;ir)r=A[i]; 27 | } 28 | int ans=0; 29 | while(l<=r){ 30 | int mid=(l+r)>>1; 31 | if(check(mid,n,m))l=mid+1,ans=(ans>mid?ans:mid); 32 | else r=mid-1; 33 | } 34 | printf("%d\n",ans); 35 | return 0; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Unclassified/Done/1892.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int fa[2002]; 3 | int find(int x){ 4 | return fa[x]==x?x:fa[x]=find(fa[x]); 5 | } 6 | int main(){ 7 | int n,m; 8 | scanf("%d%d",&n,&m); 9 | for(int i=1;i<=(n<<1);++i) 10 | fa[i]=i; 11 | char c[2]; 12 | int x,y; 13 | for(int i=0;i 2 | const int size=1000001; 3 | int st[size],ssiz=0,h[size],v[size],tot[size]={}; 4 | void modify(int i){ 5 | while(ssiz && h[st[ssiz-1]]<=h[i])--ssiz; 6 | if(ssiz)tot[st[ssiz-1]]+=v[i]; 7 | st[ssiz++]=i; 8 | } 9 | int read(){ 10 | int res=0,c; 11 | do c=getchar(); 12 | while(c<'0'||c>'9'); 13 | while('0'<=c&&c<='9'){ 14 | res=res*10+c-'0'; 15 | c=getchar(); 16 | } 17 | return res; 18 | } 19 | int main(){ 20 | int n=read(); 21 | for(int i=1;i<=n;++i){ 22 | h[i]=read(); 23 | v[i]=read(); 24 | } 25 | for(int i=1;i<=n;++i)modify(i); 26 | ssiz=0; 27 | for(int i=n;i>=1;--i)modify(i); 28 | int ans=0; 29 | for(int i=1;i<=n;++i) 30 | if(tot[i]>ans) 31 | ans=tot[i]; 32 | printf("%d\n",ans); 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Unclassified/Done/1975.cpp~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/Done/1975.cpp~ -------------------------------------------------------------------------------- /Unclassified/Done/2032.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int A[2000001],q[2000000],b=0,e=0; 13 | int main(){ 14 | int n,k; 15 | n=read();k=read(); 16 | for(int i=1;i<=n;++i){ 17 | A[i]=read(); 18 | while(b!=e && A[q[e-1]]=k){ 21 | while(i-q[b]>=k)++b; 22 | printf("%d\n",A[q[b]]); 23 | } 24 | } 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Unclassified/Done/2034.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int A[100002],q[100011],b=0,e=1; 13 | long long dp[100001]; 14 | int main(){ 15 | int n=read(); 16 | int k=read(); 17 | long long sum=0; 18 | for(int i=1;i<=n;++i){ 19 | A[i]=read(); 20 | sum+=A[i]; 21 | } 22 | A[n+1]=dp[0]=q[b]=0; 23 | for(int i=1;i<=n+1;++i){ 24 | while(b!=e && q[b]=dp[i])--e; 27 | q[e++]=i; 28 | } 29 | printf("%lld\n",sum-dp[n+1]); 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Unclassified/Done/2054.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long ll; 3 | ll powm(ll a,ll k,ll m){ 4 | ll res=1; 5 | while(k){ 6 | if(k&1)res=res*a%m; 7 | k>>=1,a=a*a%m; 8 | } 9 | return res; 10 | } 11 | void exgcd(ll a,ll b,ll& d,ll& x,ll& y){ 12 | if(b){ 13 | exgcd(b,a%b,d,y,x); 14 | y-=a/b*x; 15 | } 16 | else d=a,x=1,y=0; 17 | } 18 | int main(){ 19 | ll n,m,l; 20 | scanf("%lld%lld%lld",&n,&m,&l); 21 | ++n; 22 | ll a=powm(2,m,n),d,x,y; 23 | exgcd(a,n,d,x,y); 24 | printf("%lld\n",((x*l/d)%n+n)%n); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Unclassified/Done/2059.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int A[60]; 3 | double f[60][60]={}; 4 | int main(){ 5 | int n,m; 6 | scanf("%d%d",&n,&m); 7 | for(int i=1;i<=m;++i) 8 | scanf("%d",&A[i]); 9 | f[1][1]=1.0; 10 | for(int i=2;i<=n;++i){ 11 | for(int j=1;j<=n;++j){ 12 | for(int k=1;k<=m;++k){ 13 | int x=A[k]%i; 14 | if(x==0)x=i; 15 | if(jx)f[i][j]+=f[i-1][j-x]/m; 17 | } 18 | } 19 | } 20 | for(int i=1;i<=n;++i) 21 | printf("%.2lf%% ",f[n][i]*100.0); 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Unclassified/Done/2060.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n; 4 | scanf("%d",&n); 5 | n=n<<1|1; 6 | int cnt=0,a=1; 7 | do ++cnt,a=(a<<1)%n; 8 | while(a!=1); 9 | printf("%d",cnt); 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Unclassified/Done/2062.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size=1000001; 4 | int A[size],f1[size]={},f2[size]={}; 5 | int main(){ 6 | int n; 7 | scanf("%d",&n); 8 | for(int i=1;i<=n;++i) 9 | scanf("%d",&A[i]); 10 | std::sort(A+1,A+n+1); 11 | for(int i=1;i<=n;++i){ 12 | if(i>=A[i])f1[i]=f2[i-A[i]]+1; 13 | f2[i]=std::max(f1[i],f2[i-1]); 14 | } 15 | printf("%d",f1[n]); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Unclassified/Done/2071.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size=4001; 4 | int p[size][2],pair[size][2]={}; 5 | bool flag[size]={}; 6 | bool match(int u){ 7 | for(int i=0;i<2;++i){ 8 | int v=p[u][i]; 9 | if(!flag[v]){ 10 | flag[v]=true; 11 | if(!pair[v][0] || match(pair[v][0])){ 12 | pair[v][0]=u; 13 | return true; 14 | } 15 | if(!pair[v][1] || match(pair[v][1])){ 16 | pair[v][1]=u; 17 | return true; 18 | } 19 | } 20 | } 21 | return false; 22 | } 23 | int main(){ 24 | int n,cnt=0; 25 | scanf("%d",&n); 26 | n<<=1; 27 | for(int i=1;i<=n;++i) 28 | scanf("%d%d",&p[i][0],&p[i][1]); 29 | for(int i=1;i<=n;++i){ 30 | memset(flag,0,sizeof(flag)); 31 | cnt+=match(i); 32 | } 33 | printf("%d\n",cnt); 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Unclassified/Done/2082.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Line{ 4 | long long l,r; 5 | bool operator<(const Line& rhs) const{ 6 | return l'9'); 14 | while('0'<=c&&c<='9'){ 15 | res=res*10+c-'0'; 16 | c=getchar(); 17 | } 18 | return res; 19 | } 20 | int main(){ 21 | int n=read(); 22 | for(int i=0;i 2 | #include 3 | #include 4 | const int size=10000; 5 | int a[size],b[size],c[size],cnt[size]; 6 | long long v[size]; 7 | struct cmp{ 8 | bool operator()(int lhs,int rhs) const{ 9 | return v[lhs]>v[rhs]; 10 | } 11 | }; 12 | std::priority_queue,cmp> heap; 13 | int main(){ 14 | int n,m; 15 | scanf("%d%d",&n,&m); 16 | for(int i=0;i 2 | #include 3 | int main(){ 4 | int n,k,x; 5 | scanf("%d%d",&n,&k); 6 | std::priority_queue heap; 7 | for(int i=0;i1){ 12 | int t1=heap.top();heap.pop(); 13 | int t2=heap.top();heap.pop(); 14 | heap.push((t1+t2)/k); 15 | } 16 | printf("%d\n",heap.top()); 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Unclassified/Done/2115.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | long long S[100001]={}; 3 | bool check(double x,int n){ 4 | //S[n]-S[r]+S[l-1]<=x(n+r-l+1) 5 | //(S[n]-xn)-(S[r]-xr)+(S[l-1]-x(l-1))<=0 6 | double c=S[n]-x*n,minv=S[1]-x; 7 | for(int i=2;isub)minv=sub; 11 | } 12 | return false; 13 | } 14 | int main(){ 15 | int n,x,maxv=0; 16 | scanf("%d",&n); 17 | for(int i=1;i<=n;++i){ 18 | scanf("%d",&x); 19 | if(x>maxv)maxv=x; 20 | S[i]=S[i-1]+x; 21 | } 22 | double l=0.0,r=maxv; 23 | while(r-l>=0.0001){ 24 | double mid=(l+r)/2.0; 25 | if(check(mid,n))r=mid; 26 | else l=mid; 27 | } 28 | printf("%.3lf\n",l); 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Unclassified/Done/2148.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | const int size=20100; 13 | int sg(int x,int y){ 14 | long long res=0,half=1,mod=2; 15 | while(true){ 16 | if(x%mod 2 | int sg(int x,int y){ 3 | int res=0,vis[500]={}; 4 | for(int i=1;i 2 | int A[2][100001]={},n; 3 | void add(int x,int p){ 4 | while(x<=n){ 5 | ++A[p][x]; 6 | x+=x&-x; 7 | } 8 | } 9 | int query(int x,int p){ 10 | int ans=0; 11 | while(x){ 12 | ans+=A[p][x]; 13 | x-=x&-x; 14 | } 15 | return ans; 16 | } 17 | int main(){ 18 | int m; 19 | scanf("%d%d",&n,&m); 20 | int c,l,r; 21 | for(int i=0;i 2 | #include 3 | #include 4 | int v[21],g[101],dp[100001]; 5 | int main(){ 6 | int n,b; 7 | scanf("%d%d",&n,&b); 8 | for(int i=1;i<=b;++i) 9 | scanf("%d",&v[i]); 10 | for(int i=1;i<=n;++i) 11 | scanf("%d",&g[i]); 12 | int maxg=0; 13 | for(int i=n;i>=1;--i){ 14 | g[i]-=std::max(g[i-1]-1,0); 15 | maxg=std::max(maxg,g[i]); 16 | } 17 | memset(dp,0x3f,sizeof(dp)); 18 | dp[0]=0; 19 | for(int i=1;i<=b;++i) 20 | for(int j=v[i];j<=maxg;++j) 21 | dp[j]=std::min(dp[j],dp[j-v[i]]+1); 22 | int ans=0; 23 | for(int i=1;i<=n;++i){ 24 | if(dp[g[i]]==0x3f3f3f3f){ 25 | puts("-1"); 26 | return 0; 27 | } 28 | ans+=dp[g[i]]; 29 | } 30 | printf("%d\n",ans); 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Unclassified/Done/2255.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Range{ 4 | int l,r; 5 | bool operator<(Range rhs) const{ 6 | return r=std::min(l,r)){ 18 | ++cnt; 19 | if(task[i].l>=l && task[i].l>=r){ 20 | if(l=l)l=task[i].r; 24 | else r=task[i].r; 25 | } 26 | printf("%d\n",cnt); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Unclassified/Done/2261.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | int n,k; 5 | scanf("%d%d",&n,&k); 6 | long long ans=0,rk=sqrt(k); 7 | for(int i=1;i<=k/rk && i<=n;++i) 8 | ans+=k%i; 9 | for(int i=1;in)e=n; 14 | ans+=1LL*(e-b+1)*(k%b+k%e)/2; 15 | } 16 | } 17 | if(n>k)ans+=1LL*(n-k)*k; 18 | printf("%lld\n",ans); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Unclassified/Done/2320.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | int m; 5 | scanf("%d",&m); 6 | std::multiset A; 7 | while(m){ 8 | A.insert((m+1)>>1); 9 | m>>=1; 10 | } 11 | printf("%d\n",static_cast(A.size())); 12 | for(std::multiset::iterator it=A.begin();it!=A.end();++it) 13 | printf("%d ",*it); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Unclassified/Done/2327.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int A[10001],f[10001]; 3 | int main(){ 4 | int n,ans=0; 5 | scanf("%d",&n); 6 | for(int i=1;i<=n;++i) 7 | scanf("%d",&A[i]); 8 | for(int b=0;b<=1;++b){ 9 | f[1]=b; 10 | f[2]=A[1]-f[1]; 11 | bool flag=true; 12 | for(int i=3;i<=n;++i){ 13 | f[i]=A[i-1]-f[i-1]-f[i-2]; 14 | if(f[i]!=0 && f[i]!=1){ 15 | flag=false; 16 | break; 17 | } 18 | } 19 | if(A[n]==f[n]+f[n-1])ans+=flag; 20 | } 21 | printf("%d\n",ans); 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Unclassified/Done/2342.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size=30001; 3 | int fa[size],siz[size],depth[size]; 4 | int find(int x){ 5 | if(fa[x]!=x){ 6 | int p=find(fa[x]); 7 | depth[x]+=depth[fa[x]]-1; 8 | fa[x]=p; 9 | } 10 | return fa[x]; 11 | } 12 | //a->b 13 | void move(int a,int b){ 14 | depth[b]=siz[a]+1; 15 | siz[a]+=siz[b]; 16 | fa[b]=a; 17 | } 18 | int main(){ 19 | int n; 20 | scanf("%d",&n); 21 | for(int i=1;i 2 | #include 3 | #include 4 | using namespace std; 5 | double length2(double x,double y){ 6 | return x*x+y*y; 7 | } 8 | void CAS(double& a,double x,double y){ 9 | double l=length2(x,y); 10 | a=min(a,l); 11 | } 12 | int main(){ 13 | double bx,by,ex,ey; 14 | scanf("%lf%lf%lf%lf",&bx,&by,&ex,&ey); 15 | double ans=100.0; 16 | CAS(ans,bx-ex,(0.5-by)+(0.5-ey)+1.0); 17 | CAS(ans,bx-ex,(by+0.5)+(ey+0.5)+1.0); 18 | CAS(ans,by-ey,(0.5-bx)+(0.5-ex)+1.0); 19 | CAS(ans,by-ey,(bx+0.5)+(ex+0.5)+1.0); 20 | printf("%.3lf\n",sqrt(ans)); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Unclassified/Done/2359.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int mod=1000000009; 3 | int dp[10001][100]={},prime[1001],cnt=0; 4 | bool isPrime(int x){ 5 | for(int i=2;i*i<=x;++i) 6 | if(x%i==0) 7 | return false; 8 | return true; 9 | } 10 | int main(){ 11 | int n; 12 | scanf("%d",&n); 13 | for(int i=101;i<1000;++i) 14 | if(isPrime(i)){ 15 | prime[cnt++]=i; 16 | ++dp[3][i%100]; 17 | } 18 | 19 | for(int i=4;i<=n;++i) 20 | for(int j=0;j 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int A[5000010],S[5000010]={}; 13 | int main(){ 14 | int n,p; 15 | n=read(); 16 | p=read(); 17 | for(int i=1;i<=n;++i)A[i]=read(); 18 | int l,r,w; 19 | for(int i=0;i 2 | int main(){ 3 | int n; 4 | scanf("%d",&n); 5 | long long cnt=0,ans=0; 6 | for(int i=1;i<=n;++i){ 7 | int x=i; 8 | while(x%5==0)++cnt,x/=5; 9 | ans+=cnt; 10 | } 11 | printf("%lld\n",ans); 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Unclassified/Done/2391.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int fa[1000001]={},col[1000001]={}; 5 | int find(int x){ 6 | return fa[x]?fa[x]=find(fa[x]):x; 7 | } 8 | void print(int x){ 9 | if(x>=10)print(x/10); 10 | putchar('0'+x%10); 11 | } 12 | int main(){ 13 | int n,m,p,q; 14 | scanf("%d%d%d%d",&n,&m,&p,&q); 15 | 16 | for(int i=m;i>=1;--i){ 17 | int l=(1ll*i*p+q)%n+1,r=(1ll*i*q+p)%n+1; 18 | if(l>r)std::swap(l,r); 19 | l=find(l); 20 | while(l<=r){ 21 | col[l]=i; 22 | fa[l]=l+1; 23 | l=find(l+1); 24 | } 25 | } 26 | 27 | for(int i=1;i<=n;++i){ 28 | print(col[i]); 29 | putchar('\n'); 30 | } 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Unclassified/Done/2394.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | long double x; 4 | scanf("%.20lf",&x); 5 | printf("%.8lf",x/23.0L); 6 | return 0; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Unclassified/Done/2397.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n,x,cnt=0,now; 4 | scanf("%d",&n); 5 | for(int i=0;i 2 | long long f[100001]; 3 | int main(){ 4 | int n; 5 | scanf("%d",&n); 6 | long long ans=0; 7 | for(int i=n;i>=1;--i){ 8 | f[i]=n/i; 9 | f[i]*=f[i]; 10 | for(int j=i<<1;j<=n;j+=i)f[i]-=f[j]; 11 | ans+=f[i]*i; 12 | } 13 | printf("%lld\n",ans); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Unclassified/Done/2401.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[1001][1001]; 3 | int main(){ 4 | int n,k; 5 | scanf("%d%d",&n,&k); 6 | for(int i=0;i<=n;++i)dp[i][0]=1; 7 | for(int i=2;i<=n;++i) 8 | for(int j=1;j<=k && j 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int A[100001]; 13 | long long S[100001]; 14 | int main(){ 15 | int n=read(); 16 | for(int i=1;i<=n;++i){ 17 | A[i]=read(); 18 | S[i]=S[i-1]+A[i]; 19 | } 20 | long long ans=0; 21 | for(int i=1;i<=n;++i){ 22 | int l=i,r=i; 23 | while(l>1 && A[l-1]>=A[i])--l; 24 | while(r=A[i])++r; 25 | long long v=A[i]*(S[r]-S[l-1]); 26 | if(v>ans)ans=v; 27 | } 28 | printf("%lld\n",ans); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Unclassified/Done/2467.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[2][4300]={}; 3 | int main(){ 4 | int n,p; 5 | scanf("%d%d",&n,&p); 6 | dp[1][1]=1; 7 | for(int i=2;i<=n;++i){ 8 | int c=i&1,l=c^1; 9 | for(int j=1;j<=i;++j) 10 | dp[c][j]=(dp[c][j-1]+dp[l][i-j+1])%p; 11 | } 12 | int res=0; 13 | for(int i=1;i<=n;++i) 14 | res=(res+dp[n&1][i])%p; 15 | printf("%d\n",(res<<1)%p); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Unclassified/Done/2473.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | double dp[101][1<<15]={}; 3 | int w[15],mask[15]={}; 4 | double maxv(double a,double b){ 5 | return a>b?a:b; 6 | } 7 | int main(){ 8 | int k,n; 9 | scanf("%d%d",&k,&n); 10 | int end=1<=0;--i) 21 | for(int j=0;j 2 | #include 3 | const int size=60,nil=55; 4 | int L[size]={},R[size]={},fa[size]={},root,ans[size],top=0; 5 | int main(){ 6 | int n; 7 | scanf("%d",&n); 8 | fa[0]=nil; 9 | for(int i=1;i<=n;++i){ 10 | int p; 11 | scanf("%d",&p); 12 | if(p<100)L[p]=i,fa[i]=p; 13 | else R[p-100]=i,fa[i]=p-100; 14 | } 15 | root=0; 16 | for(int i=n;i>=0;--i){ 17 | int x=root; 18 | while(R[x])x=L[x]; 19 | if(L[x] && !L[L[x]] && !R[L[x]])x=L[x]; 20 | ans[top++]=x; 21 | if(x==root)root=L[x]; 22 | int p=fa[x]; 23 | L[p]=L[x]; 24 | if(L[x])fa[L[x]]=p; 25 | while(p!=nil){ 26 | std::swap(L[p],R[p]); 27 | p=fa[p]; 28 | } 29 | } 30 | while(top)printf("%d ",ans[--top]); 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Unclassified/Done/2496Unknown.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/Done/2496Unknown.cpp -------------------------------------------------------------------------------- /Unclassified/Done/2508.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | long long gcd(long long a,long long b){ 4 | return b?gcd(b,a%b):a; 5 | } 6 | long long ans=0; 7 | void calc(long long d){ 8 | long long end=d>>1; 9 | long long last=0; 10 | for(long long a=1;a*a<=end;++a){ 11 | long long a2=a*a,b=sqrt(d-a2),b2=b*b; 12 | if(a!=b && b!=last && a2+b2==d && gcd(a2,b2)==1){ 13 | ++ans; 14 | last=b; 15 | } 16 | } 17 | } 18 | int main(){ 19 | long long r; 20 | scanf("%lld",&r); 21 | long long end=2*r; 22 | for(long long i=1;i*i<=end;++i) 23 | if(end%i==0){ 24 | calc(end/i); 25 | if(end/i!=i)calc(i); 26 | } 27 | printf("%lld\n",(ans+1)<<2); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Unclassified/Done/2512.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int read(){ 4 | int res=0,c; 5 | do c=getchar(); 6 | while(c<'0'||c>'9'); 7 | while('0'<=c&&c<='9'){ 8 | res=res*10+c-'0'; 9 | c=getchar(); 10 | } 11 | return res; 12 | } 13 | const int size=1000001; 14 | int A[size]; 15 | long long B[size]; 16 | long long iabs(long long x){ 17 | return x>0?x:-x; 18 | } 19 | int main(){ 20 | int n=read(); 21 | long long sum=0; 22 | for(int i=0;i 2 | int dp[1001][1001]={}; 3 | void add(int& a,int b){ 4 | a=(a+b)%10000; 5 | } 6 | int main(){ 7 | int n,k; 8 | scanf("%d%d",&n,&k); 9 | dp[1][0]=1; 10 | for(int i=1;i 2 | int dp[1001][1001]={}; 3 | const int mod=10000; 4 | int main(){ 5 | int n,k; 6 | scanf("%d%d",&n,&k); 7 | dp[1][0]=1; 8 | for(int i=2;i<=n;++i){ 9 | int end=i*(i-1)/2; 10 | dp[i][0]=1; 11 | for(int j=1;j<=end && j<=k;++j) 12 | dp[i][j]=(dp[i][j-1]+dp[i-1][j]+(j>=i?-dp[i-1][j-i]:0))%mod; 13 | } 14 | int ans=(dp[n][k]%mod+mod)%mod; 15 | printf("%d",ans); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Unclassified/Done/2520.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int gcd(int a,int b){ 3 | return b?gcd(b,a%b):a; 4 | } 5 | int read(){ 6 | int res=0,c; 7 | bool flag=false; 8 | do{ 9 | c=getchar(); 10 | flag|=c=='-'; 11 | }while(c<'0'||c>'9'); 12 | while('0'<=c&&c<='9'){ 13 | res=res*10+c-'0'; 14 | c=getchar(); 15 | } 16 | return flag?-res:res; 17 | } 18 | bool check(int a,int b,int d){ 19 | return a%d==0 && b%d==0; 20 | } 21 | int main(){ 22 | int n=read(); 23 | for(int i=0,a,b,x,y,d;i 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | int calc(int a,int b,int k){ 13 | return b/k-(a-1)/k; 14 | } 15 | int maxv(int a,int b){ 16 | return a>b?a:b; 17 | } 18 | long long f[50001]; 19 | void foo(){ 20 | int a=read(); 21 | int b=read(); 22 | int c=read(); 23 | int d=read(); 24 | int k=read(); 25 | int end=maxv(maxv(a,b),maxv(c,d))/k; 26 | for(int i=end;i>0;--i){ 27 | f[i]=1LL*calc(a,b,k*i)*calc(c,d,k*i); 28 | for(int j=i*2;j<=end;j+=i)f[i]-=f[j]; 29 | } 30 | printf("%lld\n",f[1]); 31 | } 32 | int main(){ 33 | int n=read(); 34 | for(int i=0;i 2 | const int size=10000010; 3 | int prime[1000010],pcnt; 4 | long long phi[size]; 5 | bool flag[size]; 6 | void pre(int n){ 7 | phi[1]=1; 8 | for(int i=2;i<=n;++i){ 9 | if(!flag[i])prime[++pcnt]=i,phi[i]=i-1; 10 | for(int j=1;j<=pcnt && prime[j]*i<=n;++j){ 11 | flag[prime[j]*i]=true; 12 | if(i%prime[j]==0){ 13 | phi[i*prime[j]]=phi[i]*prime[j]; 14 | break; 15 | } 16 | phi[i*prime[j]]=phi[i]*(prime[j]-1); 17 | } 18 | } 19 | } 20 | int main(){ 21 | int n; 22 | scanf("%d",&n); 23 | pre(n); 24 | for(int i=2;i<=n;++i) 25 | phi[i]+=phi[i-1]+phi[i]; 26 | long long ans=0; 27 | for(int i=1;i<=pcnt;++i){ 28 | int siz=n/prime[i]; 29 | ans+=phi[siz]; 30 | } 31 | printf("%lld\n",ans); 32 | return 0; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Unclassified/Done/2568tmp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int gcd(int a,int b){ 3 | return b?gcd(b,a%b):a; 4 | } 5 | int main(){ 6 | int n; 7 | scanf("%d",&n); 8 | for(int k=1;k<=n;++k){ 9 | int cnt=0; 10 | for(int i=1;i<=k;++i) 11 | for(int j=1;j<=k;++j) 12 | if(gcd(i,j)==1)++cnt; 13 | printf("%d %d\n",k,cnt); 14 | } 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Unclassified/Done/2592.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[310][151][21][21]={}; 3 | void add(int& a,int b){ 4 | a=(a+b)%12345678; 5 | } 6 | int maxv(int a,int b){ 7 | return a>b?a:b; 8 | } 9 | int main(){ 10 | int n,m,k; 11 | scanf("%d%d%d",&n,&m,&k); 12 | dp[0][0][0][0]=1; 13 | for(int i=0;i 2 | int read(){ 3 | int c; 4 | do c=getchar(); 5 | while(c!='H' && c!='T'); 6 | return c; 7 | } 8 | int sg(int i,int j){ 9 | if(i && j)return i+j; 10 | int k=i+j+1,cnt=0; 11 | while(!(k&(1< 2 | const int mod=19260817; 3 | const long long end=1LL<<58; 4 | int read(){ 5 | long long res=0; 6 | int c; 7 | do c=getchar(); 8 | while(c<'0'||c>'9'); 9 | while('0'<=c&&c<='9'){ 10 | res=res*10+c-'0'; 11 | if(res>=end)res%=mod; 12 | c=getchar(); 13 | } 14 | return res%mod; 15 | } 16 | long long inv(long long a){ 17 | long long res=1; 18 | int k=mod-2; 19 | while(k){ 20 | if(k&1)res=res*a%mod; 21 | k>>=1,a=a*a%mod; 22 | } 23 | return res; 24 | } 25 | int main(){ 26 | int a=read(); 27 | int b=read(); 28 | if(b)printf("%lld\n",a*inv(b)%mod); 29 | else puts("Angry!"); 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Unclassified/Done/2613B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int A[5000]; 3 | bool check(int x,int n,int m){ 4 | if(x<=0)return false; 5 | for(int i=0;ir)r=A[i]; 18 | } 19 | int ans=1; 20 | while(l<=r){ 21 | int mid=(l+r)>>1; 22 | if(check(mid,n,m))ans=mid,l=mid+1; 23 | else r=mid-1; 24 | } 25 | printf("%d\n",ans); 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Unclassified/Done/2629.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int read(){ 4 | int res=0,c; 5 | bool flag=false; 6 | do{ 7 | c=getchar(); 8 | flag|=c=='-'; 9 | }while(c<'0'||c>'9'); 10 | while('0'<=c&&c<='9'){ 11 | res=res*10+c-'0'; 12 | c=getchar(); 13 | } 14 | return flag?-res:res; 15 | } 16 | const int size=1000010; 17 | int A[size],S[size],L[size],R[size]; 18 | int main(){ 19 | int n=read(); 20 | for(int i=1;i<=n;++i){ 21 | A[i]=read(); 22 | S[i]=S[i-1]+A[i]; 23 | } 24 | L[0]=R[n+1]=1<<30; 25 | for(int i=1;i<=n;++i)L[i]=std::min(S[i],L[i-1]); 26 | for(int i=n;i>=1;--i)R[i]=std::min(A[i],R[i+1]+A[i]); 27 | int ans=0; 28 | for(int i=1;i<=n;++i) 29 | if(L[i-1]+(S[n]-S[i-1])>=0&&R[i]>=0)++ans; 30 | printf("%d\n",ans); 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Unclassified/Done/2667.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int prime[10000],cnt=1; 3 | bool test(int x){ 4 | if(x==1)return false; 5 | for(int i=0;iprime[i];++i) 6 | if(x%prime[i]==0)return false; 7 | return true; 8 | } 9 | void pre(){ 10 | prime[0]=2; 11 | for(int i=3;i<=10000;i+=2) 12 | if(test(i))prime[cnt++]=i; 13 | } 14 | int vec[100000]; 15 | int main(){ 16 | pre(); 17 | int n,p=0,siz=1; 18 | vec[0]=0; 19 | scanf("%d",&n); 20 | if(n>2)vec[siz++]=2; 21 | while(p 2 | #include 3 | int d[511]={},cnt[511][511]={},id[1500],pc=0,l=500,r=1; 4 | void dfs(int u){ 5 | for(int v=l;v<=r;++v) 6 | if(cnt[u][v]){ 7 | --cnt[u][v],--cnt[v][u]; 8 | dfs(v); 9 | } 10 | id[++pc]=u; 11 | } 12 | int main(){ 13 | int n; 14 | scanf("%d",&n); 15 | int u,v; 16 | for(int i=0;i0;--i) 31 | printf("%d\n",id[i]); 32 | return 0; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Unclassified/Done/2734.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int a[201],sum[201],dp[201][201]; 4 | int query(int l,int r){ 5 | return sum[r]-sum[l-1]; 6 | } 7 | int main(){ 8 | int n; 9 | scanf("%d",&n); 10 | for(int i=1;i<=n;++i){ 11 | scanf("%d",&a[i]); 12 | sum[i]=sum[i-1]+a[i]; 13 | dp[i][i]=a[i]; 14 | } 15 | for(int k=1;k 2 | #include 3 | int main(){ 4 | int n; 5 | scanf("%d",&n); 6 | --n; 7 | long long l=1,r=1LL<<60,ans; 8 | while(l<=r){ 9 | long long mid=(l+r)>>1; 10 | if(mid*log10(1.0l+mid)>=n)ans=mid,r=mid-1; 11 | else l=mid+1; 12 | } 13 | printf("%lld\n",ans); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Unclassified/Done/2777.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int read(){ 4 | int res=0,c; 5 | do c=getchar(); 6 | while(c<'0'||c>'9'); 7 | while('0'<=c&&c<='9'){ 8 | res=res*10+c-'0'; 9 | c=getchar(); 10 | } 11 | return res; 12 | } 13 | int A[300001]; 14 | int main(){ 15 | int n=read(); 16 | for(int i=0;i=0;--i){ 21 | if(A[i]+n>=minv)++ans; 22 | else break; 23 | minv=std::max(minv,A[i]+(n-i)); 24 | } 25 | printf("%d\n",ans); 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Unclassified/Done/2835.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | bool in[201]={}; 3 | int main(){ 4 | int n; 5 | scanf("%d",&n); 6 | for(int i=1;i<=n;++i){ 7 | int c; 8 | scanf("%d",&c); 9 | while(c){ 10 | in[c]=true; 11 | scanf("%d",&c); 12 | } 13 | } 14 | int ans=0; 15 | for(int i=1;i<=n;++i) 16 | ans+=!in[i]; 17 | printf("%d\n",(ans?ans:1)); 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Unclassified/Done/2842.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | long long powm(long long a,long long k,long long m){ 3 | a%=m; 4 | long long res=1; 5 | while(k){ 6 | if(k&1)res=res*a%m; 7 | k>>=1,a=a*a%m; 8 | } 9 | return res; 10 | } 11 | const long long P=1000000007LL; 12 | int main(){ 13 | long long a,b; 14 | scanf("%lld%lld",&a,&b); 15 | //a#b=a^(a^(b-1)) 16 | //a^(p-1) mod P =1 17 | //a#b mod P = a^(a^(b-1) mod (P-1)) mod P 18 | long long k=powm(a,b-1,P-1); 19 | long long res=powm(a,k,P); 20 | printf("%lld\n",res); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Unclassified/Done/2879.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int sum[10002]; 5 | pair input[10000]; 6 | int main(){ 7 | int N,I,H,R; 8 | scanf("%d%d%d%d",&N,&I,&H,&R); 9 | int a,b; 10 | for(int i=0;ib)swap(a,b); 13 | input[i]=make_pair(a+1,b); 14 | } 15 | sort(input,input+R); 16 | int siz=unique(input,input+R)-input; 17 | for(int i=0;i 2 | int fa[50000]; 3 | int find(int x){ 4 | return fa[x]==x?x:fa[x]=find(fa[x]); 5 | } 6 | int read(){ 7 | int res=0,c; 8 | do c=getchar(); 9 | while(c<'0'||c>'9'); 10 | while('0'<=c&&c<='9'){ 11 | res=res*10+c-'0'; 12 | c=getchar(); 13 | } 14 | return res; 15 | } 16 | int main(){ 17 | int n,m; 18 | n=read(); 19 | m=read(); 20 | for(int i=1;i<50000;++i) 21 | fa[i]=i; 22 | for(int i=1;i<=n;++i){ 23 | int k=read(); 24 | for(int j=0;j 2 | #include 3 | const int size=50000; 4 | bool flag=true; 5 | struct Cow{ 6 | int p,c; 7 | bool operator<(Cow rhs) const{ 8 | if(flag)return c=cow[i].c) 21 | m-=cow[i].c; 22 | else{ 23 | printf("%d\n",i); 24 | return 0; 25 | } 26 | std::sort(cow+k,cow+n); 27 | for(int i=k;i=cow[i].p)m-=cow[i].p; 29 | else{ 30 | printf("%d\n",i); 31 | return 0; 32 | } 33 | printf("%d\n",n); 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Unclassified/Done/3048.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int p[11],k; 3 | bool add(int i){ 4 | if(p[i]+1==p[i+1]){ 5 | if(add(i+1)){ 6 | for(int j=0;j<=i;++j) 7 | p[j]=j; 8 | return false; 9 | } 10 | } 11 | else { 12 | ++p[i]; 13 | return true; 14 | } 15 | } 16 | int main(){ 17 | int n; 18 | scanf("%d%d",&n,&k); 19 | for(int i=0;i=0;--i){ 23 | putchar('1'); 24 | for(int j=p[i]-(i?p[i-1]+1:0);j>0;--j)putchar('0'); 25 | } 26 | puts(""); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Unclassified/Done/3093.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Cow{ 4 | int t,w; 5 | bool operator<(Cow rhs) const{ 6 | return t 2 | #include 3 | struct Cow{ 4 | int t,w; 5 | bool operator<(Cow rhs) const{ 6 | return t==rhs.t?w>rhs.w:t 2 | #include 3 | const int size=20; 4 | int h[size],w[size],c[size],dph[1<=H && dpw[i]>ans)ans=dpw[i]; 22 | } 23 | if(ans<0)puts("Mark is too tall"); 24 | else printf("%d\n",ans); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Unclassified/Done/3114.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | struct Line{ 6 | int p,y; 7 | bool operator<(Line rhs) const{ 8 | return p==rhs.p?y Y,saw; 24 | for(int i=0;i0)Y.insert(L[j].y); 27 | else Y.erase(-L[j].y); 28 | if(Y.size())saw.insert(*Y.begin()); 29 | } 30 | printf("%d\n",static_cast(saw.size())); 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Unclassified/Done/3147.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[60][270000]={}; 3 | int main(){ 4 | int n,c; 5 | scanf("%d",&n); 6 | for(int i=1;i<=n;++i){ 7 | scanf("%d",&c); 8 | dp[c][i]=i+1; 9 | } 10 | int ans=0; 11 | for(int i=2;i<60;++i) 12 | for(int j=1;j<=n;++j){ 13 | if(!dp[i][j])dp[i][j]=dp[i-1][dp[i-1][j]]; 14 | if(dp[i][j])ans=i; 15 | } 16 | printf("%d\n",ans); 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Unclassified/Done/3152.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n; 4 | scanf("%d",&n); 5 | for(int i=30;i>=0;--i) 6 | if(n&(1< 2 | long long C(long long n){ 3 | return n*(n-1)*(n-2)/6; 4 | } 5 | int gcd(int a,int b){ 6 | return b?gcd(b,a%b):a; 7 | } 8 | int main(){ 9 | int n,m; 10 | scanf("%d%d",&n,&m); 11 | ++n,++m; 12 | long long res=C(n*m)-n*C(m)-m*C(n); 13 | for(int i=1;i 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | const int size=100100,mod=1000000007; 13 | int powm(int a,int k){ 14 | int res=1; 15 | while(k){ 16 | if(k&1)res=1LL*res*a%mod; 17 | k>>=1,a=1LL*a*a%mod; 18 | } 19 | return res; 20 | } 21 | int dp[size]; 22 | int main(){ 23 | int n,k,l,h; 24 | scanf("%d%d%d%d",&n,&k,&l,&h); 25 | l=(l-1)/k; 26 | h/=k; 27 | int end=h-l+1; 28 | for(int i=end;i>0;--i){ 29 | int a=h/i-l/i; 30 | dp[i]=(powm(a,n)-a)%mod; 31 | for(int j=i<<1;j<=end;j+=i)dp[i]=(dp[i]-dp[j])%mod; 32 | } 33 | printf("%d\n",(dp[1]+(l==0)+mod)%mod); 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Unclassified/Done/3197.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int mod=100003; 3 | long long powm(long long a,long long k){ 4 | a%=mod; 5 | long long res=1; 6 | while(k){ 7 | if(k&1)res=res*a%mod; 8 | k>>=1,a=a*a%mod; 9 | } 10 | return res; 11 | } 12 | long long clamp(long long x){ 13 | return (x%mod+mod)%mod; 14 | } 15 | int main(){ 16 | long long m,n; 17 | scanf("%lld%lld",&m,&n); 18 | printf("%lld\n",(m%mod)*clamp(powm(m,n-1)-powm(m-1,n-1))%mod); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Unclassified/Done/3205.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size=1001,mod=19650827; 3 | int dp[size][size][2]={},A[size]; 4 | int main(){ 5 | int n; 6 | scanf("%d",&n); 7 | for(int i=1;i<=n;++i){ 8 | scanf("%d",&A[i]); 9 | dp[i][i][0]=1; 10 | } 11 | for(int k=2;k<=n;++k) 12 | for(int r=k;r<=n;++r){ 13 | int l=r-k+1; 14 | if(A[l]A[l])dp[l][r][1]+=dp[l][r-1][0]; 18 | if(A[r]>A[r-1])dp[l][r][1]+=dp[l][r-1][1]; 19 | dp[l][r][1]%=mod; 20 | } 21 | printf("%d\n",(dp[1][n][0]+dp[1][n][1])%mod); 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Unclassified/Done/3214.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size=1000001,mod=100000007; 4 | long long powm(long long a,int k){ 5 | long long res=1; 6 | while(k){ 7 | if(k&1)res=res*a%mod; 8 | k>>=1,a=a*a%mod; 9 | } 10 | return res; 11 | } 12 | int main(){ 13 | int n,m; 14 | scanf("%d%d",&n,&m); 15 | long long powv=(powm(2,n)-1+mod)%mod; 16 | long long A=1,f1=1,f2=0,f3=0; 17 | for(int i=1;i<=m;++i){ 18 | f3=f2; 19 | f2=f1; 20 | f1=(A-f2-f3*(i-1)%mod*(powv-(i-2))%mod)%mod; 21 | A=A*(powv-i+1)%mod; 22 | } 23 | long long fac=1; 24 | for(int i=1;i<=m;++i)fac=fac*i%mod; 25 | long long res=f1*powm(fac,mod-2)%mod; 26 | printf("%lld\n",(res%mod+mod)%mod); 27 | return 0; 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /Unclassified/Done/3214dp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size=1000001,mod=100000007; 4 | int dp[100][60][100]={}; 5 | int main(){ 6 | int n,m; 7 | scanf("%d%d",&n,&m); 8 | dp[0][0][0]=1; 9 | int end=1< 2 | typedef long long Int64; 3 | Int64 powm(Int64 a,Int64 k,Int64 p){ 4 | Int64 res=1; 5 | while(k){ 6 | if(k&1)res=res*a%p; 7 | k>>=1,a=a*a%p; 8 | } 9 | return res; 10 | } 11 | int main(){ 12 | Int64 m,n,k,p; 13 | scanf("%lld%lld%lld%lld",&n,&k,&m,&p); 14 | Int64 sum=powm(m,k-2,p); 15 | Int64 cnt=(k-1)*sum%p; 16 | Int64 seq=((m+1)*m/2)%p; 17 | Int64 sub=cnt*seq%p; 18 | n%=p; 19 | Int64 ans=(sum*m%p*n%p-sub+p)%p; 20 | printf("%lld\n",ans); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Unclassified/Done/3353.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | long long sum[100001]={}; 4 | int main(){ 5 | int n,w; 6 | scanf("%d%d",&n,&w); 7 | int p,b,maxp=0; 8 | for(int i=0;i 2 | const int mod=6662333; 3 | long long powm(long long k){ 4 | long long res=1,a=2; 5 | while(k){ 6 | if(k&1)res=res*a%mod; 7 | k>>=1,a=a*a%mod; 8 | } 9 | return res; 10 | } 11 | int main(){ 12 | long long x; 13 | scanf("%lld",&x); 14 | printf("%lld\n",powm(x-1)); 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Unclassified/Done/3531.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size=1000001; 3 | char A[size],B[size]; 4 | int q[26][size],e[26]={},b[26]={},num[size],sum[size]; 5 | void add(int x,int n){ 6 | while(x<=n){ 7 | ++sum[x]; 8 | x+=x&-x; 9 | } 10 | } 11 | int query(int x){ 12 | int res=0; 13 | while(x){ 14 | res+=sum[x]; 15 | x-=x&-x; 16 | } 17 | return res; 18 | } 19 | int main(){ 20 | int n; 21 | scanf("%d%s%s",&n,A,B); 22 | for(int i=0;i 2 | #include 3 | struct Mogic{ 4 | int t,b; 5 | } m[100000]; 6 | bool cmp(Mogic lhs,Mogic rhs){ 7 | if(lhs.b>=0 && rhs.b>=0) 8 | return lhs.trhs.t+rhs.b; 11 | return lhs.b>rhs.b; 12 | } 13 | bool foo(){ 14 | int n,T; 15 | scanf("%d%d",&n,&T); 16 | for(int i=0;i0 && T>m[i].t)T+=m[i].b; 21 | else return false; 22 | return T>0; 23 | } 24 | int main(){ 25 | int z; 26 | scanf("%d",&z); 27 | while(z--)puts(foo()?"+1s":"-1s"); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Unclassified/Done/3640/Task3Codes.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/Done/3640/Task3Codes.zip -------------------------------------------------------------------------------- /Unclassified/Done/3640/bin/Gamble1.cppx: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int i, a, b, V, E; 5 | 6 | int main() { 7 | scanf("%d %d", &V, &E); 8 | for (i = 0; i < E; i++) 9 | scanf("%d %d", &a, &b); 10 | 11 | printf("%d\n", V); 12 | printf("%d", 0); 13 | for (i = 1; i < V; i++) 14 | printf(" %d", i); 15 | printf("\n"); 16 | 17 | printf("The value of counter is: %d\n", 0); 18 | return 0; // will never get TLE 19 | } 20 | -------------------------------------------------------------------------------- /Unclassified/Done/3640/bin/Gamble2.cppx: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int i, a, b, V, E; 5 | 6 | int main() { 7 | scanf("%d %d", &V, &E); 8 | for (i = 0; i < E; i++) 9 | scanf("%d %d", &a, &b); 10 | 11 | printf("%d\n", V); 12 | printf("%d", 0); 13 | for (i = 1; i < V; i++) 14 | printf(" %d", i); 15 | printf("\n"); 16 | 17 | printf("TLE because iteration counter > 1000000\n"); 18 | return 1000010; // this is TLE 19 | } 20 | -------------------------------------------------------------------------------- /Unclassified/Done/3640/data/4.txt: -------------------------------------------------------------------------------- 1 | 33 2 | 2 1 -1 2 -2 3 | 1 2 -100000 4 | 2 3 -1 4 -2 5 | 1 4 -50000 6 | 2 5 -1 6 -2 7 | 1 6 -25000 8 | 2 7 -1 8 -2 9 | 1 8 -12500 10 | 2 9 -1 10 -2 11 | 1 10 -6250 12 | 2 11 -1 12 -2 13 | 1 12 -3125 14 | 2 13 -1 14 -2 15 | 1 14 -1562 16 | 2 15 -1 16 -2 17 | 1 16 -781 18 | 2 17 -1 18 -2 19 | 1 18 -390 20 | 2 19 -1 20 -2 21 | 1 20 -195 22 | 2 21 -1 22 -2 23 | 1 22 -97 24 | 2 23 -1 24 -2 25 | 1 24 -48 26 | 2 25 -1 26 -2 27 | 1 26 -24 28 | 2 27 -1 28 -2 29 | 1 28 -12 30 | 2 29 -1 30 -2 31 | 1 30 -6 32 | 2 31 -1 32 -2 33 | 1 32 -3 34 | 0 35 | 6 36 | 0 32 37 | 0 32 38 | 0 32 39 | 0 32 40 | 0 32 41 | 0 32 42 | -------------------------------------------------------------------------------- /Unclassified/Done/3640/data/6.txt: -------------------------------------------------------------------------------- 1 | 33 2 | 2 1 -1 2 -2 3 | 1 2 -100000 4 | 2 3 -1 4 -2 5 | 1 4 -50000 6 | 2 5 -1 6 -2 7 | 1 6 -25000 8 | 2 7 -1 8 -2 9 | 1 8 -12500 10 | 2 9 -1 10 -2 11 | 1 10 -6250 12 | 2 11 -1 12 -2 13 | 1 12 -3125 14 | 2 13 -1 14 -2 15 | 1 14 -1562 16 | 2 15 -1 16 -2 17 | 1 16 -781 18 | 2 17 -1 18 -2 19 | 1 18 -390 20 | 2 19 -1 20 -2 21 | 1 20 -195 22 | 2 21 -1 22 -2 23 | 1 22 -97 24 | 2 23 -1 24 -2 25 | 1 24 -48 26 | 2 25 -1 26 -2 27 | 1 26 -24 28 | 2 27 -1 28 -2 29 | 1 28 -12 30 | 2 29 -1 30 -2 31 | 1 30 -6 32 | 2 31 -1 32 -2 33 | 1 32 -3 34 | 0 35 | 6 36 | 0 32 37 | 0 32 38 | 0 32 39 | 0 32 40 | 0 32 41 | 0 32 42 | -------------------------------------------------------------------------------- /Unclassified/Done/3640/data/Gamble.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | std::string to_string(int x){ 6 | std::stringstream ss; 7 | ss< 2 | #include 3 | int sum[100001]={}; 4 | int main(){ 5 | int n,k,b,x; 6 | scanf("%d%d%d",&n,&k,&b); 7 | for(int i=0;i 2 | void printImpl(long long x){ 3 | if(x>=10)printImpl(x/10); 4 | putchar('0'+x%10); 5 | } 6 | void print(long long x){ 7 | printImpl(x); 8 | putchar(' '); 9 | } 10 | long long f[1000001]; 11 | int main(){ 12 | int n; 13 | scanf("%d",&n); 14 | f[0]=0; 15 | for(int i=1;i<=n;++i) 16 | for(int j=i;j<=n;j+=i) 17 | f[j]+=i; 18 | long long sum=0; 19 | for(int i=1;i<=n;++i){ 20 | sum+=n-f[i]; 21 | print(sum); 22 | } 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Unclassified/Done/3719.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int maxv(int a,int b){ 3 | return a>b?a:b; 4 | } 5 | int scan(){ 6 | int cnt=0; 7 | while(true){ 8 | int c=getchar(); 9 | switch(c){ 10 | case '(':cnt+=scan();break; 11 | case 'a':++cnt;break; 12 | case '|':return maxv(cnt,scan());break; 13 | default:return cnt;break; 14 | } 15 | } 16 | return cnt; 17 | } 18 | int main(){ 19 | printf("%d\n",scan()); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Unclassified/Done/3768-WA60.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size=30000100; 3 | typedef long long Int64; 4 | Int64 f[size]; 5 | Int64 powm(Int64 a,Int64 k,Int64 p){ 6 | Int64 res=1; 7 | while(k){ 8 | if(k&1)res=res*a%p; 9 | k>>=1,a=a*a%p; 10 | } 11 | return res; 12 | } 13 | int main(){ 14 | Int64 p,n; 15 | scanf("%lld%lld",&p,&n); 16 | Int64 ans=0,inv2=powm(2,p-2,p); 17 | for(Int64 i=n;i>=1;--i){ 18 | Int64 x=(n/i)%p; 19 | Int64 sum=x*(x+1)%p*inv2%p*i%p; 20 | f[i]=sum*sum%p; 21 | for(Int64 j=i<<1;j<=n;j+=i) 22 | f[i]=(f[i]-f[j])%p; 23 | ans=(ans+f[i]*i%p)%p; 24 | } 25 | ans=(ans+p)%p; 26 | printf("%lld\n",ans); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Unclassified/Done/3773.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | const int size=250000,mod=1000000007; 13 | int A[size],dp[size]={},p[size]={}; 14 | int main(){ 15 | int n=read(); 16 | for(int i=1;i<=n;++i){ 17 | A[i]=read(); 18 | p[A[i]]=i; 19 | } 20 | int ans=0; 21 | for(int i=1;i<=n;++i){ 22 | ans=(ans+dp[A[i]])%mod; 23 | ++dp[A[i]]; 24 | for(int j=(A[i]-1)&A[i];j;j=(j-1)&A[i]) 25 | if(p[j]>i) 26 | dp[j]=(dp[A[i]]+dp[j])%mod; 27 | } 28 | printf("%d\n",ans); 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Unclassified/Done/3842.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Line{ 4 | int l,r; 5 | int move(int pos) const{ 6 | if(l<=pos && pos<=r)return pos; 7 | else if(pos 2 | #include 3 | #include 4 | using namespace std; 5 | int A[110000]; 6 | int main(){ 7 | int n,m; 8 | scanf("%d",&n); 9 | for(int i=0;i>1]); 25 | } 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Unclassified/Done/3901.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int last[100001]; 4 | int main(){ 5 | int n,q,x; 6 | scanf("%d%d",&n,&q); 7 | std::map cache; 8 | for(int i=1;i<=n;++i){ 9 | scanf("%d",&x); 10 | int& id=cache[x]; 11 | last[i]=id; 12 | id=i; 13 | } 14 | for(int i=2;i<=n;++i) 15 | last[i]=std::max(last[i],last[i-1]); 16 | int l,r; 17 | for(int i=0;i 2 | #include 3 | int A[100001]={}; 4 | int main(){ 5 | int n,c,len=0; 6 | scanf("%d",&n); 7 | for(int i=0;iA[len]) 10 | A[++len]=c; 11 | else { 12 | int x=std::lower_bound(A,A+len,c)-A; 13 | A[x]=std::min(A[x],c); 14 | } 15 | } 16 | printf("%d\n",n-len); 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Unclassified/Done/3908.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | long long calc(long long n){ 3 | long long mod=n%4LL; 4 | switch(mod){ 5 | case 0:return n; 6 | case 1:return 1; 7 | case 2:return n+1; 8 | case 3:return 0; 9 | } 10 | } 11 | int main(){ 12 | long long n; 13 | scanf("%lld",&n); 14 | printf("%lld\n",calc(n)); 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Unclassified/Done/3908test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n; 4 | scanf("%d",&n); 5 | for(int i=1;i<=n;++i){ 6 | int ans=1; 7 | for(int j=2;j<=i;++j) 8 | ans^=j; 9 | printf("%d %d\n",i,ans); 10 | } 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Unclassified/Done/3909.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size=1000000,mod=1000000007; 3 | int A[size],B[size]; 4 | int main(){ 5 | int n,sum=0,ans=0; 6 | scanf("%d",&n); 7 | for(int i=0;i 2 | #include 3 | const int size=1000000; 4 | int X[size],Y[size]; 5 | int main(){ 6 | int n,k; 7 | scanf("%d%d",&n,&k); 8 | for(int i=0;i 2 | const int size=100001; 3 | long long A[size]; 4 | bool B[size]; 5 | long long foo(int bit,int n){ 6 | B[0]=false; 7 | for(int i=1;i<=n;++i) 8 | B[i]=B[i-1]^static_cast(A[i]&(1LL< 2 | #include 3 | typedef long long intt; 4 | int main(){ 5 | intt n,k; 6 | scanf("%lld%lld",&n,&k); 7 | std::map fac; 8 | for(intt i=2;k!=1;++i) 9 | if(k%i==0){ 10 | while(k%i==0){ 11 | ++fac[i]; 12 | k/=i; 13 | } 14 | } 15 | typedef std::map::iterator iter_t; 16 | intt ans=1LL<<60; 17 | for(iter_t i=fac.begin();i!=fac.end();++i){ 18 | intt x=0; 19 | for(intt j=i->first;j<=n;j*=i->first)x+=n/j; 20 | x/=i->second; 21 | if(x 2 | const int maxv=1<<30; 3 | int main(){ 4 | int n; 5 | while(~scanf("%d",&n)){ 6 | int x,l1,l2,cnt1=0,cnt2=0; 7 | scanf("%d",&l1); 8 | l2=l1; 9 | for(int i=1;il1)l1=-maxv,++cnt1; 13 | else l1=x; 14 | if(i&1 && x>l2)l2=-maxv,++cnt2; 15 | else if(~i&1 && x 2 | #include 3 | const long long mod=998244353; 4 | long long query(long long x){ 5 | long long res=0,rtx=sqrt(x); 6 | for(long long i=1;i<=rtx;++i) 7 | res=(res+i*(x/i-x/(i+1))%mod)%mod; 8 | for(long long i=1;i<=x/(rtx+1);++i) 9 | res=(res+x/i)%mod; 10 | return res; 11 | } 12 | int main(){ 13 | long long a,b; 14 | scanf("%lld%lld",&a,&b); 15 | printf("%lld\n",((query(b)-query(a-1))%mod+mod)%mod); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Unclassified/Done/3974.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int read(){ 3 | int res=0,c; 4 | do c=getchar(); 5 | while(c<'0'||c>'9'); 6 | while('0'<=c&&c<='9'){ 7 | res=res*10+c-'0'; 8 | c=getchar(); 9 | } 10 | return res; 11 | } 12 | const int size=1010; 13 | int A[size][size]; 14 | long long dp[size][size]; 15 | long long maxv(long long a,long long b){ 16 | return a>b?a:b; 17 | } 18 | long long foo(){ 19 | int n=read(); 20 | int m=read(); 21 | for(int i=1;i<=n;++i) 22 | for(int j=1;j<=m;++j) 23 | A[i][j]=read(); 24 | for(int i=1;i<=n;++i) 25 | for(int j=m;j>=1;--j) 26 | dp[i][j]=maxv(dp[i-1][j+1]+A[i][j],maxv(dp[i-1][j],dp[i][j+1])); 27 | return dp[n][1]; 28 | } 29 | int main(){ 30 | int t=read(); 31 | for(int i=0;i 2 | int main(){ 3 | double n; 4 | scanf("%lf",&n); 5 | printf("%.14lf\n",n*(n+1.0)/(2.0*(2.0*n-1.0))); 6 | return 0; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /Unclassified/Done/4072TLE60.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size=3100; 4 | int S[size]; 5 | long long dp[size][size]; 6 | int main(){ 7 | int n,m; 8 | scanf("%d%d",&n,&m); 9 | for(int i=1;i<=n;++i){ 10 | scanf("%d",&S[i]); 11 | S[i]+=S[i-1]; 12 | } 13 | memset(dp,0x3f,sizeof(dp)); 14 | dp[0][0]=0; 15 | for(int i=1;i<=m;++i){ 16 | for(int j=1;j<=n;++j) 17 | for(int k=0;kval)dp[i][j]=val; 21 | } 22 | } 23 | long long ans=m*dp[m][n]-S[n]*S[n]; 24 | printf("%lld\n",ans); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Unclassified/Done/4101.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int t; 4 | scanf("%d",&t); 5 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | const int size=2000; 6 | int random(){ 7 | return rand()%size; 8 | } 9 | int main(){ 10 | srand(time(0)); 11 | freopen("test.in","w",stdout); 12 | int n=size; 13 | int m=size*2; 14 | printf("%d %d\n",n,m); 15 | for(int i=1;i<=n;++i) 16 | printf("%d ",random()%40); 17 | puts(""); 18 | for(int i=1;i<=m;++i){ 19 | int l=random()+1; 20 | int r=random()+1; 21 | if(l>r)std::swap(l,r); 22 | printf("%d %d\n",l,r); 23 | } 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Unclassified/Done/4137/4137std.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size=2005; 4 | int A[size]; 5 | bool B[size]; 6 | int main(){ 7 | freopen("test.in","r",stdin); 8 | freopen("std.out","w",stdout); 9 | int n,m; 10 | scanf("%d%d",&n,&m); 11 | for(int i=1;i<=n;++i) 12 | scanf("%d",&A[i]); 13 | for(int i=1;i<=m;++i){ 14 | int l,r; 15 | scanf("%d%d",&l,&r); 16 | memset(B,0,sizeof(B)); 17 | for(int j=l;j<=r;++j)B[A[j]]=true; 18 | int cur=0; 19 | while(B[cur])++cur; 20 | printf("%d\n",cur); 21 | } 22 | return 0; 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /Unclassified/Done/4301.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | const int size=105; 5 | int A[size]={},B[32]={}; 6 | int main(){ 7 | int n; 8 | scanf("%d",&n); 9 | for(int i=0;i()); 12 | long long sum=0; 13 | for(int i=0;i=0;--j) 17 | if(A[i]&(1< 2 | #include 3 | #include 4 | #include 5 | int random(int x){ 6 | return 1LL*rand()*rand()%x+1; 7 | } 8 | int main(){ 9 | srand(clock()); 10 | freopen("test.in","w",stdout); 11 | int n=200000; 12 | int m=500000; 13 | printf("%d %d\n",n,m); 14 | for(int i=1;i<=n;++i) 15 | printf("%d ",rand()); 16 | puts(""); 17 | for(int i=0;ir)std::swap(l,r); 22 | printf("2 %d %d\n",l,r); 23 | } 24 | else{ 25 | printf("1 %d %d %d\n",random(n),random(n),random(1000000007)); 26 | } 27 | } 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Unclassified/Done/4503.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int size=30005; 4 | char buf[size]; 5 | const int a=127,b=823,c=577,d=347; 6 | long long L[205],R[205],A[205][size]; 7 | int main(){ 8 | int n,l,s; 9 | scanf("%d%d%d",&n,&l,&s); 10 | for(int i=0;i=1;--j)R[j]=R[j+1]*b+buf[j]; 14 | for(int j=1;j<=l;++j)A[j][i]=L[j-1]*c+R[j+1]*d; 15 | } 16 | long long res=0; 17 | for(int i=1;i<=l;++i){ 18 | std::sort(A[i],A[i]+n); 19 | long long cur=1LL<<60,cnt=0; 20 | for(int j=0;j<=n;++j) 21 | if(A[i][j]==cur)++cnt; 22 | else{ 23 | res+=cnt*(cnt-1)>>1; 24 | cur=A[i][j]; 25 | cnt=1; 26 | } 27 | } 28 | printf("%d\n",res); 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Unclassified/Done/4639/compile.bat: -------------------------------------------------------------------------------- 1 | 4639 output/compiler10.out -------------------------------------------------------------------------------- /Unclassified/Done/4820.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const double r = 0.57721566490153286060651209; 4 | int main() { 5 | long long n, m; 6 | scanf("%lld%lld", &n, &m); 7 | double base = m / 2.0, sum = 0.0; 8 | if(n <= 10000) { 9 | for(int i = 1; i <= n; ++i) 10 | sum += base / i; 11 | } else 12 | sum = base * (log(n + 1.0) + r); 13 | printf("%d\n", static_cast(sum - 1e-10)); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Unclassified/Done/FJ-0527/math/math.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | freopen("math.in","r",stdin); 4 | freopen("math.out","w",stdout); 5 | long long a,b; 6 | scanf("%lld%lld",&a,&b); 7 | long long ans=a*b-a-b; 8 | printf("%lld\n",ans); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Unclassified/Done/Fib/mat.txt: -------------------------------------------------------------------------------- 1 | (Fn+1,Fn) (p,1) (Fn+2,Fn+1) 2 | (Fn,Fn-1) (q,0) (Fn+1,Fn) 3 | base = (a3,a2) * mul^(n-2) 4 | (a2,a1) -------------------------------------------------------------------------------- /Unclassified/Done/KMP/kmp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char s1[1000001],s2[1001]; 4 | int next[1001]; 5 | using namespace std; 6 | int main(){ 7 | scanf("%s%s",s1,s2); 8 | const int len1=strlen(s1),len2=strlen(s2); 9 | int i,j=0; 10 | next[0]=next[1]=0; 11 | for(i=1;i 2 | int sum[100001]={},n,x,y; 3 | inline void add(){ 4 | while(x<=n){ 5 | sum[x]+=y; 6 | x+=x&-x; 7 | } 8 | } 9 | int get(int i){ 10 | int res=0; 11 | while(i){ 12 | res+=sum[i]; 13 | i-=i&-i; 14 | } 15 | return res; 16 | } 17 | int main(){ 18 | int m; 19 | scanf("%d%d",&n,&m); 20 | for(int i=1;i<=n;++i){ 21 | x=i,scanf("%d",&y); 22 | add(); 23 | } 24 | 25 | char c[2]; 26 | while(m){ 27 | scanf("%s%d%d",c,&x,&y); 28 | if(*c=='x')add(); 29 | else printf("%d\n",get(y)-get(x-1)); 30 | --m; 31 | } 32 | return 0; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Unclassified/Done/energy/energy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int gcd(int a,int b){ 4 | return b?gcd(b,a%b):a; 5 | } 6 | int main(){ 7 | int n,m,ans=0; 8 | cin>>n>>m; 9 | for(int i=1;i<=n;++i) 10 | for(int j=1;j<=m;++j) 11 | ans+=gcd(i,j); 12 | cout< 2 | using namespace std; 3 | int foo() 4 | { 5 | 6 | } 7 | int main() 8 | { 9 | ios::sync_with_stdio(false); 10 | int t; 11 | cin>>t; 12 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | } 7 | 8 | -------------------------------------------------------------------------------- /Unclassified/Done/mat/mat.txt: -------------------------------------------------------------------------------- 1 | (Fn,Fn-1,Fn-2) (1,1,0) (Fn+1,Fn,Fn-1) 2 | (Fn-1,Fn-2,Fn-3) (0,0,1) (Fn,Fn-1,Fn-2) 3 | (Fn-2,Fn-3,Fn-4) (1,0,0) (Fn-2,Fn-2,Fn-3) 4 | 5 | 1 1 1 2 3 4 6 9 13 19 28 -------------------------------------------------------------------------------- /Unclassified/Done/mean.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | long long A[100001],ms[100001]; 5 | int msp[100001]; 6 | 7 | int main(){ 8 | int n,m; 9 | scanf("%d%d",&n,&m); 10 | A[0]=0,ms[0]=2000LL*100000LL; 11 | for(int i=1;i<=n;++i) 12 | scanf("%lld",&A[i]); 13 | 14 | long long maxv=0LL; 15 | int p=0; 16 | for(int i=1;i<=n;++i){ 17 | A[i]+=A[i-1]; 18 | if(ms[i-1]=m) 23 | maxv=max(maxv,(A[i]-ms[i-m])*1000/(i-msp[i-m])); 24 | } 25 | 26 | printf("%lld\n",maxv); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Unclassified/Done/mean2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | long long A[100001],s[100001]; 5 | 6 | int main(){ 7 | int n,m; 8 | scanf("%d%d",&n,&m); 9 | long long l=0,r=0; 10 | for(int i=1;i<=n;++i){ 11 | scanf("%lld",&A[i]); 12 | A[i]*=10000; 13 | r=max(r,A[i]); 14 | } 15 | 16 | s[0]=0; 17 | while(l<=r){ 18 | int mid=(l+r)>>1; 19 | bool flag=false; 20 | long long minv=0; 21 | for(int i=1;i<=n;++i){ 22 | s[i]=s[i-1]+A[i]-mid; 23 | if(i>=m){ 24 | minv=min(minv,s[i-m]); 25 | if(s[i]>=minv){ 26 | flag=true; 27 | break; 28 | } 29 | } 30 | } 31 | if(flag)l=mid+1; 32 | else r=mid-1; 33 | } 34 | 35 | printf("%lld\n",l/10); 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Unclassified/Done/mod.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n,k; 5 | cin>>n>>k; 6 | long long ans=0; 7 | for(int i=2;i<=(k>>1|1);++i) 8 | ans+=k%i; 9 | int begin=(k>>1|1)+1; 10 | int end=min(k-1,n); 11 | ans+=(k%begin+k%end)*(end-begin+1)/2; 12 | if(n>k)ans+=(n-k)*k; 13 | cout< 2 | #include 3 | int p,inv[3000001]; 4 | int main(){ 5 | int n; 6 | scanf("%d%d",&n,&p); 7 | inv[1]=1; 8 | for(int i=2;i<=n;++i) 9 | inv[i]=static_cast(p-p/i)*inv[p%i]%p; 10 | for(int i=1;i<=n;++i) 11 | printf("%d\n",inv[i]); 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Unclassified/Done/random/mat.txt: -------------------------------------------------------------------------------- 1 | (Xn,c) (a,0) (Xn+1,c) 2 | (0,0) (1,1) (0,0) -------------------------------------------------------------------------------- /Unclassified/Done/random/random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | long long m; 5 | struct Mat2 final{ 6 | long long v[2][2]; 7 | Mat2(){ 8 | memset(v,0,sizeof(v)); 9 | } 10 | Mat2 operator*(const Mat2& rhs){ 11 | Mat2 res; 12 | int i,j,k; 13 | for(i=0;i<2;++i) 14 | for(j=0;j<2;++j) 15 | for(k=0;k<2;++k) 16 | res.v[i][j]=(res.v[i][j]+(v[i][k]*rhs.v[k][j])%m)%m; 17 | return res; 18 | } 19 | }; 20 | int main(){ 21 | long long a,c,x,n,g; 22 | cin>>m>>a>>c>>x>>n>>g; 23 | c%=m,a%=m,x%=m; 24 | Mat2 ans,mul; 25 | ans.v[0][0]=x,ans.v[0][1]=c; 26 | mul.v[0][0]=a,mul.v[1][0]=mul.v[1][1]=1; 27 | while(n){ 28 | if(n&1)ans=ans*mul; 29 | mul=mul*mul,n>>=1; 30 | } 31 | cout< 2 | #include 3 | const int maxn=500010; 4 | std::pair stack[maxn]; 5 | int getInt(){ 6 | int res=0,c; 7 | do c=getchar(); 8 | while(c<'0' || c>'9'); 9 | while(c>='0' && c<='9'){ 10 | res=res*10+c-'0'; 11 | c=getchar(); 12 | } 13 | return res; 14 | } 15 | 16 | int main(){ 17 | int n=getInt(),ans=0,size=0; 18 | for(int i=1;i<=n;++i){ 19 | int x=getInt(); 20 | while(size && stack[size].first1)+stack[size].second++; 26 | else{ 27 | if(size)++ans; 28 | stack[++size]=std::make_pair(x,1); 29 | } 30 | } 31 | 32 | printf("%d\n",ans); 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Unclassified/Done/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int foo(int n,int min,int max){ 3 | if(n==0)return 1; 4 | int tot=0; 5 | for(int i=min;i<=max;++i) 6 | tot+=foo(n-1,i+1,max); 7 | //printf("f(%d,%d,%d)=%d\n",n,min,max,tot); 8 | return tot; 9 | } 10 | int main(){ 11 | for(int i=0;i<=10;++i) 12 | printf("f(%d,1,6)=%d\n",i,foo(i,1,6)); 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Unclassified/Done/weight/weight.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int x[1000],y[1000],w[1000]; 5 | int main(){ 6 | int n,i; 7 | scanf("%d\n",&n); 8 | double sx,sy; 9 | sx=sy=0.0; 10 | for(i=0;i=1e-6){ 14 | sumx=sumy=0.0f; 15 | for(i=0;i 2 | char str[100000]; 3 | int cnt=0; 4 | int main(){ 5 | int n,x; 6 | scanf("%d\n",&n); 7 | char c[2]={}; 8 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | uint64_t A[51]={}; 5 | int main(){ 6 | int n,i,j; 7 | cin>>n; 8 | uint64_t x; 9 | for(i=0;i>x; 11 | for(j=50;j>=0;--j) 12 | if(x&(1ULL<=0;--i) 24 | res=std::max(res,res^A[i]); 25 | 26 | cout<output/train2.out -------------------------------------------------------------------------------- /Unclassified/ToDo/2500.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/2500.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/3219.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/3219.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/3301.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef unsigned int uint; 3 | uint read(){ 4 | uint res=0; 5 | int c; 6 | do c=getchar(); 7 | while(c<'0'||c>'9'); 8 | while('0'<=c&&c<='9'){ 9 | res=res*10+c-'0'; 10 | c=getchar(); 11 | } 12 | return res; 13 | } 14 | uint p; 15 | uint foo(){ 16 | uint n=read(); 17 | uint n1=read(); 18 | uint n2=read(); 19 | uint m=read(); 20 | 21 | } 22 | int main(){ 23 | uint t=read(); 24 | p=read(); 25 | while(t--)printf("%u\n",foo()); 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Unclassified/ToDo/3689.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/3689.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/3699.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/3699.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/3700.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | long long read(){ 3 | long long res=0; 4 | int c; 5 | do c=getchar(); 6 | while(c<'0'||c>'9'); 7 | while('0'<=c&&c<='9'){ 8 | res=res*10+c-'0'; 9 | c=getchar(); 10 | } 11 | return res; 12 | } 13 | const int mod=1000000007,size=4000001; 14 | long long inv[size]; 15 | int main(){ 16 | int n=read(); 17 | int m=read(); 18 | inv[1]=1; 19 | for(int i=2;i<=n;++i) 20 | inv[i]=-mod/i*inv[mod%i]%mod; 21 | for(int i=0;i>1)%mod; 28 | int res=cur*sum%mod*sum%mod; 29 | printf("%d\n",(res+mod)%mod); 30 | } 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Unclassified/ToDo/3770.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/3770.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/3771C.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/3771C.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/3772B.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/3772B.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/3780.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/3780.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/3782/check.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | std::string getName(int id){ 5 | std::stringstream ss; 6 | ss<<"sort"<"+out; 15 | system(cmd1.c_str()); 16 | std::string cmd2="checker "+in+" "+out+" "+out; 17 | system(cmd2.c_str()); 18 | } 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Unclassified/ToDo/4006E.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/4006E.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/4175.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/4175.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/4191D.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/4191D.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/4337.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/4337.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/4357.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/4357.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/4382.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/4382.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/4428.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/4428.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/4428test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size=1000005; 3 | int bcnt[size]; 4 | bool vis[size]={}; 5 | int main(){ 6 | int n; 7 | scanf("%d",&n); 8 | for(int i=0;i<=n;++i){ 9 | bcnt[i]=bcnt[i>>1]+(i&1); 10 | if(i%3==0)vis[bcnt[i]]=true; 11 | } 12 | for(int i=0;i<=40;++i) 13 | if(vis[i]) 14 | printf("%d\n",i); 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Unclassified/ToDo/4429.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtcxzyw/OI-Source/aa041e2af7e1546e8c7ac5a960a27a3489cfcff8/Unclassified/ToDo/4429.cpp -------------------------------------------------------------------------------- /Unclassified/ToDo/4463dp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int size=5000; 3 | long long dp[size][size]={}; 4 | int main(){ 5 | int A,n,mod; 6 | scanf("%d%d%d",&A,&n,&mod); 7 | for(int i=0;i<=A;++i)dp[0][i]=1; 8 | for(int i=1;i<=n;++i){ 9 | for(int j=1;j<=A;++j) 10 | dp[i][j]=(dp[i-1][j-1]*j+dp[i][j-1])%mod; 11 | } 12 | long long res=dp[n][A]; 13 | for(int i=1;i<=n;++i)res=res*i%mod; 14 | printf("%lld\n",res); 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Unclassified/ToDo/4484test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | const int size=30; 5 | int A[size],dp[size]; 6 | int main(){ 7 | int n; 8 | scanf("%d",&n); 9 | for(int i=1;i<=n;++i) 10 | A[i]=i; 11 | int a=0,b=0; 12 | do{ 13 | memset(dp,0,sizeof(dp)); 14 | dp[0]=0; 15 | for(int i=1;i<=n;++i) 16 | for(int j=0;j