This page is still under construction.

Parts of this page are still being built. What you see may change.

The Locksmith

Time limit1sMemory limit1024 MB

Summary
Maintain a dynamic set of arithmetic progressions (a mod b) and answer point queries asking whether any active progression contains a given lock number.
Level

Hard8 of 10

Topics
Math, Number theory, Implementation, Brute force
Solved
No attempts yet

Problem

The locksmith Lårs has been put in charge of handing out keys to the locks of Mattelandet. The country has NN locks, numbered 1,2,…,N1,2,\ldots,N. Every inhabitant has a key that opens certain locks in the country (those the inhabitant is allowed to open).

Whenever a person moves into the country, Lårs gives them a key consisting of two numbers a,ba,b. The person can then open every lock with a number mm satisfying m≡a(modb)m\equiv a \pmod{b}. (Here ≡\equiv denotes congruence. Two numbers x,yx,y are said to be congruent modulo nn, written x≡y(modn)x\equiv y \pmod{n}, if n∣(x−y)n|(x-y), that is, x−yx-y is evenly divisible by nn. This is the same as xx and yy having the same remainder when divided by nn. In most programming languages it can be written as x%n==y%nx\%n==y\%n.) When a person moves out of the country, Lårs takes back their key.

There are three types of events that Lårs, as the person in charge of locks, has to handle: answering the question of whether some inhabitant can open a specific lock, someone moving into the country, and someone moving out of the country. For every question about whether there is some inhabitant who can open a specific lock, Lårs must answer "ja" or "nej". Initially nobody lives in the country.

Input

The first line contains two integers N,QN,Q, the number of locks and the number of events (1≤N,Q≤2⋅1051\leq N,Q \leq 2\cdot 10^5).

Then come QQ lines, each in one of the following forms:

  • 1x1\enspace x, a question about whether there is some inhabitant who can open lock xx (1≤x≤N1\leq x \leq N).
  • 2ab2\enspace a\enspace b, someone moves into the country and receives key a,ba,b which works as described above (0≤a<b≤N0\leq a < b \leq N).
  • 3ab3\enspace a\enspace b, someone with key a,ba,b moves out of the country and Lårs takes back their key. It is guaranteed that a person with key a,ba,b has previously moved into the country (0≤a<b≤N0\leq a < b \leq N).

Output

For every question about whether someone can unlock a specific lock (lines whose first number is 1), print "ja" if the lock can be opened by some inhabitant currently living in the country, or "nej" if the lock cannot be opened.

Hint

In the first example there is initially no key, so lock 77 cannot be opened. Then a key is added that makes every integer mm with m≡1(mod  3)m\equiv 1 (\mod 3) open locks, so lock 77 can be opened. Finally the key is removed, and lock 77 can no longer be opened.

In the second example two identical keys are handed out. When one of them is taken back, lock 77 can still be opened (that is, all identical keys are not taken back at the same time).

Examples4

  1. Example 1

    Input
    10 5
    1 7
    2 1 3
    1 7
    3 1 3
    1 7
    
    Expected output
    nej
    ja
    nej
    
  2. Example 2

    Input
    7 7
    1 7
    2 1 3
    1 7
    2 1 3
    1 7
    3 1 3
    1 7
    
    Expected output
    nej
    ja
    ja
    ja
    
  3. Example 3

    Input
    20 8
    2 2 3
    2 0 2
    1 7
    1 8
    1 9
    3 0 2
    1 8
    1 5
    
    Expected output
    nej
    ja
    nej
    ja
    ja
    
  4. Example 4

    Input
    200000 7
    1 200000
    2 2 3
    1 200000
    2 0 1
    1 200000
    3 2 3
    1 200000
    
    Expected output
    nej
    ja
    ja
    ja