Codeforces #663 (Div. 2) A. Suborrays

A. Suborrays

原题链接:https://codeforces.com/contest/1391/problem/A

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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

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

  • ( p i (p_i (pi O R OR OR p i + 1 p_{i+1} pi+1 O R OR OR … … O R OR OR p j − 1 p_{j−1} pj1 O R OR OR p j ) ≥ j − i + 1 p_j)≥j−i+1 pj)ji+1 , where O R OR OR denotes the bitwise O R OR OR operation.

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

Given a positive integer n n n, output any good permutation of length n 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 ( 1 ≤ t ≤ 100 ) t (1≤t≤100) t(1t100). Description of the test cases follows.

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

Output
For every test, output any good permutation of length 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, [ 3 , 1 , 2 ] [3,1,2] [3,1,2] is a good permutation. Some of the subarrays are listed below.

  • 3 3 3 O R OR OR 1 1 1 = 3 ≥ 2 ( i = 1 , j = 2 ) =3≥2 (i=1,j=2) =32(i=1,j=2)
  • 3 3 3 O R OR OR 1 1 1 O R OR OR 2 = 3 ≥ 3 ( i = 1 , j = 3 ) 2=3≥3 (i=1,j=3) 2=33(i=1,j=3)
  • 1 1 1 O R OR OR 2 = 3 ≥ 2 ( i = 2 , j = 3 ) 2=3≥2 (i=2,j=3) 2=32(i=2,j=3)
  • 1 ≥ 1 ( i = 2 , j = 2 ) 1≥1 (i=2,j=2) 11(i=2,j=2)
    Similarly, you can verify that [ 4 , 3 , 5 , 2 , 7 , 1 , 6 ] [4,3,5,2,7,1,6] [4,3,5,2,7,1,6] is also good.

题意:输入一个长度n,用 1 1 1 ~ n n n的数字进行随机排列。定义对于一个正整数n,如果对于每一对 i i i j ( 1 ≤ i ≤ j ≤ n ) j(1≤i≤j≤n) j(1ijn)都满足,对于p的每个子数组,其中所有元素的OR不小于该子数列中元素的个数。我们称长度为 n n n 的排列 p p p 是好的。
题解:两个数进行位运算了,且范围是1~n,那么进行位运算后的结果不会小于元素的个数。简而言之就是:无论怎么输出这个置换序列都是正确的。(我是逆序输出的。)

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		for (int i = n; i >= 1; i--)
			printf("%d ",i);
		cout << endl;
	}
	return 0;
}

其实这次的div2做的有点像div3的难度。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>