Dhaka Regional ACM ICPC 2016 Mock Contest Solution F - Process and Resources

F. Process and Resources

Score: 1

CPU: 1s
Memory: 1200MB

In operating systems, one of the major concerns is about process and resource management. Now you are to find whether a given process can be assigned to a given resource. In this problem, there will be two types of queries,

  • Query type 1:
    • You will be given a process id (pid) and a resource id (rid). If the resource is already free (initially all resources are free), then output ‘Y’ and the resource will be hold by this process. Otherwise output ‘N’ (even if the resource is already held by this process).
  • Query type 2:
    • You will be given a resource id. If the resource is already free output ‘F’, otherwise output the pid of the process which holds the resource and free the resource.

Input

The first line of the input file contains the number of test case T (1 <= T <= 25). Each test case starts with the number of query Q (1 <= Q <= 100000). Each of Q lines starts with the query type (either 1 or 2), then pid and rid (for type 1) or rid (for type 2) separated by spaces, where ( 0 < pid <= 2^63-1) and (0 < rid <= 2*10^7)

Output

For each query, output expected output described above. For clarification, see sample input/output.

Sample

InputOutput
1 4 1 100 1 1 101 1 2 1 1 101 1Y N 100 Y




















Comments

Popular posts from this blog

Solution - Codeforces Problem 327B - Hungry Sequence

Solution - Timus Problem 1293. Eniya

Solution - Timus Problem 1409. Two Gangsters