CF 1547D Co-growing Sequence
阿新 • • 發佈:2021-07-12
CF 1547D Co-growing Sequence
D Co-growing Sequence
來源:https://codeforces.com/problemset/problem/1547/D
題目簡述
定義一個數列為growing: 對於數列a, i從1到n-1,ai & ai+1=ai
For example, the following four sequences are growing: [2,3,15,175] — in binary it's [10,11,1111,10101111]; [5] — in binary it's [101]; [1,3,7,15] — in binary it's [1,11,111,1111]; [0,0,0] — in binary it's [0,0,0]. The following three sequences are non-growing: [3,4,5] — in binary it's [11,100,101]; [5,4,3] — in binary it's [101,100,011]; [1,2,4,8] — in binary it's [0001,0010,0100,1000].
定義兩個數列為co-growing :對於數列x和y,(x1^y1 , x2^y2 , ... , xn^yn)所組成的數列為growing.
現給出x數列,求能和其組成co-growing的最小y數列,更小指的是第一個不相同的數更小。
Input
第一行為整數t(1≤t≤10^4)。接下來是t個測試用例。
每個測試用例的第一行包含一個整數n(1≤n≤2⋅10^5)-序列xi的長度。
第二行包含n個整數x1,x2,…,xn(0≤xi<2^30) -序列xi的元素。
所有測試用例的n總和不超過2⋅10^5。
Output
對於每個測試用例,輸出n個整數y1,y2,…,yn(0≤yi<2^30) -字典序最小序列, 使其與給定序列xi co-growing。
Sample Input
5
4
1 3 7 15
4
1 2 4 8
5
1 2 3 4 5
4
11 13 15 1
1
0
Sample Output
0 0 0 0
0 1 3 7
0 1 0 3 2
0 2 0 14
0
More Info
無
題目思路
觀察規律得xi+yi = (x1 | x2 | ..... | xi).
程式碼
#include <bits/stdc++.h> using namespace std; #define ll long long const int N=200005; int n,t; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>t; while(t--){ cin>>n; int a[N]; for(int i=1;i<=n;i++) cin>>a[i]; cout<<0<<' '; int p=a[1]; for(int i=2;i<=n;i++){ p|=a[i]; cout<<p-a[i]<<' '; } cout<<endl; } return 0; }