Under construction

Still being built. Things may change

No-Edge Pizza

Interview

Time limit1sMemory limit512 MB

Summary
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 NN slices. The slices are numbered 1 to NN clockwise. Slice NN and slice 1 are adjacent. Each slice may have a topping, and a topping's flavor is a positive integer at most 10910^9. No-Edge Pizza also takes special orders, where the customer chooses the position and flavor of the toppings directly. There are QQ 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 ll consecutive slices at once. Second, the sum of the topping flavors on those ll slices must be the same for every possible set of ll consecutive slices. Third, NN slices split into groups of ll must leave no slice over, so NN is always a multiple of ll. 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 ll 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 NN, ll, and the number of orders QQ, separated by spaces. (1≤l≤N≤1,000,000,000,1≤Q≤100,000(1 \leq l \leq N \leq 1,000,000,000, 1 \leq Q \leq 100,000, and NN is always divisible by l)l)

Each of the next QQ lines contains one request in one of the following forms.

1 xx tt: Adds a topping with flavor tt to slice xx. (1≤x≤N,1≤t≤1,000,000,000)(1 \leq x \leq N, 1 \leq t \leq 1,000,000,000) If slice xx already has a topping, removes it and replaces it with a topping of flavor tt.

2 xx: Removes the topping from slice xx. The problem guarantees that slice xx has a topping. (1≤x≤N)(1 \leq x \leq N)

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 ll consecutive slices. If the order cannot be accepted, print NO.

Examples2

  1. Example 1

    Input
    10 2 10
    1 9 1
    1 6 9
    2 9
    1 5 2
    1 3 8
    2 3
    1 9 5
    2 9
    2 5
    2 6
    
    Expected output
    YES 1
    YES 10
    YES 9
    YES 11
    NO
    YES 11
    NO
    YES 11
    YES 9
    YES 0
    
  2. Example 2

    Input
    6 2 10
    1 2 4
    2 2
    1 2 10
    1 6 8
    2 2
    1 6 5
    1 5 2
    2 5
    2 6
    1 1 9
    
    Expected output
    YES 4
    YES 0
    YES 10
    NO
    YES 8
    YES 5
    YES 7
    YES 5
    YES 0
    YES 9