text
stringlengths
0
801
* write number: write the minimum positive integer that isn't present in the array $a$ to the element $a_i$, $i$ is the position where the pointer points at. Such operation can be performed only when $a_i = -1$. * carriage return: return the pointer to its initial position (i.e. $1$ for the first typewriter, $n$ for the second) * move pointer: move the pointer to the next position, let $i$ be the position the pointer points at before this operation, if Misuki is using the first typewriter, $i := i + 1$ would happen, and $i := i - 1$ otherwise. Such operation can be performed only if after the operation, $1 \le i \le n$ holds.
Your task is to construct any permutation $p$ of length $n$, such that the minimum number of carriage return operations needed to make $a = p$ is the same no matter which typewriter Misuki is using.
Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 500$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the permutation.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
For each test case, output a line of $n$ integers, representing the permutation $p$ of length $n$ such that the minimum number of carriage return operations needed to make $a = p$ is the same no matter which typewriter Misuki is using, or $-1$ if it is impossible to do so.
If there are multiple valid permutations, you can output any of them.
In the
This is an interactive problem.
Misuki has chosen a secret tree with $n$ nodes, indexed from $1$ to $n$, and asked you to guess it by using queries of the following type:
* "? a b" — Misuki will tell you which node $x$ minimizes $|d(a,x) - d(b,x)|$, where $d(x,y)$ is the distance between nodes $x$ and $y$. If more than one such node exists, Misuki will tell you the one which minimizes $d(a,x)$.
Find out the structure of Misuki's secret tree using at most $15n$ queries!
Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 200$) — the number of test cases.
Each test case consists of a single line with an integer $n$ ($2 \le n \le 1000$), the number of nodes in the tree.
It is guaranteed that the sum of $n$ across all test cases does not exceed $1000$.
A tree is an undirected acyclic connected graph. A tree with $n$ nodes will always have $n-1$ edges.
In the example case, the answer to "? 1 2" is $1$. This means that there is an edge between nodes $1$ and $2$.
The answer to "? 1 3" is $1$. This means that there is an edge between nodes $1$ and $3$.
The answer to "? 1 4" is $3$. It can be proven that this can only happen if node $3$ is connected to both node $1$ and $4$.
The edges of the tree are hence $(1,2)$, $(1,3)$ and $(3,4)$.
This is the hard version of the problem. The difference between the two versions is the definition of deterministic max-heap, time limit, and constraints on $n$ and $t$. You can make hacks only if both versions of the problem are solved.
Consider a perfect binary tree with size $2^n - 1$, with nodes numbered from $1$ to $2^n-1$ and rooted at $1$. For each vertex $v$ ($1 \le v \le 2^{n - 1} - 1$), vertex $2v$ is its left child and vertex $2v + 1$ is its right child. Each node $v$ also has a value $a_v$ assigned to it.
Define the operation $\mathrm{pop}$ as follows:
1. initialize variable $v$ as $1$; 2. repeat the following process until vertex $v$ is a leaf (i.e. until $2^{n - 1} \le v \le 2^n - 1$); 1. among the children of $v$, choose the one with the larger value on it and denote such vertex as $x$; if the values on them are equal (i.e. $a_{2v} = a_{2v + 1}$), you can choose any of them; 2. assign $a_x$ to $a_v$ (i.e. $a_v := a_x$); 3. assign $x$ to $v$ (i.e. $v := x$); 3. assign $-1$ to $a_v$ (i.e. $a_v := -1$).
Then we say the $\mathrm{pop}$ operation is deterministic if there is a unique way to do such operation. In other words, $a_{2v} \neq a_{2v + 1}$ would hold whenever choosing between them.
A binary tree is called a max-heap if for every vertex $v$ ($1 \le v \le 2^{n - 1} - 1$), both $a_v \ge a_{2v}$ and $a_v \ge a_{2v + 1}$ hold.
A max-heap is deterministic if the $\mathrm{pop}$ operation is deterministic to the heap when we do it for the first and the second time.
Initially, $a_v := 0$ for every vertex $v$ ($1 \le v \le 2^n - 1$), and your goal is to count the number of different deterministic max- heaps produced by applying the following operation $\mathrm{add}$ exactly $k$ times:
* Choose an integer $v$ ($1 \le v \le 2^n - 1$) and, for every vertex $x$ on the path between $1$ and $v$, add $1$ to $a_x$.
Two heaps are considered different if there is a node which has different values in the heaps.
Since the answer might be large, print it modulo $p$.
Each test con
Given an array of integers $s_1, s_2, \ldots, s_l$, every second, cosmic rays will cause all $s_i$ such that $i=1$ or $s_i\neq s_{i-1}$ to be deleted simultaneously, and the remaining parts will be concatenated together in order to form the new array $s_1, s_2, \ldots, s_{l'}$.
Define the strength of an array as the number of seconds it takes to become empty.
You are given an array of integers compressed in the form of $n$ pairs that describe the array left to right. Each pair $(a_i,b_i)$ represents $a_i$ copies of $b_i$, i.e. $\underbrace{b_i,b_i,\cdots,b_i}_{a_i\textrm{ times}}$.
For each $i=1,2,\dots,n$, please find the strength of the sequence described by the first $i$ pairs.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\le t\le10^4$). The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($1\le n\le3\cdot10^5$) — the length of sequence $a$.
The next $n$ lines contain two integers each $a_i$, $b_i$ ($1\le a_i\le10^9,0\le b_i\le n$) — the pairs which describe the sequence.
It is guaranteed that the sum of all $n$ does not exceed $3\cdot10^5$.
It is guaranteed that for all $1\le i<n$, $b_i\neq b_{i+1}$ holds.
For each test case, print one line containing $n$ integers — the answer for each prefix of pairs.
In the first test case, for the prefix of length $4$, the changes will be $[0,0,1,0,0,0,1,1,1,1,1]\rightarrow[0,0,0,1,1,1,1]\rightarrow[0,0,1,1,1]\rightarrow[0,1,1]\rightarrow[1]\rightarrow[]$, so the array becomes empty after $5$ seconds.
In the second test case, for the prefix of length $4$, the changes will be $[6,6,6,6,3,6,6,6,6,0,0,0,0]\rightarrow[6,6,6,6,6,6,0,0,0]\rightarrow[6,6,6,6,6,0,0]\rightarrow[6,6,6,6,0]\rightarrow[6,6,6]\rightarrow[6,6]\rightarrow[6]\rightarrow[]$, so the array becomes empty after $7$ seconds.
This is the easy version of the problem. In this version, $n=m$ and the time limit is lower. You can make hacks only if both versions of the problem are solved.
In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.
Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:
* after every round, $\gcd(W_L,W_F)\le 1$; * at the end of the match, $W_L\le n, W_F\le m$.
Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.
Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.
Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.