Lexicographic Comparison
Time limit2sMemory limit1024 MB
Given permutations a and p under position swaps, compare A_x and A_y lexicographically, where A_k is a with p applied k-1 times.
- Level
Hard8 of 10
- Topics
- Array, String matching, Binary search, Segment tree
- Solved
- No attempts yet
Problem
Consider and , two permutations of length . Initially, for all . Let be a sequence of permutations such that and for all and .
There are three types of operations, where and are positive integers:
swap_a: swap and , where .swap_p: swap and , where .cmp: compare with lexicographically.
For each operation of type 3, output the relationship between and . A permutation is lexicographically smaller than a permutation if and only if there exists an index such that and for all .
Input
The first line contains an integer (), the number of test cases. For each test case:
The first line contains integers and (), the length of the permutations and the number of operations.
Each of the following lines contains a string and two integers and representing an operation. The string is one of swap_a, swap_p, and cmp. If is swap_a or swap_p, then . If is cmp, then .
The sum of and the sum of over all tests do not exceed .
Output
For each test case, output one line per cmp query. Output < if is lexicographically smaller than , > if is lexicographically greater than (that is, is lexicographically smaller than ), and = if .