问题 M: Minimal and Maximal XOR Sum

内存限制:512 MB 时间限制:4 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

Given a permutation p1,p2,,pn of 1n. You can perform several operations.

In each operation you can choose an interval [l,r] and reverse the elements pl,pl+1,,pr to pr,pr1,,pl, the weight of this operation is rl+1.

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

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

 

输入格式

The input consists of multiple test cases. The first line contains a single integer T (1T2×105) - the number of test cases. Description of the test cases follows.

The first line of each test case contains one integer n (1n105).

The second line contains n integers p1,p2,,pn.

It's guaranteed that n6×105.

 

输出格式

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

输入样例 复制

3
3
1 3 2
3
3 1 2
6
1 2 5 6 3 4

输出样例 复制

2 3
0 1
0 5

分类标签