F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

M. Minimal and Maximal XOR Sum

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 611    Accepted Submission(s): 278


Problem Description
Given a permutation $p_1, p_2, \dots, p_n$ of $1 \sim n$. You can perform several operations.

In each operation you can choose an interval $[l,r]$ and reverse the elements $p_l,p_{l + 1}, \dots,p_r$ to $p_r, p_{r - 1}, \dots,p_l$, the weight of this operation is $r-l+1$.

You can perform any number of operations, and your goal is to make $p_i=i$ at last.

Please calculate the minimal and maximal XOR sum of the weight of all the operations.
 

Input
The input consists of multiple test cases. The first line contains a single integer $T$ ($1 \le T \le 2 \times 10 ^ 5$) - the number of test cases. Description of the test cases follows.

The first line of each test case contains one integer $n$ ($1\leq n\leq 10^5$).

The second line contains $n$ integers $p_1, p_2, \dots, p_n$.

It's guaranteed that $\sum n \leq 6\times10^5$.
 

Output
For each test case, print two integers - the minimal and maximal XOR sum of the weight of all the operations.
 

Sample Input
3 3 1 3 2 3 3 1 2 6 1 2 5 6 3 4
 

Sample Output
2 3 0 1 0 5
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-11 20:23:03, Gzip enabled