No-Edge Pizza
InterviewTime limit1sMemory limit512 MB
Track toppings on a circle of N slices; for each order, report whether every residue class mod l has one flavor and the minimum l-window sum.
- Level
Medium5 of 10
- Topics
- Hash map, Math, Implementation
- Solved
- No attempts yet
Problem
A pizza is round, so it has no edge. Junhyeok runs No-Edge Pizza, a shop named after this idea. No-Edge Pizza sells a special pizza made of slices. The slices are numbered 1 to clockwise. Slice and slice 1 are adjacent. Each slice may have a topping, and a topping's flavor is a positive integer at most . No-Edge Pizza also takes special orders, where the customer chooses the position and flavor of the toppings directly. There are special orders in total. For each special order, Junhyeok fills every slice without a special topping with toppings of his choice to finish the pizza.
Junhyeok has three unusual rules for his cooking. First, a customer must eat consecutive slices at once. Second, the sum of the topping flavors on those slices must be the same for every possible set of consecutive slices. Third, slices split into groups of must leave no slice over, so is always a multiple of . A slice without a topping has flavor 0, and each slice holds at most one topping. Junhyeok makes a pizza only when he can satisfy these rules. When he can make one, he minimizes the sum of the topping flavors on slices to keep the ingredient cost down.
Help Junhyeok check, for each special order, whether he can make a suitable pizza.
Input
The first line contains , , and the number of orders , separated by spaces. , and is always divisible by
Each of the next lines contains one request in one of the following forms.
1 : Adds a topping with flavor to slice . If slice already has a topping, removes it and replaces it with a topping of flavor .
2 : Removes the topping from slice . The problem guarantees that slice has a topping.
Output
For each order, print one line. If the order can be accepted, add the toppings first, then print YES and the minimum possible sum of topping flavors over consecutive slices. If the order cannot be accepted, print NO.