AtCoder Regular Contest 077

 

C - pushpush


Time Limit: 2 sec / Memory Limit: 256 MB

Score : 300300 points

Problem Statement

You are given an integer sequence of length nn, a1,...,ana1,...,an. Let us consider performing the following nn operations on an empty sequence bb.

The ii-th operation is as follows:

  1. Append aiai to the end of bb.
  2. Reverse the order of the elements in bb.

Find the sequence bb obtained after these nn operations.

Constraints

  • 1≤n≤2×1051≤n≤2×105
  • 0≤ai≤1090≤ai≤109
  • nn and aiai are integers.

Input

Input is given from Standard Input in the following format:

nn
a1a1 a2a2 ...... anan

Output

Print nn integers in a line with spaces in between. The ii-th integer should be bibi.


Sample Input 1 Copy

Copy

4
1 2 3 4

Sample Output 1 Copy

Copy

4 2 1 3
  • After step 1 of the first operation, bb becomes: 11.
  • After step 2 of the first operation, bb becomes: 11.
  • After step 1 of the second operation, bb becomes: 1,21,2.
  • After step 2 of the second operation, bb becomes: 2,12,1.
  • After step 1 of the third operation, bb becomes: 2,1,32,1,3.
  • After step 2 of the third operation, bb becomes: 3,1,23,1,2.
  • After step 1 of the fourth operation, bb becomes: 3,1,2,43,1,2,4.
  • After step 2 of the fourth operation, bb becomes: 4,2,1,34,2,1,3.

Thus, the answer is 4 2 1 3.


Sample Input 2 Copy

Copy

3
1 2 3

Sample Output 2 Copy

Copy

3 1 2

As shown above in Sample Output 1, bb becomes 3,1,23,1,2 after step 2 of the third operation. Thus, the answer is 3 1 2.


Sample Input 3 Copy

Copy

1
1000000000

Sample Output 3 Copy

Copy

1000000000

Sample Input 4 Copy

Copy

6
0 6 7 6 7 0

Sample Output 4 Copy

Copy

0 6 6 0 7 7

题意:

输入N,后面有N个数,代表:a1,a2,a3, ... ,aN,我们将会对b这个空序列进行N个操作

第i个操作进行如下处理:

  • 在b序列的末尾加入a[i]

  • 翻转b序列

分析:

规律题

最后一个和倒数第二个会被加到b的开头和末尾,

b:a[n]  .....a[n-1]

b:a[n]  a[n-2]  .....a[n-3]  a[1]

依此类推

#include
using namespace std;
typedef long long LL;
const int N=200005;
const int MOD=1e9+7;
int n;
int a[N];
int b[N];
int main()
{

    cin>>n;
   for(int i=1;i<=n;i++)
   {
   	scanf("%d",&a[i]);
   }
   int m=n;
   int j=1;
   for(int i=n;i>=2;i-=2)
   {
   	b[j]=a[i];
   	b[n-j+1]=a[i-1];
   	j++;
   }
   if(n&1)
   {
   	b[j]=a[1];
   }
   
   for(int i=1;i<=n;i++)
   	printf("%d ",b[i]);
   
    return 0;

}

 

D - 11


Time Limit: 2 sec / Memory Limit: 256 MB

Score : 600600 points

Problem Statement

You are given an integer sequence of length n+1n+1, a1,a2,...,an+1a1,a2,...,an+1, which consists of the nn integers 1,...,n1,...,n. It is known that each of the nn integers 1,...,n1,...,n appears at least once in this sequence.

For each integer k=1,...,n+1k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length kk, modulo 109+7109+7.

Notes

  • If the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.

  • A subsequence of a sequence aa with length kk is a sequence obtained by selecting kk of the elements of aa and arranging them without changing their relative order. For example, the sequences 1,3,51,3,5 and 1,2,31,2,3 are subsequences of 1,2,3,4,51,2,3,4,5, while 3,1,23,1,2 and 1,10,1001,10,100 are not.

Constraints

  • 1≤n≤1051≤n≤105
  • 1≤ai≤n1≤ai≤n
  • Each of the integers 1,...,n1,...,n appears in the sequence.
  • nn and aiai are integers.

Input

Input is given from Standard Input in the following format:

nn
a1a1 a2a2 ... an+1an+1

Output

Print n+1n+1 lines. The kk-th line should contain the number of the different subsequences of the given sequence with length kk, modulo 109+7109+7.


Sample Input 1 Copy

Copy

3
1 2 1 3

Sample Output 1 Copy

Copy

3
5
4
1

There are three subsequences with length 11: 11 and 22 and 33.

There are five subsequences with length 22: 1,11,1 and 1,21,2 and 1,31,3 and 2,12,1 and 2,32,3.

There are four subsequences with length 33: 1,1,31,1,3 and 1,2,11,2,1 and 1,2,31,2,3 and 2,1,32,1,3.

There is one subsequence with length 44: 1,2,1,31,2,1,3.


Sample Input 2 Copy

Copy

1
1 1

Sample Output 2 Copy

Copy

1
1

There is one subsequence with length 11: 11.

There is one subsequence with length 22: 1,11,1.


Sample Input 3 Copy

Copy

32
29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9

Sample Output 3 Copy

Copy

32
525
5453
40919
237336
1107568
4272048
13884156
38567100
92561040
193536720
354817320
573166440
818809200
37158313
166803103
166803103
37158313
818809200
573166440
354817320
193536720
92561040
38567100
13884156
4272048
1107568
237336
40920
5456
528
33
1

Be sure to print the numbers modulo 109+7109+7.

题意:

n+1个数,有一个数出现两次,求长度为k属于1~n+1的不重复序列个数。

分析:

长度k:一共有C(n+1,k)个子序列

但对于

2 1  1 4

k=2:2 1和 1 4只能属于一个

所以需要减去C(n-pos2+pos1,k)

n-pos2减去与以后面开始的长度为k的子序列

pos1减去前面的数构成的序列中间经过pos2的长度为k的子序列

需要求组合数对%1e9+7(需要预处理1!~n!的逆元)

​
#include
using namespace std;
typedef long long LL;
const LL N=1e5+100; 
const LL MOD=1e9+7;

int n;
LL a[N];
int v[N];
 
LL fac[N],finv[N],inv[N];
 
void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<100010;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]* i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
LL C(int x,int y)
{
	if(x>n;
    for(int i = 1; i <= n + 1; ++i){
        cin >> a[i];
        v[a[i]]++;
    }
    LL pos1,pos2;
    for(int i = 1; i <= n + 1; ++i){
        if(v[a[i]] == 2 && !pos1){
            pos1 = i;
        }
        else if(v[a[i]] == 2) {
            pos2 = i;
        }
    }
	LL ans;
	make();
	for (int i=0;i<=n;i++)
	{
		ans=C(n+1,i+1);
		ans-=C(n-pos2+pos1,i);
		if (ans<0) ans+=MOD;
		printf("%d\n",ans);	
	}
	return 0;
}

​

 

你可能感兴趣的:(数学——组合数学,好题,ATcoder比赛,模板)