#P3586. [POI 2015 R2] 物流 Logistics

[POI 2015 R2] 物流 Logistics

Description

Maintain a sequence of length nn, initially all 00, supporting the following two operations:

  1. U k a: set the kk-th number in the sequence to aa.
  2. Z c s: on this sequence, each time choose cc positive numbers and subtract 11 from each; ask whether it is possible to perform ss such operations.

Each query is independent, i.e., each query does not modify the sequence.

Input Format

The first line contains two positive integers n,mn, m, denoting the length of the sequence and the number of operations.

The next mm lines contain the mm operations.

Output Format

Output several lines. For each Z query, print TAK if it is possible; otherwise, print NIE.

3 8
U 1 5
U 2 7
Z 2 6
U 3 1
Z 2 6
U 2 2
Z 2 6
Z 2 1

NIE
TAK
NIE
TAK

Hint

Constraints

For 100%100\% of the testdata, 1n,m1061\leq n,m\leq 10^6, 1k,cn1\leq k,c\leq n, 0a1090\leq a\leq 10^9, 1s1091\leq s\leq 10^9.

Original title: Logistyka.

Translated by ChatGPT 5