赞
踩
https://codeforces.com/contest/1397/problem/C
You are given an array aa of nn integers.
You want to make all elements of aa equal to zero by doing the following operation exactly three times:
It can be proven that it is always possible to make all elements of aa equal to zero.
Input
The first line contains one integer nn (1≤n≤1000001≤n≤100000): the number of elements of the array.
The second line contains nn elements of an array aa separated by spaces: a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109).
Output
The output should contain six lines representing three operations.
For each operation, print two lines:
Example
input
Copy
4 1 3 2 4
output
Copy
1 1 -1 3 4 4 2 2 4 -3 -6 -6
思路:由于题目说只进行三次操作,容易思考到前两次变到n的倍数,最后一次整个变成0.考虑到区间尽可能长且开始进行长度为n的操作无法满足,考虑长度为n-1,可以发现a[i]+a[i]*(n-1)刚好可以变成n的倍数。然后第一次操作对第一个元素进行操作就好了
- #include<iostream>
- #include<vector>
- #include<queue>
- #include<cstring>
- #include<cmath>
- #include<map>
- #include<set>
- #include<cstdio>
- #include<algorithm>
- #define debug(a) cout<<#a<<"="<<a<<endl;
- using namespace std;
- const int maxn=1e5+100;
- typedef long long LL;
- LL a[maxn];
- int main(void)
- {
- cin.tie(0);std::ios::sync_with_stdio(false);
- LL n;cin>>n;
- for(LL i=1;i<=n;i++) cin>>a[i];
- cout<<"1 1"<<endl;
- cout<<(-a[1])<<endl;
- if(n==1)
- {
- cout<<"1 1"<<endl;
- cout<<"0"<<endl;
- cout<<"1 1"<<endl;
- cout<<"0"<<endl;
- return 0;
- }
- cout<<"2"<<" "<<n<<endl;
- for(LL i=2;i<=n;i++) cout<<a[i]*(n-1)<<" ";
- cout<<endl;
- cout<<"1"<<" "<<n<<endl;
- for(LL i=1;i<=n;i++)
- {
- if(i==1) cout<<"0"<<" ";
- else cout<<(-1*a[i]*n)<<" ";
- }
- cout<<endl;
- return 0;
- }
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。