Problems

Pick a problem and write your solution in the built-in editor. The judge runs it against real test cases while you watch, and the wider archive is open to read whenever you like.

Total results388 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
B-Smooth NumbersCount B-smooth numbers (no prime factor above B) in the interval [n, n+m], with n up to 2e9, m up to 1e8, and B up to 1e6.Hard8Number theorySegment tree+2No attempts yet1s128 MBJudgeable
Ice SkatesAfter each of m membership events, decide whether every current member can be assigned skates, given k pairs of each size and foot sizes with tolerance d.Hard8Segment treeGreedy+1No attempts yet1s128 MBJudgeable
Monotonicity 2Find the longest subsequence of a given array whose adjacent-comparison pattern repeats the given cyclic scheme of <, >, = symbols.Hard8Dynamic programmingSegment tree+1No attempts yet3s512 MBJudgeable
Painting the WallGiven n axis-aligned rectangles, find the total area of the plane covered by at least n-1 of them.Hard8SortingSegment tree+2No attempts yet1s128 MBJudgeable
PermutationFor a sequence a and each of m point updates, report whether a permutation p with p_i <= a_i for all i exists.Hard8GreedySegment tree+1No attempts yet1s128 MBJudgeable
Fibonacci MachineMaintain registers under range increment, answering range queries of the sum of Fibonacci values at the register entries, modulo 1e9+7.Hard8Segment treeMatrix+2No attempts yet2s512 MBJudgeable
Interval Partition GeneratorThe task is to decode each given lexicographic interval index on the remaining set and report the total interval count with the chosen endpoints.Hard8Segment treeBinary search+1No attempts yet1s128 MBJudgeable
The Company ChoirGiven a rooted tree where each node has a pitch and a distinct ability score, answer queries that ask for the k highest-ability subordinates of a node whose pitch lies in a range [a,b].Hard8TreeDFS+2No attempts yet1s128 MBJudgeable
KingdomRoads merge cities into connected states over time, and each query asks how many states a horizontal line meets and how many cities those states contain.Hard8Union-findSegment tree+2No attempts yet1s128 MBJudgeable
KkunglishFor each query range, the program reports the case-insensitive occurrence of T with the most case differences, or -1 if none, then flips the case of the range.Hard8Segment treeString matchingNo attempts yet2s128 MBJudgeable
Longest ChainFind the longest chain of triples with all three coordinates strictly increasing among up to 300,000 points per dataset.Hard8Divide and conquerDynamic programming+2No attempts yet10s128 MBJudgeable
Wedding HallFind the largest L-shaped hall of three equal squares that fits inside a walled garden without enclosing any tree.Hard8GeometryBinary search+2No attempts yet1s128 MBJudgeable
WallApply k range raise-to-at-least and lower-to-at-most updates on n columns and print each final height.Hard8Segment treeNo attempts yet3s256 MBJudgeable
CardsThe program decides after each swap of two two-sided cards whether one face per card can show numbers that never decrease left to right.Hard8Segment treeDynamic programmingNo attempts yet3s256 MBJudgeable
RallyFind the vertex whose removal minimizes the longest directed path in a DAG and report that minimum length.Hard8Topological sortDynamic programming+1No attempts yet1s256 MBJudgeable
TribesRepeatedly merge axis-aligned rectangles whose overlap has positive area into their bounding box, then print the remaining boxes in lexicographic order.Hard8Union-findSegment tree+2No attempts yet3s1024 MBJudgeable
FertilizingEach day the C_i shortest of N trees grow by the day number and the K_i-th shortest height is recorded; report the sum over all days.Hard8Segment treeSorting+1No attempts yet3s256 MBJudgeable
Fantastic ProblemYou count size-k windows where some pair shares a factor, refresh the count after each point update, then print the final sum.Hard8Segment treeNumber theory+1No attempts yet10s256 MBJudgeable
Journey through the kingdomFind the cheapest carriage-hopping cost between consecutive target cells on a grid where each cell rents a ride to any cell in its rectangle range.Hard8Shortest pathSegment treeNo attempts yet3s256 MBJudgeable
MokiaPoint updates add customers to grid cells and each query asks for the total inside a rectangle using only earlier updates.Hard8Divide and conquerSegment treeNo attempts yet1s128 MBJudgeable
ImprovementsReposition ships on a line from a station so no two ropes joining consecutive ships cross, keeping as many ships as possible in place.Hard8Dynamic programmingCombinatorics+1No attempts yet1s256 MBJudgeable
The j-th NumberAfter copying each insert value into every array of its interval, each query asks for the j-th smallest value collected from an interval of arrays.Hard8Binary searchSegment tree+2No attempts yet10s512 MBJudgeable
EditorGiven up to 500000 edits and leveled undos, print the editor state after each operation.Hard8StackSegment tree+1No attempts yet3s512 MBJudgeable
Forming TeamsFor each planned day, decide whether students with accepted size ranges can fill all requested teams of the given sizes.Hard8GreedyIntervals+2No attempts yet4s512 MBJudgeable
Selling horsesOne horse multiplies by X[i] each year and any held horses sell at price Y[i]; report the maximum revenue after each point update modulo 1e9+7.Hard8Segment treeGreedy+1No attempts yet2s512 MBJudgeable
ExchangeCount the swaps performed by running the first M passes of selection sort on each array.Hard8Segment treeSorting+1No attempts yet1s256 MBJudgeable
Call a CabPartition the ordered points into the fewest rides where each ride meets one type's minimum total distance and heading range limit.Hard8Dynamic programmingSegment tree+2No attempts yet5s256 MBJudgeable
Colored painting salesEach client buys a_i colored or b_i black-and-white paintings, and after each update count the sales with at least C colored buyers modulo 10007.Hard8Dynamic programmingSegment tree+1No attempts yet4s32 MBJudgeable
Pyramid BaseFind the side length of the largest axis-aligned square on a grid that avoids all given rectangular obstacles.Hard8Binary searchGeometry+2No attempts yet5s128 MBJudgeable
Cow ConfinementEach cow moves only down or right across a large grid and cannot cross rectangular fences, and the task asks how many flowers each cow can reach.Hard8Segment treeSorting+1No attempts yet10s512 MBJudgeable
Greenhouse GrowthGiven n sunflower heights and an m-day schedule of left or right lamps, compute every height after daily growth toward the taller neighbor.Hard8Segment treeStack+2No attempts yet6s512 MBJudgeable
Text ProcessorCount the distinct substrings inside each fixed-width window of a lowercase string for many queries.Hard8String matchingSliding window+1No attempts yet1s256 MBJudgeable
Niya's HappinessTrack insertions and deletions in a banknote multiset and report after each update whether every amount up to the total is payable exactly.Hard8Segment treeSorting+1No attempts yet3s512 MBJudgeable
Sunlight on a TreeReport all nodes on the tree path from u to v whose dot product with the query direction is minimal.Hard8TreeSegment tree+1No attempts yet5s256 MBJudgeable
New Year TrainAssign each wagon in input order to one of M queue tracks so wagons exit numbered 1 to N, choosing the lexicographically smallest assignment.Hard8GreedyQueue+1No attempts yet2s256 MBJudgeable
Rain AgainFind the fewest leading drops so every W by H rectangle inside the L by L pot contains a drop strictly inside, or report -1.Hard8Binary searchSegment tree+1No attempts yet2s256 MBJudgeable
Counting palindromesCount the palindromic substrings fully contained in each query interval of a lowercase string.Hard8String matchingSegment tree+2No attempts yet2s64 MBJudgeable
K-th smallest weight on a tree pathAnswer each query with the K-th smallest vertex weight on the path between two vertices in a tree.Hard8Segment treeTree+1No attempts yet1.5s512 MBJudgeable
Fortune Telling 2N two-sided cards start showing A_i and each threshold T_j flips every card whose visible number is at most T_j; compute the final visible sum.Hard8Segment treeSorting+1No attempts yet2s256 MBJudgeable
Mowing the FieldCount interior crossings of perpendicular mower segments cut at least T days apart.Hard8Segment treeGeometry+1No attempts yet5s512 MBJudgeable
FaultGiven diagonal fault shifts with surface erosion, report the original depth of the layer exposed at each unit of the surface.Hard8Segment treeGeometryNo attempts yet2s256 MBJudgeable
Fairland (Large)Keep the largest rooted connected subtree containing the CEO so all kept salaries fit within a range of width D.Hard8TreeSliding window+2No attempts yet10s512 MBJudgeable
The Great Wall (Large)Count how many moving interval attacks pierce a wall that rises after each success to the strength that would have stopped it.Hard8Segment treeIntervals+1No attempts yet15s512 MBJudgeable
Increasing Speed Limits (Large)Generate a sequence from a recurrence, then count modulo 1e9+7 how many non-empty strictly increasing subsequences it has.Hard8Dynamic programmingSegment treeNo attempts yet5s512 MBJudgeable
Dynamic memory allocationSimulate a memory allocator over n bytes: allocate the leftmost run of l free bytes, or free a range and count how many bytes were actually freed.Hard8IntervalsSegment tree+1No attempts yet1s1024 MBJudgeable
Hongjun Loves PaintingBricks start with color equal to their index and colorfulness 0; range paint operations add the absolute color change to each brick, and queries ask for the total colorfulness over a range.Hard8Segment treeImplementation+2No attempts yet2s512 MBJudgeable
Range GCDSupport range add and range GCD queries on an array by tracking a difference array with a segment tree and one prefix sum.Hard8Segment treeNumber theory+1No attempts yet2s512 MBJudgeable
Minho's WishFor each of Q range queries on an array, count how many distinct values occur at least three times within the queried index range.Hard8Segment treePrefix sum+2No attempts yet2s512 MBJudgeable
TreeMaintain a rooted tree under vertex deletions (children reparent to grandparent) and answer distance queries between two live vertices.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Calculation mistakeMaintain a string of digits and plus or minus signs under range replacements, and evaluate the arithmetic value of any substring with the calculator's operator rules.Hard8Segment treeString+1No attempts yet3s256 MBJudgeable
Farthest White Pair in a TreeMaintain a tree whose vertices flip between white and black, and after each flip report the largest distance between two white vertices, where edge lengths may be negative.Hard8TreeDivide and conquer+2No attempts yet2s512 MBJudgeable
Sequence and Queries 1Given a static sequence, answer M queries counting how many values in range A[i..j] are greater than k.Hard8Segment treeSorting+2No attempts yet1s512 MBJudgeable
Palindromes and QueriesSupport range character assignments and count palindromic substrings of length at most K inside a queried range.Hard8Segment treeString+2No attempts yet2s512 MBJudgeable
Sequence and Queries 3Given a static sequence, answer queries (decoded with the previous answer via XOR) counting how many elements in a subarray exceed k.Hard8Segment treeBinary search+1No attempts yet1s512 MBJudgeable
Sequence and Queries 10For each query with ranges [x1,y1] and [x2,y2], find the maximum subarray sum A_i+...+A_j where i is in the first range and j is in the second.Hard8Segment treePrefix sum+1No attempts yet2s512 MBJudgeable
Emission SpectrumMaintain an integer array under adjacent swaps and answer k-th smallest value queries over subarrays online.Hard8Binary searchDivide and conquer+2No attempts yet2s512 MBJudgeable
Sequence and Queries 13Maintain an array under range add, range multiply, and range assign modulo 1e9+7, answering range sum queries.Hard8Segment treeLinked list+2No attempts yet2s512 MBJudgeable
ShoppingGiven an array of prices and a sequence of queries (money, l, r), simulate a shopper who spends as much as possible at each product from l to r and report the leftover money.Hard8ArraySegment tree+2No attempts yet5s512 MBJudgeable
Demilitarized ZoneFor each protected point, count how many starting mines eventually trigger a blast covering it, given chain reactions over intervals.Hard8IntervalsSorting+2No attempts yet3s256 MBJudgeable
Maximum Bitwise OR by Window LengthFor each window length K from 1 to N, output the maximum bitwise OR over all K consecutive elements of the array.Hard8Bit manipulationDivide and conquer+2No attempts yet2s512 MBJudgeable
PoklonFor each query interval, count distinct values that occur exactly twice within it. N and Q go up to 500,000.Hard8Prefix sumHash map+1No attempts yet5s512 MBJudgeable
Why Did the Cow Cross the Road 11Given a permutation of breeds on each side of a road, connect pairs whose breed numbers differ by at most 4 using non-crossing edges, maximizing the count.Hard8Dynamic programmingDivide and conquer+2No attempts yet2s512 MBJudgeable
Sequence and Queries 18Maintain an array under point updates and answer range queries counting elements greater than k.Hard8Segment treeSorting+2No attempts yet2s512 MBJudgeable
Weather ForecastMaintain N snow depths under point increments and decrements, then answer range-count queries (depth between L and R) and T-th largest value queries online.Hard8Segment treeBinary search+2No attempts yet2s128 MBJudgeable
RMT Subway Load TestEach subway line is a cycle of stations; line operations rotate passenger counts around the cycle, and range-sum surveys must be answered online.Hard8Segment treePrefix sum+2No attempts yet5s512 MBJudgeable
Cups and MarblesAfter m range-sort spells (ascending or descending) on a permutation, report the marble in the middle cup.Hard8Binary searchSorting+2No attempts yet4s256 MBJudgeable
Goodness of a sequenceFor every contiguous block, subtract the maximum increasing-subsequence sum from the block sum, then report the best value and how many shortest blocks achieve it.Hard8Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Sequence and Queries 19Maintain an array under range add, range floor-division by d, and report the minimum and sum over a range. The division step needs a segment tree with min and sum.Hard8Segment treeLinked list+1No attempts yet2s512 MBJudgeable
Sheets and PaintballsGiven axis-aligned rectangles and colored points, count the distinct color labels that reach each rectangle along the vertical stacking order.Hard8SortingSegment tree+2No attempts yet2s512 MBJudgeable
Intergalactic ChordsMaintain an array of N notes (0 to 8); for each chord [a,b] find the most frequent note in the range, break ties by largest, then add it modulo 9 to every note in the range.Hard8Segment treeImplementation+2No attempts yet1s1024 MBJudgeable
Daunting deviceApply N range-recolor operations whose endpoints depend on the current count of a query color, then report the highest cell frequency.Hard8Segment treeImplementation+2No attempts yet1s1024 MBJudgeable
Joker's Card TrickAfter each point update to a row of nonzero integers, find the smallest prefix index maximizing the running sum of values scaled by the total positive and total negative sums.Hard8Segment treePrefix sum+2No attempts yet3s512 MBJudgeable
Posters on the wallGiven up to 50000 non-overlapping axis-aligned rectangles, answer online queries that ask for the total rectangle area inside a query rectangle, with coordinates decoded from the previous answer.Hard8Segment treeSorting+2No attempts yet2s1024 MBJudgeable
The Infosci Pirate CrewGiven N islands with coordinates, treasure values, and safe hardness, choose a monotone northeast path and a hardness interval to maximize collected value minus interval length.Hard8Dynamic programmingSorting+2No attempts yet1s512 MBJudgeable
The Grand Noi and ICPC BattleMaintain a sequence of N ones under range assignment and queries for the sum of A_i A_j A_k over all i<j<k in a range, modulo 10^8, with N up to 1e9 and Q up to 1e5.Hard8Segment treeDivide and conquer+2No attempts yet2s512 MBJudgeable
Maximum Interval Sum 2For a sequence with point updates, answer range queries for the maximum of U times a subarray sum plus V times its length minus one.Hard8Segment treeDivide and conquer+2No attempts yet1s256 MBJudgeable
SprinklersGiven a permutation of N sprinklers, count axis-aligned integer rectangles whose every point lies both northeast of some sprinkler and southwest of another, modulo 1e9+7.Hard8CombinatoricsDivide and conquer+2No attempts yet2s512 MBJudgeable
Global warmingChoose one contiguous interval and a shift d with |d| <= x, then find the maximum possible length of a strictly increasing subsequence of the modified sequence.Hard8Dynamic programmingBinary search+2No attempts yet2s512 MBJudgeable
Zoning HousesFor each query range of houses, find the side length of the smallest axis-aligned square covering all points in the range, with the option to drop one point.Hard8Segment treeDivide and conquer+2No attempts yet2s512 MBJudgeable
Coloring RoadsColor every edge on a root path with a given color and then count colors used on exactly m edges, answering Q updates online.Hard8TreeSegment tree+2No attempts yet4s1024 MBJudgeable
Masha and CactusChoose a maximum-weight subset of extra edges whose tree paths keep each vertex in at most one cycle, by a subtree DP with lazy updates on the path to the root.Hard8TreeDynamic programming+2No attempts yet4s512 MBJudgeable
RectanglesGiven up to 100,000 axis-aligned rectangles drawn by XOR-flipping pixels on a white field, find the total count of black pixels.Hard8Segment treePrefix sum+2No attempts yet2s512 MBJudgeable
King Kog's ReceptionKnights join or cancel reservations with a start time and duration; after each change, a query asks how long a visitor arriving at time t must wait, since she yields to a knight arriving at the same instant.Hard8Segment treeBinary search+2No attempts yet2s512 MBJudgeable
Three Primary ColorsGiven up to 25,000 colored rectangles painted one at a time without repainting already covered pixels, report the total area of each of the seven resulting color regions.Hard8Divide and conquerSegment tree+2No attempts yet3s256 MBJudgeable
IlluminationChoose a subset of trees to decorate, maximizing total beauty, so that for each of M given intervals at most one tree inside it is chosen.Hard8Dynamic programmingSegment tree+2No attempts yet2s512 MBJudgeable
Sequence and Queries 22Given a sequence and a stream of updates and range-sum queries, answer each query for the sequence state after its k-th update only, where k can be any earlier prefix of updates.Hard8Segment treeDivide and conquer+2No attempts yet1s512 MBJudgeable
Maximum Subarray Sum and QueriesGiven an array, answer queries that ask for the maximum subarray sum inside a given index range.Hard8Segment treeDivide and conquer+2No attempts yet2s512 MBJudgeable
Intersecting RectanglesGiven n axis-aligned rectangles with all x and y coordinates distinct, decide whether any two boundaries cross or touch. One rectangle fully containing another does not count.Hard8SortingSegment tree+2No attempts yet2s512 MBJudgeable
Cow LandOn a weighted tree, support point value updates and path XOR queries between any two nodes, returning the XOR of enjoyment values along the unique route.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
KisikChoose K of N distinct buildings, arrange them side by side on the ground, and minimize the area of the enclosing bounding rectangle.Hard8SortingDivide and conquer+2No attempts yet2s512 MBJudgeable
Truth TellersGiven N people each stating a range for the number of truth tellers, find the maximum consistent truth-teller count after each of Q point updates.Hard8ArraySegment tree+2No attempts yet3.5s256 MBJudgeable
Raider Choragi and Queries (Normal)A donut-shaped ring of 2N zones holds prisoner counts that change over Q updates; after each change, print the minimum number of squads, each covering one zone or two adjacent zones with total at most W.Hard8Dynamic programmingSegment tree+2No attempts yet5s512 MBJudgeable
Card Factory (Large)Each of N cards shows its front initially; given M queries K that flip every card whose visible number is at most K, report the final visible sum.Hard8SortingBinary search+2No attempts yet3s256 MBJudgeable
Sequence and Queries 24Maintain an array under point updates and range queries that ask for the largest sum of two distinct elements within a subarray.Hard8Segment treeDynamic programming+2No attempts yet1s512 MBJudgeable
2xN Tiling with QueriesMaintain the count of tilings of a 2xN grid by 1x2 and 2x1 tiles while cells get blocked and unblocked by queries.Hard8Dynamic programmingSegment tree+2No attempts yet2s256 MBJudgeable
Fox QuizGiven answer strings S and T over O/X, answer range queries and point flips: for a range, choose positions to mark F to maximize A times correct answers plus B times occurrences of the consecutive pattern F,O,X.Hard8Segment treeDynamic programming+2No attempts yet3s1024 MBJudgeable
Sequence and Queries 25Maintain an array under range bitwise AND, range bitwise OR, and range maximum queries, each value below 2^20.Hard8Segment treeBit manipulation+2No attempts yet2s512 MBJudgeable
Sequence and Queries 28Maintain an array under range add, range floor-sqrt, and range sum queries, and report each range sum.Hard8Segment treeMath+2No attempts yet1s512 MBJudgeable
Sequence and Queries 31Maintain a 0/1 sequence under range reversals, and answer queries for the longest run of 1s inside a given range.Hard8Segment treeIntervals+2No attempts yet2s512 MBJudgeable
XORangesMaintain an array under point updates and answer queries for the XOR of every contiguous subarray inside [l, u].Hard8Bit manipulationSegment tree+2No attempts yet1s512 MBJudgeable