HDU 6129 Just do it(複数校正7、組合せ数法則)
タイトル:
数列、m回変換して、b[i]=a[1]~a[i]の異種または値を変換します.最後のシーケンスを求めます.
考え方:
法則を探すテーマです.
各数の後の数への寄与を考慮する.
まずa 1を考慮する:
1回目の変換:1 1 1 1 1 1
2回目の変換:1 2 3 4 5
3回目の変換:1 3 6 10 15
4回目の変換:1 4 10 20 35
各行が楊輝三角の斜辺であることは容易に発見できる.
したがって、f(x,y)=C(x+y-2,y-1)において、f(x,y)は変換x回、a 1のy番目の位置数への寄与値を表す.
では、この組み合わせ数が奇数なのか偶数なのかだけを考えてみましょう.
簡単な式C(x,y)は奇数であり、(x&y)==yの場合にのみ満たされる.
そして、どのようにすべての貢献を計算するかを考えています.私たちはa 1の貢献を計算しているからです.a 2、a 3、a 4の貢献はa 1の位置から右に移動して、移動して帰ってもいいです.
したがって,a 1の寄与値を列挙し,奇数の場合,後続の寄与を計算した.
Just do it
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 1113 Accepted Submission(s): 648
Problem Description
There is a nonnegative integer sequence
a1...n of length
n. HazelFan wants to do a type of transformation called prefix-XOR, which means
a1...n changes into
b1...n, where
bi equals to the XOR value of
a1,...,ai. He will repeat it for
m times, please tell him the final sequence.
Input
The first line contains a positive integer
T(1≤T≤5), denoting the number of test cases.
For each test case:
The first line contains two positive integers
n,m(1≤n≤2×105,1≤m≤109).
The second line contains
n nonnegative integers
a1...n(0≤ai≤230−1).
Output
For each test case:
A single line contains
n nonnegative integers, denoting the final sequence.
Sample Input
2 1 1 1 3 3 1 2 3
Sample Output
1 1 3 1
Source
2017 Multi-University Training Contest - Team 7
Recommend
liuyiding | We have carefully selected several similar problems for you: 6132 6131 6130 6129 6128
Statistic | Submit | Discuss | Note
数列、m回変換して、b[i]=a[1]~a[i]の異種または値を変換します.最後のシーケンスを求めます.
考え方:
法則を探すテーマです.
各数の後の数への寄与を考慮する.
まずa 1を考慮する:
1回目の変換:1 1 1 1 1 1
2回目の変換:1 2 3 4 5
3回目の変換:1 3 6 10 15
4回目の変換:1 4 10 20 35
各行が楊輝三角の斜辺であることは容易に発見できる.
したがって、f(x,y)=C(x+y-2,y-1)において、f(x,y)は変換x回、a 1のy番目の位置数への寄与値を表す.
では、この組み合わせ数が奇数なのか偶数なのかだけを考えてみましょう.
簡単な式C(x,y)は奇数であり、(x&y)==yの場合にのみ満たされる.
そして、どのようにすべての貢献を計算するかを考えています.私たちはa 1の貢献を計算しているからです.a 2、a 3、a 4の貢献はa 1の位置から右に移動して、移動して帰ってもいいです.
したがって,a 1の寄与値を列挙し,奇数の場合,後続の寄与を計算した.
#include
#include
#include
using namespace std;
const int maxn = 200000 + 10;
int a[maxn], ans[maxn];
int main(){
int T;
scanf("%d",&T);
while(T--){
int n, m;
scanf("%d %d",&n, &m);
for (int i = 1; i <= n; ++i){
scanf("%d",a+i);
ans[i] = 0;
}
for (int i = 1; i <= n; ++i){
int x = i + m - 2;
int y = i-1;
if ((x&y)==y){
for (int j = i; j <= n; ++j){
ans[j] ^= a[j-i+1];
}
}
}
for (int i = 1; i <= n; ++i){
if (i > 1)putchar(' ');
printf("%d", ans[i]);
}
putchar('
');
}
return 0;
}
Just do it
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 1113 Accepted Submission(s): 648
Problem Description
There is a nonnegative integer sequence
a1...n of length
n. HazelFan wants to do a type of transformation called prefix-XOR, which means
a1...n changes into
b1...n, where
bi equals to the XOR value of
a1,...,ai. He will repeat it for
m times, please tell him the final sequence.
Input
The first line contains a positive integer
T(1≤T≤5), denoting the number of test cases.
For each test case:
The first line contains two positive integers
n,m(1≤n≤2×105,1≤m≤109).
The second line contains
n nonnegative integers
a1...n(0≤ai≤230−1).
Output
For each test case:
A single line contains
n nonnegative integers, denoting the final sequence.
Sample Input
2 1 1 1 3 3 1 2 3
Sample Output
1 1 3 1
Source
2017 Multi-University Training Contest - Team 7
Recommend
liuyiding | We have carefully selected several similar problems for you: 6132 6131 6130 6129 6128
Statistic | Submit | Discuss | Note