当前位置: 代码迷 >> 综合 >> 1391/A A. Suborrays
  详细解决方案

1391/A A. Suborrays

热度:28   发布时间:2024-02-10 07:32:53.0

A. Suborrays

http://codeforces.com/contest/1391/A

题面:

A permutation of length n n is an array consisting of n n distinct integers from 1 1 to n n in arbitrary order. For example, [ 2 , 3 , 1 , 5 , 4 ] [2,3,1,5,4] is a permutation, but [ 1 , 2 , 2 ] [1,2,2] is not a permutation ( 2 2 appears twice in the array) and [ 1 , 3 , 4 ] [1,3,4] is also not a permutation ( n = 3 n=3 but there is 4 4 in the array).

For a positive integer n n , we call a permutation p p of length n n good if the following condition holds for every pair i i and j j ( 1 i j n 1 \le i \le j \le n ) —

( p i  OR  p i + 1  OR   OR  p j ? 1  OR  p j ) j ? i + 1 (p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1 , where OR \text{OR} denotes the bitwise OR operation.

In other words, a permutation p p is good if for every subarray of p p , the OR \text{OR} of all elements in it is not less than the number of elements in that subarray.

Given a positive integer n n , output any good permutation of length n n . We can show that for the given constraints such a permutation always exists.

Input

Each test contains multiple test cases. The first line contains the number of test cases t t ( 1 t 100 1 \le t \le 100 ). Description of the test cases follows.

The first and only line of every test case contains a single integer n n ( 1 n 100 1 \le n \le 100 ).

Output

For every test, output any good permutation of length n n on a separate line.

Example

input
3
1
3
7
output
1
3 1 2
4 3 5 2 7 1 6
Note

For n = 3 n = 3 , [ 3 , 1 , 2 ] [3,1,2] is a good permutation. Some of the subarrays are listed below.

3  OR  1 = 3 2 3\text{ OR }1 = 3 \geq 2 ( i = 1 , j = 2 ) (i = 1,j = 2)

3  OR  1  OR  2 = 3 3 3\text{ OR }1\text{ OR }2 = 3 \geq 3 ( i = 1 , j = 3 ) (i = 1,j = 3)

1  OR  2 = 3 2 1\text{ OR }2 = 3 \geq 2 ( i = 2 , j = 3 ) (i = 2,j = 3)

1 1 1 \geq 1 ( i = 2 , j = 2 ) (i = 2,j = 2)

Similarly, you can verify that [ 4 , 3 , 5 , 2 , 7 , 1 , 6 ] [4,3,5,2,7,1,6] is also good.

翻译:

一个排列permutation长度为 n n 是一个数组,组成consisting 是n个不同的整数从 1 1 n n 任意arbitrary 顺序 order。例如, [ 2 , 3 , 1 , 5 , 4 ] [2,3,1,5,4] , 是一个排列,但是 [ 1 , 2 , 2 ] [1,2,2] 不是一个排列(2出现了两次在数组里) 并且 [ 1 , 3 , 4 ] [1,3,4] 也不是排列(n = 3 但是这里有 4 在数组里)。

对于正整数 n,我们叫排列 P 长度为 n 是好,如果他以下following 情况condition 保持,对于每一对 i i and j j ( 1 i j n 1 \le i \le j \le n ) — ( p i  OR  p i + 1  OR   OR  p j ? 1  OR  p j ) j ? i + 1 (p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1 ,,其中OR代表denotes 按位bitwise OR 运算符 operation 运算

换句话说In other words,P排列是一个好的 如果对于每一个子数组subarray 从P中,所有元素的OR不小于元素的数量在子数组中。

给一个正整数 N,输出任意好的排列 长度为 n。我们证明show 对于给定的约束constraints ,这样的一个排列总是存在的。

题意:

( p i  OR  p i + 1  OR   OR  p j ? 1  OR  p j ) j ? i + 1 (p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1

给你一个从 1 到 n 的数组,求一个排列,满足上面的式子。

题解:

有个 OR 的规律:
a  OR  b a + b a \text{ OR } b \ge a + b
所以任意两个 O R OR ,一定大于两个数相加。

那么,将数组从 1 到 n 输出,就算每次增加最小的加一,最后也是满足上面的规则。

代码:

#include <bits/stdc++.h>
using namespace std;int main(void)
{int T;cin>>T;while(T--){int n;cin>>n;for(int i=1; i<=n; i++){cout<<i<<" ";}cout<<endl;}return 0;
}