B. Omkar and Infinity Clock

传送门
B. Omkar and Infinity Clock
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem:
You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k operations with this array.Define one operation as the following: Set d to be the maximum value of your array.
For every i from 1 to n, replace ai with d−ai The goal is to predict the contents in the array after k operations. Please help Ray determine what the final sequence will look like!

Input
Each test contains multiple test cases. The first line contains the number of cases t(1≤t≤100). Description of the test cases follows.The first line of each test case contains two integers n and k (1≤n≤2⋅105,1≤k≤1018) – the length of your array and the number of operations to perform. The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109)– the initial contents of your array.It is guaranteed that the sum of n over all test cases does not exceed 2⋅105

Output
For each case, print the final version of array a after k operations described above.

Example
Input

3
2 1
-199 192
5 19
5 -1 4 2 0
1 2
69

Output

391 0
0 6 1 3 5
0

Note
In the first test case the array changes as follows: Initially, the array is [−199,192] d=192After the operation, the array becomes [d−(−199),d−192]=[391,0]

题意:输入一个n,k和一个a序列,你可以进行操作,计算出a中的最大值d,然后ai=d−ai​,进行k次这样的操作,求出最后的a序列。

思路:多写几组发现这个序列是交替的,最终只会有两组数组出现,只要根据K的奇偶性,来判断应该输出哪组数组即可。

AC代码

#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 200010;
typedef long long ll;
typedef long double ld;
ll a[maxn],b[maxn];
int main()
{
    ll t,n,k;
    ll i,j;
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        ll m=-1000000100;
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
            m=max(m,a[i]);
        }
        ll f=-1000000100;
        for(i=1;i<=n;i++)
        {
            a[i]=m-a[i];
            f=max(f,a[i]);
        }
        for(i=1;i<=n;i++)
        {
            b[i]=f-a[i];
        }
        if(k%2==1)
        {
            for(i=1;i<=n;i++)
            {
                if(i!=1)
                    cout<<" "<<a[i];
                else
                    cout<<a[i];
            }
        }
        else
        {
            for(i=1;i<=n;i++)
            {
                if(i!=1)
                    cout<<" "<<b[i];
                else
                    cout<<b[i];
            }
        }
        cout<<endl;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稚皓君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值