5.14 _ div 3

A B都很顺利的用20分钟就做了出来还是挺让我满意的,甚至有点膨胀。

B 题直接巧用priority_queue,a 是greater,b 是less 。如果a.top >b.top就交换。

要注意的是每次输出完a  b都要清空

 for(i=0;i

 

不过C 题就让我卡死了

C. Board Moves

 

You are given a board of size n×nn×n, where nn is odd (not divisible by 22). Initially, each cell of the board contains one figure.

In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i,j)(i,j) you can move the figure to cells:

  • (i−1,j−1)(i−1,j−1);
  • (i−1,j)(i−1,j);
  • (i−1,j+1)(i−1,j+1);
  • (i,j−1)(i,j−1);
  • (i,j+1)(i,j+1);
  • (i+1,j−1)(i+1,j−1);
  • (i+1,j)(i+1,j);
  • (i+1,j+1)(i+1,j+1);

Of course, you can not move figures to cells out of the board. It is allowed that after a move there will be several figures in one cell.

Your task is to find the minimum number of moves needed to get all the figures into one cell (i.e. n2−1n2−1 cells should contain 00 figures and one cell should contain n2n2 figures).

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤2001≤t≤200) — the number of test cases. Then tt test cases follow.

The only line of the test case contains one integer nn (1≤n<5⋅1051≤n<5⋅105) — the size of the board. It is guaranteed that nn is odd (not divisible by 22).

It is guaranteed that the sum of nn over all test cases does not exceed 5⋅1055⋅105 (∑n≤5⋅105∑n≤5⋅105).

Output

For each test case print the answer — the minimum number of moves needed to get all the figures into one cell.

Example

input

3
1
5
499993

output

0
40
41664916690999888

我觉得这题不应该做不对,vc用不了 long long, 这是个很伤的事,在测试的时候容易出错,我的主体代码在下面

   int kk=1;
   int c=8;
   long int ans=0;
	for(int i=1;i<=a;i++)
	{
		
        ans+=c*kk;
		c+=8;
		kk++;
	
	}

 在vc里就只显示一个1593219664,再大一个就输出负数了,想不明白,答案给的代码和我的并没有实质上的不同,只是它很简练的找到了一个通项公式,看来下次我也应该多从数学的角度在前几题试一下,或者说是多从不同的方向试一下啊。

我还不服给换成答案给的代码也还是一个1593219664。

我还不知道怎么解决,

 

因为C题实在通过不了,我就专心开始攻破D题

D. Constructing the Array

You are given an array aa of length nn consisting of zeros. You perform nn actions with this array: during the ii-th action, the following sequence of operations appears:

  1. Choose the maximum by length subarray (continuous subsegment) consisting only of zeros, among all such segments choose the leftmost one;
  2. Let this segment be [l;r][l;r]. If r−l+1r−l+1 is odd (not divisible by 22) then assign (set) a[l+r2]:=ia[l+r2]:=i (where ii is the number of the current action), otherwise (if r−l+1r−l+1 is even) assign (set) a[l+r−12]:=ia[l+r−12]:=i.

Consider the array aa of length 55 (initially a=[0,0,0,0,0]a=[0,0,0,0,0]). Then it changes as follows:

  1. Firstly, we choose the segment [1;5][1;5] and assign a[3]:=1a[3]:=1, so aa becomes [0,0,1,0,0][0,0,1,0,0];
  2. then we choose the segment [1;2][1;2] and assign a[1]:=2a[1]:=2, so aa becomes [2,0,1,0,0][2,0,1,0,0];
  3. then we choose the segment [4;5][4;5] and assign a[4]:=3a[4]:=3, so aa becomes [2,0,1,3,0][2,0,1,3,0];
  4. then we choose the segment [2;2][2;2] and assign a[2]:=4a[2]:=4, so aa becomes [2,4,1,3,0][2,4,1,3,0];
  5. and at last we choose the segment [5;5][5;5] and assign a[5]:=5a[5]:=5, so aa becomes [2,4,1,3,5][2,4,1,3,5].

Your task is to find the array aa of length nn after performing all nn actions. Note that the answer exists and unique.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.

The only line of the test case contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the length of aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑n≤2⋅105).

Output

For each test case, print the answer — the array aa of length nn after performing nn actions described in the problem statement. Note that the answer exists and unique.

Example

input

6
1
2
3
4
5
6

output

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

我的英语太差了,每次看复杂一点的题就头大,看了好长时间才明白这题的意思。

刚开始每个数组都是0, 就是每一步选择最大的全0区间,如果有多个就选择最左边的,然后给区间中间的数标记上数字,如果是偶数个数的区间,即选择中间靠左的位置。

就是简单来说从1~n 每一步选择一个位置,还真的挺难写的。

要把这题做出来应该首先要求队列运用的非常熟练,cf上给的答案,好多地方不明白是什么意思。还是看了好几个博客才搞明白这题大概的思路。

就是用一个优先队列来一步步取,定义排序规则,先以长度为标准再以开始点为标准。然后每一步进行的时候把最中间的数标上号,再把每一步产生的新区间加入到队列中。

#include

using namespace std;
const int maxn=2e5+100;

struct node {
    int l,r,len;
    bool operator < (const node &p) const {
        if (len==p.len)
            return l>=p.l;
        else
            return len q;
int a[maxn];
int t,n;

int main () {
    cin>>t;
    while (t--) {
        cin>>n;
        q.push({1,n,n});
        int tot=0;
        while (!q.empty()) {
            node u=q.top();
            q.pop();
            int mid=(u.l+u.r)>>1;
            a[mid]=++tot;

            if (u.l<=mid-1) q.push({u.l,mid-1,mid-u.l});
            if (mid+1<=u.r) q.push({mid+1,u.r,u.r-mid});
        }
        for (int i=1;i<=n;i++) cout<

 

你可能感兴趣的:(5.14 _ div 3)